Jump to content

winnetrie

Members
  • Posts

    408
  • Joined

  • Last visited

Everything posted by winnetrie

  1. Thank you! Good the know. I apologize for my ignorance, but sometimes a documentation is more difficult to understand without a real person explaining it in greater detail. Especially if English is not your main language. I'm very greatfull people like you take the time to do this.
  2. Aha if i understand it right, i can register my eventhandler class with non static methods like this: MinecraftForge.EVENT_BUS.register(new ModRegistry()); I guess this goes in the main class, but where exactly?
  3. That's very strange…..I was Always told you can't acces non-static methods without instantiating that class. Even java doc says this. I tried, just for fun, to remove the static keyword from the methods and exactly that happend what i expected…..nothing was registered. Oh yes ofcourse
  4. But the Eclipse shows me en error and suggest to make it static: Cannot make a static reference to the non-static field white_terracotta_bricks_halfslab Since i can't make my registry methods non-static (because you then need to create an instance of that class in order to acces those methods), i have to use static fields. Or do i miss something?
  5. But then i have to use static initializers again. I can't use local variables in another method, and i need some references to the blocks who are inside the blockregistry method and use them in the itemregistry method to register the itemBlock Or are in this case static initializers ok to use?
  6. As i'm using the proper methods to register blocks and items, i have a hard time to figure out how to register slabs now. Because i have nothing to point to (no fields) and ForgeRegistries.BLOCKS.getValue() returns an AIR block sometimes. There is alot of stuff that goes wrong. i'll attach my latest log. I have also lots of model loading errors. Saying the file is not found, but it is and i spelled it right. This is my registering class: Here my slab class: latest.log
  7. Can we replace registered blocks/items with your own? For example if i want to replace minecraft:stone with my modded stone, wich would in fact delete the original block. That brings also the next question. Can we delete a registered block from the registry? I assume that could bring a lot of issues, especially if other classes depends on the original block. I guess mods that use static fields to instantiate their stuff won't be compatible. In the past days i have come up with alot of neat ideas, but that would require to replace some blocks and items from vanilla and maybe other mods too. Are we even allowed to do this?
  8. Just another quick question. Can i do the same for getMapColor and getMaterial? Just asking because they have a deprecated annotiation
  9. Oh right, i'm sorry. I forget to fix that. It's indeed not needed. Thank you very much. I actually can't believe it was as easy as that…..??
  10. yes a private field. Oh..? Really? I didn't knew that. I Always thought i need to get it and then set it also. Does this rule also apply for getblockhardness? Wait i post the class: public abstract class BlockTerracottaSlab extends BlockSlab{ private Block parentBlock; private SoundType blockSound; public BlockTerracottaSlab(Material material, MapColor mapcolor, String modprefix, String registryname) { super(material, mapcolor); parentBlock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(modprefix + registryname)); //setSoundType(blockSound); setRegistryName(modprefix + registryname); setCreativeTab(CreativeTabs.BUILDING_BLOCKS); // TODO Auto-generated constructor stub } @Override public SoundType getSoundType(IBlockState state, World world, BlockPos pos, @Nullable Entity entity){ blockSound = parentBlock.getSoundType(state, world, pos, entity); return blockSound; } @Override public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) { return parentBlock.getBlockState().getBaseState().getBlockHardness(worldIn, pos); } @Override public String getUnlocalizedName(int meta) { // TODO Auto-generated method stub return parentBlock.getUnlocalizedName(); } @Override public boolean isDouble() { // TODO Auto-generated method stub return false; } @Override public IProperty<?> getVariantProperty() { // TODO Auto-generated method stub return BlockSlab.HALF; } @Override public Comparable<?> getTypeForItem(ItemStack stack) { // TODO Auto-generated method stub return EnumBlockHalf.BOTTOM; } @SideOnly(Side.CLIENT) protected static boolean isHalfSlab(IBlockState state) { Block block = state.getBlock(); return block instanceof BlockSlab; } public static class Double extends BlockTerracottaSlab { public Double(Material material, MapColor mapcolor, String modprefix, String registryname) { super(material, mapcolor, modprefix, registryname); // TODO Auto-generated constructor stub } @Override public boolean isDouble() { return true; } } public static class Half extends BlockTerracottaSlab { public Half(Material material, MapColor mapcolor, String modprefix, String registryname) { super(material, mapcolor, modprefix, registryname); // TODO Auto-generated constructor stub } @Override public boolean isDouble() { return false; } } } please tell me if something isn't right.
  11. Like this? : @Override public SoundType getSoundType(IBlockState state, World world, BlockPos pos, @Nullable Entity entity){ blockSound = parentBlock.getSoundType(state, world, pos, entity); return blockSound; } How would i set the slabs soundtype to this sound now?
  12. I'm trying to create a universal BlockSlab class, where the soundtype and blockhardness is the same as the block i want it to be. For example i have a bricks block and i want to make a slab for it with the same properties(sound, hardnes etc etc)
  13. How would i get the soundType from a block. Right now i have this: parentBlock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(modprefix + registryname)); setSoundType(parentBlock.getSoundType()); but getSoundType() is deprecated. There is also this: getSoundType(IBlockState state, World world, BlockPos pos, @Nullable Entity entity) But i do not understand to use this. Why do i need World, BlockPos and Entity here ? World, BlockPos and Entity are not relevant. I need the soundtype from the parentblock, but not parentblock that is already somewhere in the world. EDIT: Same thing for getBlockHardness btw
  14. Oh, alright. I'll change it later. Going to sleep now. I am using .json recipes for crafting btw. Can we also do that with smelting recipes? EDIT: Sorry, but i can't find anything about json smelting recipes for 1.12.2. Even in the minecraft recipe folder, there is none to find.
  15. Alright i'm done rewriting the code. Result looks like this: ModRegistry class: ClientProxy class: BlockStainedClay class: ModRecipes class: And also a Utilities class: Can i improve this more or is this a good starting template?
  16. Should i use ForgeRegistries.BLOCKS.getValuesCollection() because getValues() is deprecated, but it says this: @Nonnull default Collection<V> getValuesCollection() { // TODO rename this to getValues in 1.13 return getValues();
  17. btw to get a block from the registry do i call this?: Block.getBlockFromName(References.MOD_ID + ":" + "white_terracotta_bricks"); I ask, because i only know this way. There is also Block.REGISTRY.getObjectById(id) But i don't know the id, only the name
  18. Yes ….haha i know, that's why i said this: Ow yes i could loop trough the registry and look for blocks with my modid, then register the itemblock for it...ofcourse. Thank you
  19. Yes i know i can do this as simple as your example. Main reason was to have clean code, but it takes as much as space like the simple way. On the other hand, having all blocks and items stored in a list can be usefull some day. Meh….That sounds stupid when i read it again ? I guess i just wanted to make it fancy, but you are so right about this. EDIT: It does takes less space to register blocks and itemblocks. both are done in 1 method, So registering block and it's itemblock takes only 1 line instead of 2 lines each time. Or can this be done otherwise?
  20. Alright this is absolutely not working, because the subscribe event triggers before the ModBlocks.init(); So i changed my class to this: @EventBusSubscriber public class ModBlocks { public static final List<Block> BLOCKS = new ArrayList<Block>(); public static final List<ItemBlock> ITEMBLOCKS = new ArrayList<ItemBlock>(); public static void addBlockToRegistryList(Block block) { BLOCKS.add(block); ITEMBLOCKS.add((ItemBlock) new ItemBlock(block).setRegistryName(block.getRegistryName())); System.out.println(block.getRegistryName() + "has been registered"); } @SubscribeEvent public static void onBlockRegister(RegistryEvent.Register<Block> event) { addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.WHITE_STAINED_HARDENED_CLAY, "white_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.ORANGE_STAINED_HARDENED_CLAY, "orange_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.MAGENTA_STAINED_HARDENED_CLAY, "magenta_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.LIGHT_BLUE_STAINED_HARDENED_CLAY, "light_blue_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.YELLOW_STAINED_HARDENED_CLAY, "yellow_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.LIME_STAINED_HARDENED_CLAY, "lime_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.PINK_STAINED_HARDENED_CLAY, "pink_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.GRAY_STAINED_HARDENED_CLAY, "gray_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.SILVER_STAINED_HARDENED_CLAY, "silver_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.CYAN_STAINED_HARDENED_CLAY, "cyan_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.PURPLE_STAINED_HARDENED_CLAY, "purple_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.BLUE_STAINED_HARDENED_CLAY, "blue_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.BROWN_STAINED_HARDENED_CLAY, "brown_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.GREEN_STAINED_HARDENED_CLAY, "green_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.RED_STAINED_HARDENED_CLAY, "red_terracotta_bricks")); addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.BLACK_STAINED_HARDENED_CLAY, "black_terracotta_bricks")); event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0])); } @SubscribeEvent public static void registerItemBlocks(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(ModBlocks.ITEMBLOCKS.toArray(new ItemBlock[0])); } } This is working fine, but i'm not sure putting the addBlockToRegistryList inside the onBlockRegister is the correct place. It had to be within a subscribe event or it won't work. So i was wondering if there is a subscribevent where i can put it?
  21. Because i have been told not to use static initializers, i have come up with an other approach to register my stuff. I'm wondering if this is a good 1? So i have a ModBlocks class that has 2 methods: 1 for adding my blocks to a list and the other to iniatilize that It looks like this: public class ModBlocks { public static final List<Block> BLOCKS = new ArrayList<Block>(); public static final List<ItemBlock> ITEMBLOCKS = new ArrayList<ItemBlock>(); public static void addBlockToRegistryList(Block block) { BLOCKS.add(block); ITEMBLOCKS.add((ItemBlock) new ItemBlock(block).setRegistryName(block.getRegistryName())); } public static void init() { addBlockToRegistryList(new BlockTerracotta(Material.ROCK, MapColor.WHITE_STAINED_HARDENED_CLAY, "white_terracotta_bricks")); } Then i have a RegistryHandler class: @EventBusSubscriber public class RegistryHandler { @SubscribeEvent public static void onItemRegister(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0])); } @SubscribeEvent public static void onBlockRegister(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0])); } @SubscribeEvent public static void registerItemBlocks(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(ModBlocks.ITEMBLOCKS.toArray(new ItemBlock[0])); } } And my ClientProxy: @EventBusSubscriber public class ClientProxy implements IProxy{ private static final String DEFAULT_VARIANT = "inventory"; @SubscribeEvent public static void onModelRegister(ModelRegistryEvent event) { for (Item item : ModItems.ITEMS) { registerItemModel(item); } for (Block block : ModBlocks.BLOCKS) { registerBlockModel(block); } } @Override public void PreInit(FMLPreInitializationEvent event) { // TODO Auto-generated method stub } @Override public void Init(FMLInitializationEvent event) { // TODO Auto-generated method stub } @Override public void PostInit(FMLPostInitializationEvent event) { // TODO Auto-generated method stub } @Override public void ServerStarting(FMLServerStartingEvent event) { // TODO Auto-generated method stub } public static void registerItemModel(Item item) { ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), DEFAULT_VARIANT)); } public static void registerBlockModel(Block block) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), DEFAULT_VARIANT)); } } and my main class: @Mod(modid = References.MOD_ID, name = References.NAME, version = References.VERSION) public class Wtemod { @Instance public static Wtemod instance; @SidedProxy(clientSide = References.CLIENT_PROXY_CLASS, serverSide = References.SERVER_PROXY_CLASS) public static IProxy proxy; @EventHandler public void PreInit(FMLPreInitializationEvent event) { //entities & networking } @EventHandler public void Init(FMLInitializationEvent event) { //registry events ModBlocks.init(); ModRecipes.init(); } @EventHandler public void PostInit(FMLPostInitializationEvent event) { //inter-mod stuff } @EventHandler public void serverStarting(FMLServerStartingEvent event) { //server commands registering } }
  22. So does that mean i do not need to create fields for my blocks. because we just use the registry to get the blocks/items? I do add my blocks to a list inside their class like this: ModBlocks.BLOCKS.add(this); The list is in another class called ModBlocks and looks like this: public static final List<Block> BLOCKS = new ArrayList<Block>(); So i guess i can't use that anymore. Perhaps it was a bad concept anyway.
  23. Oh i see, but i usually create a BlockBaseStair in that case and then use that to extends all my stairs.. Well, but then again you are right about it. It only has a few extra lines of code. I removed that class now.
  24. Well if i shouldn't use static initializers, how do i do it right then? My BlockBase class extends on Block, so there shouldn't be an issue for instanceof Block, because it is. If i can't make my own class that extends on Block, then i have no clue how i would add and override stuff.... I'll try with a resourcelocation in the constructor. Sorry no github, i have an account there but don't know how to use it
  25. I'm passing Material.CLAY and i'm mining it with the shovel. It should behave like the minecraft clayblock. The minecraft clayblock has it's hardness set to 0.6, i have to set it to 0.1 to get the same result. Can you explaine more about "BlockBase is an antipattern"? How would i pass the correct item to this method? public Item getItemDropped(IBlockState state, Random rand, int fortune) { return itemdrop; } I can't directly say what item it has to be, because i use the same class to create 16 different blocks and they all need a different itemdrop. Yes i use static initializers. My class looks like this: public class ModBlocks { public static final List<Block> BLOCKS = new ArrayList<Block>(); public static final List<ItemBlock> ITEMBLOCKS = new ArrayList<ItemBlock>(); //Creating terracotta bricks public static final Block WHITE_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.WHITE_STAINED_HARDENED_CLAY, "white_terracotta_bricks"); public static final Block ORANGE_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.ORANGE_STAINED_HARDENED_CLAY, "orange_terracotta_bricks"); public static final Block MAGENTA_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.MAGENTA_STAINED_HARDENED_CLAY, "magenta_terracotta_bricks"); public static final Block LIGHT_BLUE_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.LIGHT_BLUE_STAINED_HARDENED_CLAY, "light_blue_terracotta_bricks"); public static final Block YELLOW_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.YELLOW_STAINED_HARDENED_CLAY, "yellow_terracotta_bricks"); public static final Block LIME_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.LIME_STAINED_HARDENED_CLAY, "lime_terracotta_bricks"); public static final Block PINK_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.PINK_STAINED_HARDENED_CLAY, "pink_terracotta_bricks"); public static final Block GRAY_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.GRAY_STAINED_HARDENED_CLAY, "gray_terracotta_bricks"); public static final Block SILVER_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.SILVER_STAINED_HARDENED_CLAY, "silver_terracotta_bricks"); public static final Block CYAN_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.CYAN_STAINED_HARDENED_CLAY, "cyan_terracotta_bricks"); public static final Block PURPLE_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.PURPLE_STAINED_HARDENED_CLAY, "purple_terracotta_bricks"); public static final Block BLUE_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.BLUE_STAINED_HARDENED_CLAY, "blue_terracotta_bricks"); public static final Block BROWN_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.BROWN_STAINED_HARDENED_CLAY, "brown_terracotta_bricks"); public static final Block GREEN_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.GREEN_STAINED_HARDENED_CLAY, "green_terracotta_bricks"); public static final Block RED_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.RED_STAINED_HARDENED_CLAY, "red_terracotta_bricks"); public static final Block BLACK_TERRACOTTA_BRICKS = new BlockTerracotta(Material.ROCK, MapColor.BLACK_STAINED_HARDENED_CLAY, "black_terracotta_bricks"); //Creating stained clay blocks public static final Block WHITE_STAINED_CLAY = new BlockStainedClay(ModItems.WHITE_STAINED_CLAYBALL, Material.CLAY, MapColor.WHITE_STAINED_HARDENED_CLAY, "white_stained_clay"); public static final Block ORANGE_STAINED_CLAY = new BlockStainedClay(ModItems.ORANGE_STAINED_CLAYBALL, Material.CLAY, MapColor.ORANGE_STAINED_HARDENED_CLAY, "orange_stained_clay"); public static final Block MAGENTA_STAINED_CLAY = new BlockStainedClay(ModItems.MAGENTA_STAINED_CLAYBALL, Material.CLAY, MapColor.MAGENTA_STAINED_HARDENED_CLAY, "magenta_stained_clay"); public static final Block LIGHT_BLUE_STAINED_CLAY = new BlockStainedClay(ModItems.LIGHT_BLUE_STAINED_CLAYBALL, Material.CLAY, MapColor.LIGHT_BLUE_STAINED_HARDENED_CLAY, "light_blue_stained_clay"); public static final Block YELLOW_STAINED_CLAY = new BlockStainedClay(ModItems.YELLOW_STAINED_CLAYBALL, Material.CLAY, MapColor.YELLOW_STAINED_HARDENED_CLAY, "yellow_stained_clay"); public static final Block LIME_STAINED_CLAY = new BlockStainedClay(ModItems.LIME_STAINED_CLAYBALL, Material.CLAY, MapColor.LIME_STAINED_HARDENED_CLAY, "lime_stained_clay"); public static final Block PINK_STAINED_CLAY = new BlockStainedClay(ModItems.PINK_STAINED_CLAYBALL, Material.CLAY, MapColor.PINK_STAINED_HARDENED_CLAY, "pink_stained_clay"); public static final Block GRAY_STAINED_CLAY = new BlockStainedClay(ModItems.GRAY_STAINED_CLAYBALL, Material.CLAY, MapColor.GRAY_STAINED_HARDENED_CLAY, "gray_stained_clay"); public static final Block SILVER_STAINED_CLAY = new BlockStainedClay(ModItems.SILVER_STAINED_CLAYBALL, Material.CLAY, MapColor.SILVER_STAINED_HARDENED_CLAY, "silver_stained_clay"); public static final Block CYAN_STAINED_CLAY = new BlockStainedClay(ModItems.CYAN_STAINED_CLAYBALL, Material.CLAY, MapColor.CYAN_STAINED_HARDENED_CLAY, "cyan_stained_clay"); public static final Block PURPLE_STAINED_CLAY = new BlockStainedClay(ModItems.PURPLE_STAINED_CLAYBALL, Material.CLAY, MapColor.PURPLE_STAINED_HARDENED_CLAY, "purple_stained_clay"); public static final Block BLUE_STAINED_CLAY = new BlockStainedClay(ModItems.BLUE_STAINED_CLAYBALL, Material.CLAY, MapColor.BLUE_STAINED_HARDENED_CLAY, "blue_stained_clay"); public static final Block BROWN_STAINED_CLAY = new BlockStainedClay(ModItems.BROWN_STAINED_CLAYBALL, Material.CLAY, MapColor.BROWN_STAINED_HARDENED_CLAY, "brown_stained_clay"); public static final Block GREEN_STAINED_CLAY = new BlockStainedClay(ModItems.GREEN_STAINED_CLAYBALL, Material.CLAY, MapColor.GREEN_STAINED_HARDENED_CLAY, "green_stained_clay"); public static final Block RED_STAINED_CLAY = new BlockStainedClay(ModItems.RED_STAINED_CLAYBALL, Material.CLAY, MapColor.RED_STAINED_HARDENED_CLAY, "red_stained_clay"); public static final Block BLACK_STAINED_CLAY = new BlockStainedClay(ModItems.BLACK_STAINED_CLAYBALL, Material.CLAY, MapColor.BLACK_STAINED_HARDENED_CLAY, "black_stained_clay"); } So that's not how it supposed to be? I'm a bit confused now.
×
×
  • Create New...

Important Information

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