瀏覽代碼

ItemEntityHooks

shedaniel 4 年之前
父節點
當前提交
fe9e0383f6

+ 49 - 0
common/src/main/java/me/shedaniel/architectury/hooks/ItemEntityHooks.java

@@ -0,0 +1,49 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.hooks;
+
+import me.shedaniel.architectury.ArchitecturyPopulator;
+import me.shedaniel.architectury.Populatable;
+import me.shedaniel.architectury.utils.IntValue;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+import net.minecraft.world.entity.item.ItemEntity;
+
+@Environment(EnvType.CLIENT)
+public final class ItemEntityHooks {
+    private ItemEntityHooks() {}
+    
+    @Populatable
+    private static final Impl IMPL = null;
+    
+    /**
+     * The lifespan of an {@link ItemEntity}.
+     * Fabric: Since it doesn't have this, the value will be a readable-only value of 6000.
+     * Forge: Value of lifespan of the forge hook.
+     */
+    public static IntValue lifespan(ItemEntity entity) {
+        return IMPL.lifespan(entity);
+    }
+    
+    public interface Impl {
+        IntValue lifespan(ItemEntity entity);
+    }
+    
+    static {
+        ArchitecturyPopulator.populate(ItemEntityHooks.class);
+    }
+}

+ 28 - 0
common/src/main/java/me/shedaniel/architectury/utils/BooleanValue.java

@@ -0,0 +1,28 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.utils;
+
+import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
+
+import java.util.function.BooleanSupplier;
+
+public interface BooleanValue extends Value<Boolean>, BooleanSupplier, BooleanConsumer {
+    @Override
+    default Boolean get() {
+        return getAsBoolean();
+    }
+}

+ 28 - 0
common/src/main/java/me/shedaniel/architectury/utils/DoubleValue.java

@@ -0,0 +1,28 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.utils;
+
+import it.unimi.dsi.fastutil.doubles.DoubleConsumer;
+
+import java.util.function.DoubleSupplier;
+
+public interface DoubleValue extends Value<Double>, DoubleSupplier, DoubleConsumer {
+    @Override
+    default Double get() {
+        return getAsDouble();
+    }
+}

+ 22 - 0
common/src/main/java/me/shedaniel/architectury/utils/FloatSupplier.java

@@ -0,0 +1,22 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.utils;
+
+@FunctionalInterface
+public interface FloatSupplier {
+    float getAsFloat();
+}

+ 26 - 0
common/src/main/java/me/shedaniel/architectury/utils/FloatValue.java

@@ -0,0 +1,26 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.utils;
+
+import it.unimi.dsi.fastutil.floats.FloatConsumer;
+
+public interface FloatValue extends Value<Float>, FloatSupplier, FloatConsumer {
+    @Override
+    default Float get() {
+        return getAsFloat();
+    }
+}

+ 28 - 0
common/src/main/java/me/shedaniel/architectury/utils/IntValue.java

@@ -0,0 +1,28 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.utils;
+
+import it.unimi.dsi.fastutil.ints.IntConsumer;
+
+import java.util.function.IntSupplier;
+
+public interface IntValue extends Value<Integer>, IntSupplier, IntConsumer {
+    @Override
+    default Integer get() {
+        return getAsInt();
+    }
+}

+ 28 - 0
common/src/main/java/me/shedaniel/architectury/utils/LongValue.java

@@ -0,0 +1,28 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.utils;
+
+import it.unimi.dsi.fastutil.longs.LongConsumer;
+
+import java.util.function.LongSupplier;
+
+public interface LongValue extends Value<Long>, LongSupplier, LongConsumer {
+    @Override
+    default Long get() {
+        return getAsLong();
+    }
+}

+ 22 - 0
common/src/main/java/me/shedaniel/architectury/utils/Value.java

@@ -0,0 +1,22 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.utils;
+
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+public interface Value<T> extends Supplier<T>, Consumer<T> {}

+ 38 - 0
fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/ItemEntityHooksImpl.java

@@ -0,0 +1,38 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.hooks.fabric;
+
+import me.shedaniel.architectury.hooks.ItemEntityHooks;
+import me.shedaniel.architectury.utils.IntValue;
+import net.minecraft.world.entity.item.ItemEntity;
+
+public class ItemEntityHooksImpl implements ItemEntityHooks.Impl {
+    @Override
+    public IntValue lifespan(ItemEntity entity) {
+        return new IntValue() {
+            @Override
+            public void accept(int value) {
+                
+            }
+            
+            @Override
+            public int getAsInt() {
+                return 6000;
+            }
+        };
+    }
+}

+ 38 - 0
forge/src/main/java/me/shedaniel/architectury/hooks/forge/ItemEntityHooksImpl.java

@@ -0,0 +1,38 @@
+/*
+ * Copyright 2020 shedaniel
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package me.shedaniel.architectury.hooks.forge;
+
+import me.shedaniel.architectury.hooks.ItemEntityHooks;
+import me.shedaniel.architectury.utils.IntValue;
+import net.minecraft.entity.item.ItemEntity;
+
+public class ItemEntityHooksImpl implements ItemEntityHooks.Impl {
+    @Override
+    public IntValue lifespan(ItemEntity entity) {
+        return new IntValue() {
+            @Override
+            public void accept(int value) {
+                entity.lifespan = value;
+            }
+            
+            @Override
+            public int getAsInt() {
+                return entity.lifespan;
+            }
+        };
+    }
+}