MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create a candy that makes you feel nauseous if eaten multiple times"
/* This mod creates a candy item that gives the player nausea if eaten multiple times within a certain duration. */ public class NauseatingCandy extends Item { private static final int NAUSEA_DURATION = 200; // 10 seconds private static final int MAX_EATEN_COUNT = 3; private Map<UUID, Integer> eatenCount = new HashMap<>(); public NauseatingCandy(Properties properties) { super(properties); } @Override public ItemStack finishUsingItem(ItemStack stack, World worldIn, LivingEntity entityLiving) { if (entityLiving instanceof PlayerEntity && !worldIn.isClientSide) { UUID playerUUID = entityLiving.getUUID(); int count = eatenCount.getOrDefault(playerUUID, 0) + 1; eatenCount.put(playerUUID, count); if (count >= MAX_EATEN_COUNT) { entityLiving.addEffect(new MobEffectInstance(MobEffects.NAUSEA, NAUSEA_DURATION)); eatenCount.put(playerUUID, 0); // Reset the count } } return super.finishUsingItem(stack, worldIn, entityLiving); } } /* You would also need to register this item in your main mod file or item registry file. */ public static final RegistryObject<Item> NAUSEATING_CANDY = ITEMS.register("nauseating_candy", () -> new NauseatingCandy(new Item.Properties().tab(ItemGroup.TAB_FOOD).food(new Food.Builder().nutrition(2).saturationMod(0.1F).build())));