Add an API Helper to ChestGUI to allow inplace updating of the stack that was clicked.
This commit is contained in:
parent
95405f9e5a
commit
c6954add09
7 changed files with 68 additions and 19 deletions
|
@ -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.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=GPLv3
|
mod_license=GPLv3
|
||||||
# The mod version. See https://semver.org/
|
# 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.
|
# 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.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
@ -26,6 +26,8 @@ public abstract class BlockImitation extends Block
|
||||||
|
|
||||||
public abstract BlockState getImitatedBlockState(BlockGetter level, BlockPos pos);
|
public abstract BlockState getImitatedBlockState(BlockGetter level, BlockPos pos);
|
||||||
|
|
||||||
|
public abstract void updateImitation(BlockState newState, BlockGetter level, BlockPos pos);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void animateTick(BlockState blockState, Level level, BlockPos pos, RandomSource random) {
|
public void animateTick(BlockState blockState, Level level, BlockPos pos, RandomSource random) {
|
||||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||||
|
|
|
@ -23,6 +23,8 @@ import net.minecraftforge.network.NetworkHooks;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ChestGUI
|
public class ChestGUI
|
||||||
{
|
{
|
||||||
|
@ -36,9 +38,9 @@ public class ChestGUI
|
||||||
public boolean hasReset = false;
|
public boolean hasReset = false;
|
||||||
public boolean hasRemove = false;
|
public boolean hasRemove = false;
|
||||||
|
|
||||||
private Runnable onAdd;
|
private IChestGUIButtonCallback onAdd;
|
||||||
private Runnable onReset;
|
private IChestGUIButtonCallback onReset;
|
||||||
private Runnable onRemove;
|
private IChestGUIButtonCallback onRemove;
|
||||||
|
|
||||||
public ChestGUIButton addBtn = null;
|
public ChestGUIButton addBtn = null;
|
||||||
public ChestGUIButton resetBtn = null;
|
public ChestGUIButton resetBtn = null;
|
||||||
|
@ -46,21 +48,21 @@ public class ChestGUI
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ChestGUI withAdd(Runnable onAdd)
|
public ChestGUI withAdd(IChestGUIButtonCallback onAdd)
|
||||||
{
|
{
|
||||||
hasAdd=true;
|
hasAdd=true;
|
||||||
this.onAdd=onAdd;
|
this.onAdd=onAdd;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChestGUI withReset(Runnable onReset)
|
public ChestGUI withReset(IChestGUIButtonCallback onReset)
|
||||||
{
|
{
|
||||||
hasReset = true;
|
hasReset = true;
|
||||||
this.onReset = onReset;
|
this.onReset = onReset;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChestGUI withRemove(Runnable onRemove)
|
private ChestGUI withRemove(IChestGUIButtonCallback onRemove)
|
||||||
{
|
{
|
||||||
hasRemove = true;
|
hasRemove = true;
|
||||||
this.onRemove=onRemove;
|
this.onRemove=onRemove;
|
||||||
|
@ -68,6 +70,10 @@ public class ChestGUI
|
||||||
}
|
}
|
||||||
public ChestGUI withButton(ChestGUIButton button)
|
public ChestGUI withButton(ChestGUIButton button)
|
||||||
{
|
{
|
||||||
|
if(buttons.size()>=2*9)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
buttons.add(button);
|
buttons.add(button);
|
||||||
container.setStackInSlot(button.getSlotNum(), button.buildIcon());
|
container.setStackInSlot(button.getSlotNum(), button.buildIcon());
|
||||||
|
|
||||||
|
@ -98,8 +104,8 @@ public class ChestGUI
|
||||||
{
|
{
|
||||||
ItemStack remStack = new ItemStack(ModItems.CHESTGUI_REM.get(), 1);
|
ItemStack remStack = new ItemStack(ModItems.CHESTGUI_REM.get(), 1);
|
||||||
|
|
||||||
ChestGUIButton rem = new ChestGUIButton(remStack, ()-> {
|
ChestGUIButton rem = new ChestGUIButton(remStack, (stack)-> {
|
||||||
onRemove.run();
|
onRemove.run(stack);
|
||||||
}, new Vector2i(2, 3));
|
}, new Vector2i(2, 3));
|
||||||
|
|
||||||
removeBtn = rem;
|
removeBtn = rem;
|
||||||
|
@ -111,8 +117,8 @@ public class ChestGUI
|
||||||
{
|
{
|
||||||
ItemStack resStack = new ItemStack(ModItems.CHESTGUI_RESET.get(), 1);
|
ItemStack resStack = new ItemStack(ModItems.CHESTGUI_RESET.get(), 1);
|
||||||
|
|
||||||
ChestGUIButton rem = new ChestGUIButton(resStack, ()-> {
|
ChestGUIButton rem = new ChestGUIButton(resStack, (stack)-> {
|
||||||
onReset.run();
|
onReset.run(stack);
|
||||||
}, new Vector2i(2, 4));
|
}, new Vector2i(2, 4));
|
||||||
|
|
||||||
resetBtn = rem;
|
resetBtn = rem;
|
||||||
|
@ -126,8 +132,8 @@ public class ChestGUI
|
||||||
|
|
||||||
ItemStack remStack = new ItemStack(ModItems.CHESTGUI_ADD.get(), 1);
|
ItemStack remStack = new ItemStack(ModItems.CHESTGUI_ADD.get(), 1);
|
||||||
|
|
||||||
ChestGUIButton rem = new ChestGUIButton(remStack, ()-> {
|
ChestGUIButton rem = new ChestGUIButton(remStack, (stack)-> {
|
||||||
onAdd.run();
|
onAdd.run(stack);
|
||||||
}, new Vector2i(2, 5));
|
}, new Vector2i(2, 5));
|
||||||
|
|
||||||
addBtn = rem;
|
addBtn = rem;
|
||||||
|
|
|
@ -20,13 +20,14 @@ public class ChestGUIButton
|
||||||
private String name;
|
private String name;
|
||||||
private List<LoreEntry> tooltipInfo = new ArrayList<>();
|
private List<LoreEntry> tooltipInfo = new ArrayList<>();
|
||||||
|
|
||||||
private Runnable callback;
|
private IChestGUIButtonCallback callback;
|
||||||
private CompoundTag NBT = new CompoundTag();
|
private CompoundTag NBT = new CompoundTag();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Position is Row (X), Column (Y)
|
* Position is Row (X), Column (Y)
|
||||||
*/
|
*/
|
||||||
private Vector2i position;
|
private Vector2i position;
|
||||||
|
private ItemStack built;
|
||||||
|
|
||||||
public ChestGUIButton withName(String name)
|
public ChestGUIButton withName(String name)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +35,7 @@ public class ChestGUIButton
|
||||||
return this;
|
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.icon = icon;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -43,7 +44,7 @@ public class ChestGUIButton
|
||||||
tooltipInfo = new ArrayList<>();
|
tooltipInfo = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChestGUIButton(ItemStack existing, Runnable callback, Vector2i position)
|
public ChestGUIButton(ItemStack existing, IChestGUIButtonCallback callback, Vector2i position)
|
||||||
{
|
{
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
@ -80,6 +81,7 @@ public class ChestGUIButton
|
||||||
|
|
||||||
|
|
||||||
ret = ret.setHoverName(ChatHelpers.macro(name));
|
ret = ret.setHoverName(ChatHelpers.macro(name));
|
||||||
|
built=ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -90,6 +92,7 @@ public class ChestGUIButton
|
||||||
ItemStackHandler st = new ItemStackHandler(1);
|
ItemStackHandler st = new ItemStackHandler(1);
|
||||||
st.setStackInSlot(0, stack);
|
st.setStackInSlot(0, stack);
|
||||||
|
|
||||||
|
built=stack;
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +141,6 @@ public class ChestGUIButton
|
||||||
|
|
||||||
public void clicked()
|
public void clicked()
|
||||||
{
|
{
|
||||||
callback.run();
|
callback.run(built);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package dev.zontreck.libzontreck.chestgui;
|
||||||
|
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IChestGUIButtonCallback
|
||||||
|
{
|
||||||
|
void run(ItemStack stack);
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import dev.zontreck.libzontreck.util.heads.HeadCache;
|
||||||
import dev.zontreck.libzontreck.vectors.Vector2i;
|
import dev.zontreck.libzontreck.vectors.Vector2i;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
@ -34,8 +35,7 @@ public class CreditsCommand {
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for(CreditsEntry entry : HeadCache.CREDITS)
|
for(CreditsEntry entry : HeadCache.CREDITS)
|
||||||
{
|
{
|
||||||
gui = gui.withButton(new ChestGUIButton(entry.compile(), ()->{
|
gui = gui.withButton(new ChestGUIButton(entry.compile(), (stack)->{
|
||||||
|
|
||||||
}, new Vector2i(x,y)));
|
}, new Vector2i(x,y)));
|
||||||
|
|
||||||
//LibZontreck.LOGGER.info("Add gui button : " + entry.name);
|
//LibZontreck.LOGGER.info("Add gui button : " + entry.name);
|
||||||
|
|
29
src/main/java/dev/zontreck/libzontreck/util/BlocksUtil.java
Normal file
29
src/main/java/dev/zontreck/libzontreck/util/BlocksUtil.java
Normal file
|
@ -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<Vector3> VeinOf(ServerLevel level, Vector3 start, int limit)
|
||||||
|
{
|
||||||
|
List<Vector3> ret = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue