Jump to content

LoganJohnG

Members
  • Posts

    7
  • Joined

  • Last visited

LoganJohnG's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. The Type Hierarchy is definitely useful to find the events. I added a delay when checking if a door is open for the case for the iron door might not open. Also when you open a door it's closed when initially right-clicking it. @SubscribeEvent public void handleRightClickBlock(RightClickBlock event) { final BlockPos pos = event.getPos(); final World world = event.getWorld(); new java.util.Timer().schedule( new java.util.TimerTask() { @Override public void run() { IBlockState blockState = world.getBlockState(pos); if (null != blockState) { StateImplementation state = (StateImplementation) blockState; Block block = state.getBlock(); switch (block.getRegistryName().toString()) { case "minecraft:acacia_door": case "minecraft:birch_door": case "minecraft:dark_oak_door": case "minecraft:iron_door": case "minecraft:jungle_door": case "minecraft:spruce_door": case "minecraft:wooden_door": for (IProperty<?> p : state.getPropertyKeys()) { if (p.getName().equals("open")) { if ((boolean) state.getValue(p)) { System.out.println("Door is open"); } else { System.out.println("Door is closed"); } break; } } break; default: System.out.println("RightClickBlock name: " + block.getRegistryName() + "class " + block.getClass()); break; } } } }, 250 //ms ); }
  2. Sure I played some MC. Not an extensive amount though. I'd have to ask my kids how it works when they get home. Okay this works great to detect open and close chest events. @SubscribeEvent public void handlePlayerContainerEvent(PlayerContainerEvent event) { if (event.getContainer().getClass() == ContainerChest.class) { if (event.getClass() == PlayerContainerEvent.Open.class) { System.out.println("Chest Opened"); } else if (event.getClass() == PlayerContainerEvent.Close.class) { System.out.println("Chest Closed"); } } }
  3. Oh the iron door takes a weighted pressure plate to open.
  4. Gameplay wise how do you open an iron door? Seems like according to the properties, it has to be powered. Anyway, just going through BlockChest I don't see an opened property that is exposed. Instead I need to get the EntityPlayer to check if the openContainer is not null which means it's open. Probably not the best way to do it. case "RightClickBlock": // net.minecraftforge.event.entity.player.PlayerInteractEvent$RightClickBlock { RightClickBlock gameEvent = (RightClickBlock) event; BlockPos pos = gameEvent.getPos(); IBlockState blockState = gameEvent.getWorld().getBlockState(pos); if (null != blockState) { System.out.println("Player right click block: " + blockState + " " + blockState.getClass()); StateImplementation state = (StateImplementation) blockState; Block block = state.getBlock(); System.out.println("Block: " + block.getClass()); switch (block.getRegistryName().toString()) { case "minecraft:chest": case "minecraft:ender_chest": case "minecraft:trapped_chest": { Entity player = gameEvent.getEntity(); System.out.println("Entity: "+player.getClass()); EntityPlayerSP playerSP = (EntityPlayerSP)player; if (playerSP.openContainer != null) { System.out.println("Container is open "+block.getRegistryName().toString()); } break; } case "minecraft:acacia_door": case "minecraft:birch_door": case "minecraft:dark_oak_door": case "minecraft:iron_door": case "minecraft:jungle_door": case "minecraft:spruce_door": case "minecraft:wooden_door": for (IProperty<?> p : state.getPropertyKeys()) { if (p.getName().equals("open")) { System.out.println("Block state: " + state.getValue(p)); if ((boolean) state.getValue(p)) { System.out.println("Closed Door"); } else { System.out.println("Opened Door"); } break; } } break; default: System.out.println("Block name: " + block.getRegistryName()); break; } } break;
  5. This will print a log entry each time a new Event type happens... package com.example.examplemod; import java.util.Hashtable; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class MyForgeEventHandler { Hashtable<String, String> mHashtable = new Hashtable<String, String>(); public void init() { MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public void pickupItem(Event event) { String className = event.getClass().getSimpleName(); if (mHashtable.get(className) == null) { mHashtable.put(className, className); System.out.println("Detected new eventType! " + className); } } }
  6. I'll take a look at the eventbus thanks! Here's another example if that first one was too flashy.
  7. [SOLVED] The technical issues have been figured out. You can find the mod source at: https://github.com/tgraupmann/MinecraftChromaMod Is there a guide for hooking into item events? I'm probably looking for the event API documentation... AKA I'd like to have custom code when an item is in use so that I can call custom code. For example, when the player picks up and selects a particular item. Is there an event when the bow or pickaxe or cobblestone is active in the players hands? Is there an event for when Armor, Pants, Helmet are equipped? The reason for this is I have a Java library for controlling hardware RGB lighting. I want to hook into the events to control the lighting and play various animations. A keyboard animation looks like this: Other useful events. 1. Event for when the game starts and in the main menu (to init lighting) 2. Event when the game is going to exit (to uninit lighting) 3. Event when the player spawns 4. Event when the player jumps 5. Event when the player opens a door 6. Event when the player closes a door 7. Event when the player breaks a block 8. Event when the player attacks with a sword 9. Event when the player attacks with a bow 10. Event when the player gets hit by a monster 11. Event when the player is on fire 12. Event when player is under water 13. Event when player gains XP 14. Event for player health (show healthbar on the F-keys) 15. Event for player armor (show armor on F-keys) 16. Event when player drinks a potion 17. Event when player eats food Some pointers would be most appreciated. My experience with Minecraft Forge comes from this tutorial series - https://www.udemy.com/minecraft-modding-java So I can make custom items, pickaxe, shovel, sword, armor, creative tabs, etc. The course only covers making custom items, recipes, and skinning items. I'd like to take the next step into player events, door events, and item events. Thank you!
×
×
  • Create New...

Important Information

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