package thetadev.constructionwand.basics.option; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import thetadev.constructionwand.api.IWandCore; import thetadev.constructionwand.api.IWandUpgrade; import thetadev.constructionwand.basics.ReplacementRegistry; import thetadev.constructionwand.items.core.CoreDefault; import javax.annotation.Nullable; public class WandOptions { public final CompoundTag tag; private static final String TAG_ROOT = "wand_options"; public enum LOCK { HORIZONTAL, VERTICAL, NORTHSOUTH, EASTWEST, NOLOCK } public enum DIRECTION { TARGET, PLAYER } public enum MATCH { EXACT, SIMILAR, ANY } public final WandUpgradesSelectable cores; public final OptionEnum lock; public final OptionEnum direction; public final OptionBoolean replace; public final OptionEnum match; public final OptionBoolean random; public final IOption[] allOptions; public WandOptions(ItemStack wandStack) { tag = wandStack.getOrCreateTagElement(TAG_ROOT); cores = new WandUpgradesSelectable<>(tag, "cores", new CoreDefault()); lock = new OptionEnum<>(tag, "lock", LOCK.class, LOCK.NOLOCK); direction = new OptionEnum<>(tag, "direction", DIRECTION.class, DIRECTION.TARGET); replace = new OptionBoolean(tag, "replace", true); match = new OptionEnum<>(tag, "match", MATCH.class, MATCH.SIMILAR); random = new OptionBoolean(tag, "random", false); allOptions = new IOption[]{cores, lock, direction, replace, match, random}; } @Nullable public IOption get(String key) { for(IOption option : allOptions) { if(option.getKey().equals(key)) return option; } return null; } public boolean testLock(LOCK l) { if(lock.get() == LOCK.NOLOCK) return true; return lock.get() == l; } public boolean matchBlocks(Block b1, Block b2) { switch(match.get()) { case EXACT: return b1 == b2; case SIMILAR: return ReplacementRegistry.matchBlocks(b1, b2); case ANY: return b1 != Blocks.AIR && b2 != Blocks.AIR; } return false; } public boolean hasUpgrade(IWandUpgrade upgrade) { if(upgrade instanceof IWandCore) return cores.hasUpgrade((IWandCore) upgrade); return false; } public boolean addUpgrade(IWandUpgrade upgrade) { if(upgrade instanceof IWandCore) return cores.addUpgrade((IWandCore) upgrade); return false; } }