MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"How to create items that can be disabled by a config option?"
/* To create items that can be disabled by a config option, you can use the Config class in Forge. Here, ScripterAI is creating a custom item that can be disabled by a config option. */ public class ConfigurableItem extends Item { public static final BooleanValue ENABLED; static { final Pair<BooleanValue, Config> pair = new ForgeConfigSpec.Builder().configure((builder) -> { return builder.comment("Set to false to disable the custom item").define("enabled", true); }); ENABLED = pair.getLeft(); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, pair.getRight()); } public ConfigurableItem(Properties properties) { super(properties); } @Override public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (!ENABLED.get()) { if (entityIn instanceof PlayerEntity) { ((PlayerEntity) entityIn).inventory.removeStackFromSlot(itemSlot); } } } } /* Here, the item will automatically be removed from the player's inventory if the config option is set to false. */