Jump to content

K10

Members
  • Posts

    19
  • Joined

  • Last visited

Everything posted by K10

  1. OK, I see. Thanks for your easy and gentle advises.
  2. Thanks, I see. However, How can I add other 15 prismarine metadata? Are there any way to add block metadata over 16? I thisk it is not able. Do you have any idea for adding other 15 blocks in existing prismarine block? Must I add block which has 15 other metadata in my mod?
  3. Thanks for your advice. I want to change not item name but registry name. Otherwise, I want to add variant as other 15 colored prismarine block. In my ideal, my mod have "prismarine block" and "prismarine bricks block" and "colored prismarine block" registry name.
  4. Hi. I want to rename vanilla prismarine block. In vanilla, prismarine's metadata is 1, prismarine bricks' metadata is 2, dark prismarine's metadata is 3. I want to remove these metadata and rename them new block name such as prismarine -> "prismarine", prismarine bricks -> "prismarine_block", dark prismarine -> "dark_prismarine". Anyone help me please. I think I should override vanilla prismarine block, so I tried this code but error occoured. @ObjectHolder(Reference.MODID) public class HamaBlocks { @ObjectHolder("minecraft:prismarine") public static Block prismarine = null; @ObjectHolder("minecraft:prismarine_bricks") public static Block prismarineBricks = null; @ObjectHolder("minecraft:dark_prismarine") public static Block darkPrismarine = null; public static void onBlockRegister(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(// new Block(Material.ROCK).setCreativeTab(CreativeTabs.BUILDING_BLOCKS)// .setRegistryName(new ResourceLocation("minecraft", "prismarine"))// .setUnlocalizedName("prismarine"),// new Block(Material.ROCK).setCreativeTab(CreativeTabs.BUILDING_BLOCKS)// .setRegistryName(new ResourceLocation("minecraft", "prismarine_bricks"))// .setUnlocalizedName("prismarine_bricks"),// new Block(Material.ROCK).setCreativeTab(CreativeTabs.BUILDING_BLOCKS)// .setRegistryName(new ResourceLocation("minecraft", "dark_prismarine"))// .setUnlocalizedName("dark_prismarine")// ); } }
  5. Thanks for a lot of advices! I tried them and it worked well!
  6. Hi. I added forge 1.12.2 item which teleport any entity to specific position and block that determine the position. The data of teleportation is saved NBT of item. However, NBT data is lost. The scene is when I picked item on block's gui (without Shift). additionally, an entity does not teleport to the place set without opening the inventory at once. anyone help me ? https://github.com/nihotamor/pipocraft/tree/master/
  7. Sorry, I have not updated and get tile entity packet anytime. So now Tile Entity returns custom name!!
  8. Hi. I'm trying to create a mod includes a block has tile entity like a minecraft:chest. However, when I opened a gui of the block, it returns custom name only when I am spectator. In other gamemode, tile entity returns default name such as "container.crate" as it doesn't have custom name.I tryed vanilla source from TileEntityChest, but it didn't work. Custom name is saved correctly to NBT. Even if I change custom name by using command, it is displayed only spectator mode. package doph.gpubg.tileentity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.NonNullList; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; public class TileEntityCrate extends TileEntity implements IInventory { private NonNullList<ItemStack> inventory = NonNullList.<ItemStack>withSize(getSizeInventory(), ItemStack.EMPTY); private String customName; public void setName(String name) { this.customName = name; } public NonNullList<ItemStack> getInventory(){ return inventory; } public void setItems(EntityPlayer player) { NonNullList<ItemStack> inv = player.inventory.mainInventory; for(int i = 0; i < 36; i++) { this.inventory.set(i, inv.get(i)); } inv = player.inventory.armorInventory; for(int i = 0; i < 4; i++) { this.inventory.set(i + 36, inv.get(i)); } inv = player.inventory.offHandInventory; this.inventory.set(40, inv.get(0)); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.inventory = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY); ItemStackHelper.loadAllItems(compound, this.inventory); if (compound.hasKey("CustomName", 8)) { this.customName = compound.getString("CustomName"); } } @Override public ITextComponent getDisplayName() { return (ITextComponent) (this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName())); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); ItemStackHelper.saveAllItems(compound, this.inventory); if (this.hasCustomName()) { compound.setString("CustomName", this.customName); } return compound; } @Override public int getSizeInventory() { return 45; } @Override public boolean isEmpty() { for (ItemStack itemstack : this.inventory) { if (!itemstack.isEmpty()) { return false; } } return true; } @Override public ItemStack getStackInSlot(int index) { if (index >= 0 && index < getSizeInventory()) { return this.inventory.get(index); } return ItemStack.EMPTY; } @Override public ItemStack decrStackSize(int index, int count) { return ItemStackHelper.getAndSplit(this.inventory, index, count); } @Override public ItemStack removeStackFromSlot(int index) { return ItemStackHelper.getAndRemove(inventory, index); } @Override public void setInventorySlotContents(int index, ItemStack stack) { ItemStack itemstack = getStackInSlot(index); boolean flag = !stack.isEmpty() && stack.isItemEqual(itemstack) && ItemStack.areItemStacksEqual(stack, itemstack); this.inventory.set(index, stack); if (stack.getCount() > this.getInventoryStackLimit()) { stack.setCount(this.getInventoryStackLimit()); } if (!flag) { this.markDirty(); } } @Override public int getInventoryStackLimit() { return 64; } @Override public String getName() { return this.hasCustomName() ? this.customName : "container.crate"; } @Override public boolean isUsableByPlayer(EntityPlayer player) { if (this.world.getTileEntity(this.pos) != this) { return false; } else { return player.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D; } } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return false; } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { } @Override public int getFieldCount() { return 0; } @Override public void clear() { this.inventory.clear(); } @Override public boolean hasCustomName() { return this.customName != null && !this.customName.isEmpty(); } } Does anyone have a good idea?
  9. I addded these methods to BaseManaita which should have Tile Entity: @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityManaita(); } And I checked coord of BlockPos which is argument of getServerGuiEvent, it seems is not the correct block position. I didn't pass correct block position in openGui method. When I passed correct position, it worked well!
  10. Thanks for your advice. However, The method still returns null
  11. Hello. I created a block which has a tile entity. However, when I access to the tile entity by using getTileEntity(BlockPos), the return value is null. In spite of I create tile entity by createNewTileEntity(World, int) method, it seems tile entity does not exist. Can anyone tell why this happened? Here is my all source code. https://github.com/nihotamor/melonpan
  12. I mistook file name when I create file on github because I didn't know way to drag and drop file at first. I already fixed. There are not enough document about forge tutorial in Japan, so I have to study old article... Oh, I missed it! I have to add it in my code. OK, I see. Thank you for your advices. I hava to rewrite the majority of my codes, so I recreate project and restart from first. I will report and ask later.
  13. OK, here is a my all code. https://github.com/nihotamor/cookmod
  14. Sorry, I forgot to say that these methods is called from @SubscribeEvent public static void OnBlockRegistered(RegistryEvent.Register<Block> e); @SubscribeEvent public static void OnItemRegistered(RegistryEvent.Register<Item> e);
  15. Hi. I added thin Block looks like wooden slab or wooden pressure plate in my Mod. However, There are some issue : Block model is not loaded (or not adapted). Block has a larger hit box than appearance. BlockRegisterer.java BlockManaita.java blockstates\manaita.json models\block\manaita_oak.json models\block\manaita_birch models\block\manaita Can anyone tell me why model is not adapted and block has strange collision box?
  16. Thank you. I called method creates instance of ItemBlock at FMLPreInitializationEvent, Error disappered. Finally, I could add ItemBlock to minecraft!
  17. Thank you for your advice. I tried following codes, However NullPointerException occured. package doph.niho.cookmod.init; import doph.niho.cookmod.block.BlockManaita; import doph.niho.cookmod.itemblock.BaseItemBlock; import doph.niho.cookmod.itemblock.ItemBlockManaita; import net.minecraft.block.Block; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.common.registry.ForgeRegistries; public class BlockRegisterer { public static Block manaita; public static BaseItemBlock manaitaItem; public static void RegisterModel() { RegisterRender(manaita, "_oak", "_spruce", "_birch", "_jungle", "_acacia", "_dark_oak"); } public static void RegisterFood() { ForgeRegistries.BLOCKS.register(manaita); } public static void RegisterItemBlock() { ForgeRegistries.ITEMS.register(manaitaItem); } public static void RegisterRender(Block block, String... subName) { int len = subName.length; if (len == 0) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } else { for (String str : subName) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName() + str, "inventory")); } } } public static void Init() { manaita = new BlockManaita(); manaitaItem = new ItemBlockManaita(); } } package doph.niho.cookmod.itemblock; import doph.niho.cookmod.init.BlockRegisterer; import doph.niho.cookmod.system.Define; import net.minecraft.util.ResourceLocation; public class ItemBlockManaita extends BaseItemBlock{ public ItemBlockManaita() { super(BlockRegisterer.manaita); this.setRegistryName(new ResourceLocation(Define.MODID, "manaita")); this.setUnlocalizedName("manaita"); } } Error Log : java.lang.NullPointerException: Can't use a null-name for the registry, object null. at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864) ~[guava-21.0.jar:?] at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:287) ~[ForgeRegistry.class:?] at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:281) ~[ForgeRegistry.class:?] at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:114) ~[ForgeRegistry.class:?] at doph.niho.cookmod.init.BlockRegisterer.RegisterFood(BlockRegisterer.java:23) ~[BlockRegisterer.class:?] at doph.niho.cookmod.system.Main.OnBlocksRegistered(Main.java:37) ~[Main.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_Main_OnBlocksRegistered_Register.invoke(.dynamic) ~[?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:143) ~[EventBus$1.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179) [EventBus.class:?] at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:736) [GameData.class:?] at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:604) [Loader.class:?] at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:270) [FMLClientHandler.class:?] at net.minecraft.client.Minecraft.init(Minecraft.java:513) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:421) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] java.lang.NullPointerException: Can't use a null-name for the registry, object null. at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864) at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:287) at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:281) at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:114) at doph.niho.cookmod.init.BlockRegisterer.RegisterFood(BlockRegisterer.java:23) at doph.niho.cookmod.system.Main.OnBlocksRegistered(Main.java:37) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_Main_OnBlocksRegistered_Register.invoke(.dynamic) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:143) at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179) at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:736) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:604) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:270) at net.minecraft.client.Minecraft.init(Minecraft.java:513) at net.minecraft.client.Minecraft.run(Minecraft.java:421) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26)
  18. Hello. This is my first topic. I am trying to add new block on forge 1.12.2. I Succeeded to add new Block with following code : // Main.java package doph.niho.cookmod.system; import java.util.Iterator; import doph.niho.cookmod.init.BlockRegisterer; import doph.niho.cookmod.init.CookModFood; import doph.niho.cookmod.init.RecipeDeleter; import net.minecraft.advancements.Advancement; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.crafting.IRecipe; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @Mod(modid = Define.MODID, name = Define.MOD_NAME, version = Define.MOD_VERSION, acceptedMinecraftVersions = Define.MOD_MC_VERSION) @EventBusSubscriber public class Main { @SubscribeEvent public static void OnItemsRegistered(RegistryEvent.Register<Item> e) { CookModFood.RegisterFood(); BlockRegisterer.Init(); BlockRegisterer.RegisterItemBlock(); } @SubscribeEvent public static void OnBlocksRegistered(RegistryEvent.Register<Block> e) { BlockRegisterer.RegisterFood(); } @SubscribeEvent public static void OnRecipesRegistered(RegistryEvent.Register<IRecipe> e) { RecipeDeleter.DeleteRecipe(); } // ファイルの読み込みやブロック等の登録 @EventHandler public void PreInit(FMLPreInitializationEvent e) { } // レシピ追加、Mod用の各種データ設定 @EventHandler public void Init(FMLInitializationEvent e) { BlockRegisterer.RegisterModel(); CookModFood.RegisterModel(); } // 他MODとの連携 @EventHandler public void PostInit(FMLPostInitializationEvent e) { } } //BlockRegisterer.java package doph.niho.cookmod.init; import doph.niho.cookmod.block.BlockManaita; import net.minecraft.block.Block; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.common.registry.ForgeRegistries; public class BlockRegisterer { public static Block manaita; public static ItemBlock manaitaItem; public static void RegisterModel() { RegisterRender(manaita, "_oak", "_spruce", "_birch", "_jungle", "_acacia", "_dark_oak"); } public static void RegisterFood() { ForgeRegistries.BLOCKS.register(manaita); } public static void RegisterItemBlock() { ForgeRegistries.ITEMS.register(manaitaItem); } public static void RegisterRender(Block block, String... subName) { int len = subName.length; if (len == 0) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } else { for (String str : subName) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName() + str, "inventory")); } } } public static void Init() { manaita = new BlockManaita(); manaitaItem = new ItemBlock(manaita); } } I could add Block, but when try to register ItemBlock, NullPointerException occur, so I can't register Block as Item. How to register or create instance of ItemBlock?
×
×
  • Create New...

Important Information

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