Jump to content

quaiby

Members
  • Posts

    11
  • Joined

  • Last visited

Everything posted by quaiby

  1. I already try to write plain and understandable code. But the interface and type check way seems to me more right than list. Minifying amount of the code also makes it more understandable. Yes, you're right. I just wasn't been able to imagine more suitable example and I got what I got . But entries can be added dynamically. And dynamic things are often less bug-free, than hard-coded things, aren't they? This way is applicable for mods, but what about smt else? It is better if you always care, even if it is not neccessary in most of the cases, than if you never care.
  2. I cannot understand what you mean. This code is inside Item class, not block. So it should check if the wrench is being used on a machine and not on a grass, for example.
  3. Here you can find a little bit about how Forge works: http://mcforge.readthedocs.io/en/latest/forgedev/ Of course Forge depends on the Minecraft release and they need to fix patches for newer Minecraft versions, but most of the code doesn't change from one version to the another in Minecraft. Also devs from Mojang coded MCP - Mod Coder Pack - tool, that help Forge devs to decompile and deobfuscate Minecraft. Forge has 2 main parts: patches and everything else. Patches are small files that tell compiler where to change original code. Forge's patches for Minecraft are as tiny as possible. They just call code from other parts of Forge to minimize changes to make migration to newer releases easier. Forge contain not only event hooks, but a lots of its own stuff to make modding easier: Registries, abstract layers above Minecraft code to avoid conflicts, utility classes, event buses and so on.
  4. I'm just very crazy about any amount of possible performance
  5. Though check happens rarely, big list of blocks can cause lag spike anyway because java will iterate over all of the entries in the list. Also using interface allows to reduce amount of code. Compare: one word in the class signature plus 5 lines plain check vs list of blocks that contain 20+ entries and 10+ lines iterator
  6. Nope, that's part of the internal mixin needed to interact with machines from my mod
  7. Thank you! But this method is not necessary for me, my mod allow players to break machines not only using wrench. Wrench just makes it easier
  8. Disclaimer: I know that the question is more Java-related than Forge-related. I know 2 ways to implement wrench like in IC2 (needed to break machine): using interface or using annotation. I.e. using interface: interface IWrenchable {} class MyBlock extends Block implements IWrenchable {} class WrenchItem extneds Item { @Override public EnumActionResult onItemUse(looong args list) { if (!worldIn.isRemote) { if (player.isSneaking() && worldIn.getBlockState(pos).getBlock() instanceof IWrenchable) { worldIn.destroyBlock(pos, true); player.getHeldItem(hand).damageItem(1, player); } } return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } } Using annotation: @Retention(RetentionPolicy.RUNTIME) @interface Wrenchable {} @Wrenchable class MyBlock extends Block {} class WrenchItem extneds Item { @Override public EnumActionResult onItemUse(looong args list) { if (!worldIn.isRemote) { if (player.isSneaking() && worldIn.getBlockState(pos).getBlock().getClass().isAnnotationPresent(Wrenchable.class)) { worldIn.destroyBlock(pos, true); player.getHeldItem(hand).damageItem(1, player); } } return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } } Which way is better and faster?
  9. It works properly on server side.
  10. Forge 1.12.2 2655 I have neither item nor block textures when they are in the inventory. I have model file, texture file in right places. I register both item and its model in the right order. There are no errors in my console. Debugger tells me that both item and model are registered, and that model can see the .PNG texture. Item class: public class BasicItem extends Item { protected String name; public BasicItem(String name) { this.name = name; setUnlocalizedName(MODID + ":" + name); setRegistryName(name); } } Item manager class: @Mod.EventBusSubscriber public class ItemManager { public static Item ingot_copper = new BasicItem("ingot_copper"); public static List<Item> itemsList = Arrays.asList( ingot_copper ); @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { IForgeRegistry<Item> r = event.getRegistry(); itemsList.forEach(r::register); } public static void registerItemModels() { itemsList.forEach(item -> ModelLoader.setCustomModelResourceLocation( ingot_copper, 0, new ModelResourceLocation(ingot_copper.getRegistryName(), "inventory") )); } } Client proxy class: @Mod.EventBusSubscriber public class ClientProxy extends CommonProxy { @SubscribeEvent public void registerModel(ModelRegistryEvent event) { ItemManager.registerItemModels(); } } assets/<modid>/models/item/ingot_copper.json: { "parent": "item/generated", "textures": { "layer0": "<modid>:items/ingot_copper" } } What am I doing wrong?
×
×
  • Create New...

Important Information

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