Jump to content

Search the Community

Showing results for tags 'events'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Minecraft Forge
    • Releases
    • Support & Bug Reports
    • Suggestions
    • General Discussion
  • Mod Developer Central
    • Modder Support
    • User Submitted Tutorials
  • Non-Forge
    • Site News (non-forge)
    • Minecraft General
    • Off-topic
  • Forge Mods
    • Mods

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start









Yahoo IM

MSN Messenger

Personal Text

Found 8 results

  1. I have a tool that harvests multiple crops at once, that either replants or harvests the crops depending on an enchant on the tool. The harvesting and loot dropping works fine, but when it comes to updating what block is rendering, only the clicked block is updated properly, while the others drop the loot but appear to say as the fully grown crop, until right clicked again. The normal path for the tool is to just break the crop, as if the player harvested the crop. The other path is to reset the growth of the crop and drop the crop's loot, minus one seed. I have already tried all combinations of method parameters for setBlock() and destroyBlock(), and the updateing of the crop blocks still does not happen. The code thus far: public class ScytheItem extends HoeItem { public ScytheItem(Tier tier, int atkBase, float atkSpeed) { super(tier, atkBase, atkSpeed, new Item.Properties().stacksTo(1)); } @Override public @NotNull InteractionResult useOn(@NotNull UseOnContext context) { Level level = context.getLevel(); Player player = context.getPlayer(); InteractionHand hand = context.getHand(); ItemStack stack = context.getItemInHand(); if (!level.isClientSide() && player != null) { BlockPos pos = context.getClickedPos(); Block block = level.getBlockState(pos).getBlock(); if(block instanceof CropBlock) { level.playSound(null, pos, block.getSoundType(level.getBlockState(pos), level, pos, player).getBreakSound(), SoundSource.BLOCKS, 1.0F, AOTMain.RANDOM.nextFloat()); Map<Enchantment, Integer> enchantments = stack.getAllEnchantments(); int harvestSize = 1 + enchantments.getOrDefault(EnchantmentInit.HARVESTING_SIZE.get(), 0); for (int xOff = -harvestSize; xOff <= harvestSize; xOff++) { for (int zOff = -harvestSize; zOff <= harvestSize; zOff++) { BlockPos newPos = pos.offset(xOff, 0, zOff); Block blockAt = level.getBlockState(newPos).getBlock(); if (blockAt instanceof CropBlock crop) { if (crop.isMaxAge(level.getBlockState(newPos))) { if (enchantments.containsKey(EnchantmentInit.AUTO_PLANTER.get())) { dropLoot(level, newPos, level.getBlockState(newPos), block); level.setBlock(newPos, crop.getStateForAge(0), Block.UPDATE_CLIENTS); // the broken bit } else level.destroyBlock(newPos, true); // the broken bit } } } } stack.hurtAndBreak(1, player, (p) -> p.broadcastBreakEvent(hand)); } } return super.useOn(context); } private void dropLoot(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull Block block) { List<ItemStack> drops = getDrops(level, pos, state); findSeeds(block, drops).ifPresent(seed -> seed.shrink(1)); drops.forEach((drop) -> Block.popResource(level, pos, drop)); } private List<ItemStack> getDrops(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state) { return Block.getDrops(state, (ServerLevel) level, pos, null); } private Optional<ItemStack> findSeeds(@NotNull Block block, final Collection<ItemStack> stacks) { Item seedsItem = block.asItem(); return stacks.stream().filter((stack) -> stack.getItem() == seedsItem).findAny(); } }
  2. As per title, I can't see the Doc and can't get the work done.plz help me...
  3. sorry,i found the issues just some stupid reasons. but idont know how to delete the post
  4. Hello, I'm trying to launch the game with few mods but it does not let me because mojang authenticator... ? failed and i can't play. Someone may tell me what I could do to solve it please? thanks for your attention log: https://mclo.gs/ZYkKzCo
  5. Hello my fellow Modders this is the event code it's working fine with every mob and attack except witches it didn't trigger when witches attacked the player .. can you help me with this problem ... this is the code I'm new to coding in general @SubscribeEvent(priority = EventPriority.HIGH) public void AttackEvent(LivingAttackEvent event) { if (!event.getEntity().getCommandSenderWorld().isClientSide) { if (!(event.getEntity() instanceof ServerPlayer player)) return; ItemStack ring = Utils.getFirstCurio(ModItemGod.divinering.get(), player); Entity attacker2 = event.getSource().getEntity(); Entity attacker = event.getSource().getDirectEntity(); if (ring != null && attacker instanceof SummonedZombie summonedzombie || attacker instanceof SummonedSkeleton summoneskeleton || attacker instanceof SummonedVex summonedvex || attacker instanceof Vex vex ) { ((Monster) attacker).knockback(10,2 ,10); attacker.kill(); event.setCanceled(true); } else if (ring != null && attacker2 instanceof SummonedZombie summonedzombie || attacker2 instanceof SummonedSkeleton summoneskeleton || attacker2 instanceof SummonedVex summonedvex || attacker2 instanceof Vex vex) { ((Monster) attacker2).knockback(10,2 ,10); attacker2.kill(); event.setCanceled(true); } else if (ring != null) { ((LivingEntity) attacker2).addEffect((new MobEffectInstance(MobEffects.BLINDNESS, 200, 2, false, false))); ((LivingEntity) attacker2).setHealth(((LivingEntity) attacker2).getHealth() / 2); ((LivingEntity) attacker2).knockback(10, 3, 10); event.setCanceled(true); } } }
  6. How to make an entity have a short animation when an event is triggered?
  7. Hello, Mr./Ms. My current requirement is to perform some behavior if the player's oxygen value decreases and some other behavior if the player's oxygen increases. I didn't find an event that `listened to the player's oxygen value` change, so I used `TickEvent.ClientTickEvent` to try to listen to each player's oxygen change per tick. I tried to get the instance of the player using `getEntity` and looked for methods related to oxygen in it, I found `getAirSupply` and `setAirSupply` methods. These two methods do allow me to modify the player's oxygen, but if the player is in air, minecraft automatically restores 1 oxygen per tick, and when flooded, minecraft makes the player consume 1 oxygen per tick. If I want my Mod to rigorously reduce the player's oxygen based on my conditions, can I just calculate and write multiple `if` judgments to rigorously reduce the player's oxygen? Or does `forge` provide a way to cancel the `oxygen consumed/increased` event? Like canceling the injury event. Addendum: What I said about strictly consuming the player's oxygen is the behavior of my Mod. For example, I need to consume 3 oxygen per tick, but if the player is in air, the player will only actually consume 2 oxygen. And if I need to regain 4 oxygen per tick, but if the player is in water, the player will actually only regain 3 oxygen.
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.