Jump to content

NorthWestWind

Members
  • Posts

    47
  • Joined

  • Last visited

Everything posted by NorthWestWind

  1. Ok I just went back and tried all of them again without the lines FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); and @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } And I still can register my block
  2. I took a look at the events and tested them. Method 1 doesn't work: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } } @Mod.EventBusSubscriber(modid = Musician.MOD_ID) class RegistryHandler { public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } So does method 2: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.register(RegistryHandler.class); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } } class RegistryHandler { public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } Method 3 also: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.register(new RegistryHandler()); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } } class RegistryHandler { public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } The 4th method still doesn't work: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.addListener(this::registerBlocks); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); public void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } Method 5 also failed: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.addGenericListener(Block.class, this::registerBlocks); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } Now I'm really confused.
  3. Hello there. I was just coding my mod and I tried to use `RegistryEvent.Register<Block>` to register my block, but the event doesn't fire. Other events can be fired though. In my case, `FMLCommonSetupEvent` fired just as normal as it should be. Here is my code: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.register(this); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } }
  4. So, I created a HashMap to store whether the player can walk through blocks. In LivingUpdateEvent, the map is updated. And then, in the extended block, it reads the states of the player from the map and decides whether to have collision or not, but that still doesn't work
  5. ok I'll change that IntelliJ told me this and I just don't know
  6. public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { Entity entity = context.getEntity(); if(!(entity instanceof LivingEntity)) return super.getCollisionShape(state, worldIn, pos, context); ItemStack boots = ((LivingEntity) entity).getItemStackFromSlot(EquipmentSlotType.FEET); ResourceLocation registryName = boots.getItem().getRegistryName(); if(registryName == null || !registryName.getPath().equals("item_name")) return super.getCollisionShape(state, worldIn, pos, context); return VoxelShapes.empty(); } This is the inverted one. public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { Entity entity = context.getEntity(); if(entity instanceof LivingEntity) { ItemStack boots = ((LivingEntity) entity).getItemStackFromSlot(EquipmentSlotType.FEET); ResourceLocation registryName = boots.getItem().getRegistryName(); if(registryName != null && registryName.getPath().equals("item_name")) { return VoxelShapes.empty(); } } return super.getCollisionShape(state, worldIn, pos, context); } This is the one I made at the very beginning. I don't see the problem though.
  7. I changed the method to: public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return VoxelShapes.empty(); } And the block has no collision at all. That means there should be something wrong with my condition that causes the block switches between the state collidable and not collidable
  8. That is just weird because the same thing works for other blocks that are not full cubes such as slabs, carpets, bamboo, stonecutter... Even glass panes work.
  9. I think getShape is just used to render the block's outline. It cannot change the collision shape by itself, but since getCollisionShape just call getShape by default, overriding getShape also overrides getCollisionShape. I took a look at what Properties#doesNotBlockMovement does before and turns out it only changes the collision shape, not the shape itself. A good example would be torches because they have no collision, but at the same time have an outline.
  10. I think that's because you overrided one block and all kind of that block returns null VoxelShape when the condition is matched.
  11. I did cancel the collision shape of the block (in the very first try) and I'm sure the condition is satisfied since when I have the item, I can clip into the block (and it covers my screen), but there is a force constantly pushing me out and doesn't allow me to walk through the block. Without that item, the block just acts like normal block.
  12. I tried to remove the bounding box of the player by Entity#setBoundingBox in onEntityCollision and it didn't go well. As soon as I touch the block, my entire game runs at 1 fps and I found myself at the bottom of the world. I have a feeling that I used the set bounding box method wrongly because I just get the bounding box of the entity and use AxisAlignedBB#shrink to get rid of the bounding box.
  13. Guess I will try that, but what should I put in there?
  14. GlassBlock doesn't even override onEntityCollision and the original onEntityCollision does nothing. I was thinking about that may be some problem with the Entity itself, but I have no clue
  15. Just went to test that. It doesn't work
  16. But I want it to have collision under some conditions. I don't think I can do that with Block.Properties#doesNotBlockMovement()?
  17. I want to make the Vanilla block have no collision. But I do that on other blocks and it works. I extend the block and register the block again.
  18. You can register the block with your class in the registry event to override a vanilla block. Just remember to setRegistryName("minecraft", "lantern");
  19. But this method doesn't allow it to have collision under certain conditions?
  20. I want to make some vanilla blocks to have no collision under certain condition, so I override the block (in this example, glass block): public class CustomGlassBlock extends GlassBlock { public CustomGlassBlock(Block block) { super(Properties.from(block)); } @Override public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { if(/*some condition*/) { return VoxelShapes.empty(); } return super.getCollisionShape(state, worldIn, pos, context); } } As far as I know, returning VoxelShapes.empty() in Block#getCollisionShape will actually make the block have no collision, at least I think that is true. When testing, the block does have no collision, but it is still pushing me out. What am I missing?
  21. Ok so I have no idea about what a TER is and does "change the render type" means overriding Block#getRenderType or something? Edit: I just figured out what is TER. Sorry for that. So what do I do to create a TER?
  22. I want to make the bed has no collision when player wears a set of armor, so I extended `BedBlock` in my new `Block` class and overrided the method `Block#getCollisionShape` as below: public class VanishingBedBlock extends BedBlock { public VanishingBedBlock(BedBlock block) { super(block.getColor(), Properties.from(block)); } @Override public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { Entity entity = context.getEntity(); if(entity instanceof LivingEntity) { if(/*check item somehow*/) { return VoxelShapes.empty(); } } return super.getCollisionShape(state, worldIn, pos, context); } } However, when I place the bed in Minecraft, there is only the outline of the bed when I'm not wearing the armor. The bed just goes invisible. I'm quite sure it is the problem of this class since cancelling the overriding doesn't give any problem at all. What should I do?
×
×
  • Create New...

Important Information

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