diff --git a/gradle.properties b/gradle.properties index 3fe3fe9..645380f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -53,7 +53,7 @@ mod_name=Zontreck Library Mod # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1.10.011224.2203 +mod_version=1.10.011424.1910 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/zontreck/libzontreck/blocks/BlockImitation.java b/src/main/java/dev/zontreck/libzontreck/blocks/BlockImitation.java index 5a1ca86..ab23bd1 100644 --- a/src/main/java/dev/zontreck/libzontreck/blocks/BlockImitation.java +++ b/src/main/java/dev/zontreck/libzontreck/blocks/BlockImitation.java @@ -26,6 +26,8 @@ public abstract class BlockImitation extends Block public abstract BlockState getImitatedBlockState(BlockGetter level, BlockPos pos); + public abstract void updateImitation(BlockState newState, BlockGetter level, BlockPos pos); + @Override public void animateTick(BlockState blockState, Level level, BlockPos pos, RandomSource random) { BlockState imitatedBlockState = getImitatedBlockState(level, pos); diff --git a/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUI.java b/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUI.java index 51976f7..9510e24 100644 --- a/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUI.java +++ b/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUI.java @@ -23,6 +23,8 @@ import net.minecraftforge.network.NetworkHooks; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.function.Function; public class ChestGUI { @@ -36,9 +38,9 @@ public class ChestGUI public boolean hasReset = false; public boolean hasRemove = false; - private Runnable onAdd; - private Runnable onReset; - private Runnable onRemove; + private IChestGUIButtonCallback onAdd; + private IChestGUIButtonCallback onReset; + private IChestGUIButtonCallback onRemove; public ChestGUIButton addBtn = null; public ChestGUIButton resetBtn = null; @@ -46,21 +48,21 @@ public class ChestGUI - public ChestGUI withAdd(Runnable onAdd) + public ChestGUI withAdd(IChestGUIButtonCallback onAdd) { hasAdd=true; this.onAdd=onAdd; return this; } - public ChestGUI withReset(Runnable onReset) + public ChestGUI withReset(IChestGUIButtonCallback onReset) { hasReset = true; this.onReset = onReset; return this; } - private ChestGUI withRemove(Runnable onRemove) + private ChestGUI withRemove(IChestGUIButtonCallback onRemove) { hasRemove = true; this.onRemove=onRemove; @@ -68,6 +70,10 @@ public class ChestGUI } public ChestGUI withButton(ChestGUIButton button) { + if(buttons.size()>=2*9) + { + return this; + } buttons.add(button); container.setStackInSlot(button.getSlotNum(), button.buildIcon()); @@ -98,8 +104,8 @@ public class ChestGUI { ItemStack remStack = new ItemStack(ModItems.CHESTGUI_REM.get(), 1); - ChestGUIButton rem = new ChestGUIButton(remStack, ()-> { - onRemove.run(); + ChestGUIButton rem = new ChestGUIButton(remStack, (stack)-> { + onRemove.run(stack); }, new Vector2i(2, 3)); removeBtn = rem; @@ -111,8 +117,8 @@ public class ChestGUI { ItemStack resStack = new ItemStack(ModItems.CHESTGUI_RESET.get(), 1); - ChestGUIButton rem = new ChestGUIButton(resStack, ()-> { - onReset.run(); + ChestGUIButton rem = new ChestGUIButton(resStack, (stack)-> { + onReset.run(stack); }, new Vector2i(2, 4)); resetBtn = rem; @@ -126,8 +132,8 @@ public class ChestGUI ItemStack remStack = new ItemStack(ModItems.CHESTGUI_ADD.get(), 1); - ChestGUIButton rem = new ChestGUIButton(remStack, ()-> { - onAdd.run(); + ChestGUIButton rem = new ChestGUIButton(remStack, (stack)-> { + onAdd.run(stack); }, new Vector2i(2, 5)); addBtn = rem; diff --git a/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUIButton.java b/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUIButton.java index 8979c74..17763d5 100644 --- a/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUIButton.java +++ b/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUIButton.java @@ -20,13 +20,14 @@ public class ChestGUIButton private String name; private List tooltipInfo = new ArrayList<>(); - private Runnable callback; + private IChestGUIButtonCallback callback; private CompoundTag NBT = new CompoundTag(); /** * Position is Row (X), Column (Y) */ private Vector2i position; + private ItemStack built; public ChestGUIButton withName(String name) { @@ -34,7 +35,7 @@ public class ChestGUIButton return this; } - public ChestGUIButton(Item icon, String name, Runnable callback, Vector2i position) + public ChestGUIButton(Item icon, String name, IChestGUIButtonCallback callback, Vector2i position) { this.icon = icon; this.name = name; @@ -43,7 +44,7 @@ public class ChestGUIButton tooltipInfo = new ArrayList<>(); } - public ChestGUIButton(ItemStack existing, Runnable callback, Vector2i position) + public ChestGUIButton(ItemStack existing, IChestGUIButtonCallback callback, Vector2i position) { this.callback = callback; this.position = position; @@ -80,6 +81,7 @@ public class ChestGUIButton ret = ret.setHoverName(ChatHelpers.macro(name)); + built=ret; return ret; } @@ -90,6 +92,7 @@ public class ChestGUIButton ItemStackHandler st = new ItemStackHandler(1); st.setStackInSlot(0, stack); + built=stack; return st; } @@ -138,6 +141,6 @@ public class ChestGUIButton public void clicked() { - callback.run(); + callback.run(built); } } diff --git a/src/main/java/dev/zontreck/libzontreck/chestgui/IChestGUIButtonCallback.java b/src/main/java/dev/zontreck/libzontreck/chestgui/IChestGUIButtonCallback.java new file mode 100644 index 0000000..77dbf10 --- /dev/null +++ b/src/main/java/dev/zontreck/libzontreck/chestgui/IChestGUIButtonCallback.java @@ -0,0 +1,9 @@ +package dev.zontreck.libzontreck.chestgui; + +import net.minecraft.world.item.ItemStack; + +@FunctionalInterface +public interface IChestGUIButtonCallback +{ + void run(ItemStack stack); +} diff --git a/src/main/java/dev/zontreck/libzontreck/commands/CreditsCommand.java b/src/main/java/dev/zontreck/libzontreck/commands/CreditsCommand.java index 00aa67b..9043fc6 100644 --- a/src/main/java/dev/zontreck/libzontreck/commands/CreditsCommand.java +++ b/src/main/java/dev/zontreck/libzontreck/commands/CreditsCommand.java @@ -14,6 +14,7 @@ import dev.zontreck.libzontreck.util.heads.HeadCache; import dev.zontreck.libzontreck.vectors.Vector2i; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; @@ -34,8 +35,7 @@ public class CreditsCommand { int y = 0; for(CreditsEntry entry : HeadCache.CREDITS) { - gui = gui.withButton(new ChestGUIButton(entry.compile(), ()->{ - + gui = gui.withButton(new ChestGUIButton(entry.compile(), (stack)->{ }, new Vector2i(x,y))); //LibZontreck.LOGGER.info("Add gui button : " + entry.name); diff --git a/src/main/java/dev/zontreck/libzontreck/util/BlocksUtil.java b/src/main/java/dev/zontreck/libzontreck/util/BlocksUtil.java new file mode 100644 index 0000000..4439147 --- /dev/null +++ b/src/main/java/dev/zontreck/libzontreck/util/BlocksUtil.java @@ -0,0 +1,29 @@ +package dev.zontreck.libzontreck.util; + +import dev.zontreck.libzontreck.vectors.Vector3; +import net.minecraft.server.level.ServerLevel; + +import java.util.ArrayList; +import java.util.List; + +/** + * Contains helper functions for block position calculations + */ +public class BlocksUtil +{ + /** + * Gathers a list of positions for like-blocks in a vein. This can accept a limit of -1, but has a hard cap at 512 blocks + * @param level The level to find the vein in + * @param start Starting position for vein + * @param limit The applicable limit for vein detection + * @return List of positions for the vein + */ + public static List VeinOf(ServerLevel level, Vector3 start, int limit) + { + List ret = new ArrayList<>(); + + + + return ret; + } +}