MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Show me how to make a custom armor that emits light dynamically around the player."
/* To create a custom armor that emits light dynamically around the player, you can override the "onArmorTick" method in your ArmorItem class. This method is called every tick for each armor piece that is currently worn by a player. */ public class LightEmittingArmor extends ArmorItem { public LightEmittingArmor(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) { super(materialIn, slot, builder); } @Override public void onArmorTick(ItemStack stack, World world, PlayerEntity player) { super.onArmorTick(stack, world, player); /* Check if the world is server side because we don't want to run this code on the client. */ if (!world.isClientSide) { /* Get the block position under the player. */ BlockPos pos = player.blockPosition().below(); /* Check if the block under the player is air. */ if (world.getBlockState(pos).isAir()) { /* Set the block under the player to a light block. */ world.setBlock(pos, Blocks.TORCH.defaultBlockState(), 3); } } } } /* You will also need to register this armor item in your item registry. */ public static final RegistryObject<ArmorItem> LIGHT_EMITTING_HELMET = ITEMS.register("light_emitting_helmet", () -> new LightEmittingArmor(ArmorMaterial.DIAMOND, EquipmentSlotType.HEAD, new Item.Properties().tab(ItemGroup.TAB_COMBAT))); /* Repeat the above line for the chestplate, leggings, and boots. */ /* Note: This code will replace the block under the player with a torch, which may not be what you want. You may want to add additional checks or change the block to a custom light-emitting block that doesn't replace other blocks. */