Jump to content

Search the Community

Showing results for tags 'events'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


XMPP/GTalk


Gender


URL


Location


ICQ


AIM


Yahoo IM


MSN Messenger


Personal Text

Found 11 results

  1. I try to get some information about other players when joining a server. For example, I want to listen to the `AttackEntityEvent` to observe if one player hits another. However, this event works only if my own player hits other entities. Also, I want to read the information in the chat on a server with `ClientChatReceivedEvent` but that only works in Singleplayer. I know these problems are kind of separate ones but maybe they are linked because I register my Event listeners in a wrong way. I don't know. I have the same problem with many other events like `ArrowNockEvent`, `LivingHurtEvent`. The only event that works correctly is my `TickEvent.PlayerTickEvent`. Could you help me please. Are these events wrong? If so, are they other events that I can consider? If not, how can I gather information about other players on the server? Thanks for your help! @Mod(Main.MODID) public class Main { // Define mod id in a common place for everything to reference public static final String MODID = "tttdatacollector"; // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); public Main(FMLJavaModLoadingContext context) { IEventBus modEventBus = context.getModEventBus(); // Register the commonSetup method for modloading modEventBus.addListener(this::commonSetup); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new PlayerTickEventHandler()); MinecraftForge.EVENT_BUS.register(new PlayerHurtEventHandler()); MinecraftForge.EVENT_BUS.register(new PlayerAttackEntityEventHandler()); MinecraftForge.EVENT_BUS.register(new ChatMessageEventHandler()); MinecraftForge.EVENT_BUS.register(new KillEventHandler()); } } public class ChatMessageEventHandler { private static final Logger log = LogUtils.getLogger(); @SubscribeEvent public void onChatMessageServer(ClientChatReceivedEvent event) { log.info("ClientChatReceivedEvent"); log.info(event.getMessage().getString()); } } public class BowShotEventHandler { private static final Logger log = LogUtils.getLogger(); @SubscribeEvent public void onArrowNock(ArrowNockEvent event) { log.info("onArrowNock"); if (event.getEntity() instanceof ServerPlayer player) { log.info("Player nocked an arrow: {}", player.getName().getString()); } } } public class PlayerAttackEntityEventHandler { private static final Logger log = LogUtils.getLogger(); @SubscribeEvent public void onPlayerAttack(AttackEntityEvent event) { log.info("Player Attack by {} to {}", event.getEntity().getName().getString(), event.getTarget().getName().getString()); } } public class PlayerTickEventHandler { private static final Logger log = LogUtils.getLogger(); private final AggregatedPlayerDataCache aggregatedPlayerDataCache = AggregatedPlayerDataCache.getInstance(); private final PlayerPositionCache playerPositionCache = PlayerPositionCache.getInstance(); private final PlayerDistanceScoreCalculator playerDistanceScoreCalculator = PlayerDistanceScoreCalculator.getInstance(); @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { var player = event.player; String playerName = player.getName().getString(); var playerData = aggregatedPlayerDataCache.getPlayerData(playerName); playerData.setPlayerName(playerName); var oldPos = playerPositionCache.getPlayerPosition(playerName); this.calculateAndSetDistanceAndScore(oldPos, playerData, player); } }
  2. I am looking at these docs here (scroll down), and it says that there is an event called "WorldEvent.load" and I need to use it for my mod, but when I try to import it, IntelliJ Idea indicates that "net.minecraftforge.event.world" doesn't exist
  3. Hello! I recently approached modding and Java programming in general. But I'm very used to programming in Minecraft "code", so .json files and commands. In fact, for example, with Terrabalnder it was quite simple and intuitive to convert biome, surface rules and positioning files to run whit forge. Instead what I'm having difficulty with is switching Minecraft things I used to do whit commands to java format. Things like execute a condition or position checks on a specific type of entity, even simple things like "if block ~ ~-1 ~ dirt" or "run particle...". There aren't many tutorials, so I would like to know if there are any tools, documentation or a list of procedures, methods and classes, or useful IntelliJ tooltips. Let me know leterally how from zero I can get the location of methods and informations I need to use. Thanks
  4. 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(); } }
  5. As per title, I can't see the Doc and can't get the work done.plz help me...
  6. sorry,i found the issues just some stupid reasons. but idont know how to delete the post
  7. 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
  8. 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); } } }
  9. How to make an entity have a short animation when an event is triggered?
  10. 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.