Posted September 11, 20178 yr I used \/\/\/\/\/ to create an Item spawning my structure from a structure NBT file. When I right click the Item with the if(!worldIn.isRemote) checker, nothing happens but without it the game crashes. Any ideas? Here is my code @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { if(!worldIn.isRemote) { this.loadStructure(playerIn.getPosition().add(1, 0, 1), worldIn, "House"); } return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); } public void loadStructure(BlockPos pos, World world, String name) { if(!world.isRemote) { WorldServer server = (WorldServer)world; MinecraftServer mcserver = world.getMinecraftServer(); TemplateManager templateManager = server.getStructureTemplateManager(); ResourceLocation templateLocation = new ResourceLocation(Reference.MODID, name); Template template = templateManager.getTemplate(mcserver, templateLocation); if(template != null) { IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); PlacementSettings settings = (new PlacementSettings()).setMirror(Mirror.NONE).setRotation(Rotation.NONE).setIgnoreEntities(false).setChunk(null).setReplacedBlock(null).setIgnoreStructureBlock(false); template.addBlocksToWorld(world, pos, settings); } } } Edited September 11, 20178 yr by HarryTechReviews
September 12, 20178 yr Why are you checking (!world.isRemote) twice? You have it in your onItemRightClick method and the loadStructure event. Unless you are planning of calling "loadStructure" from other places, this second check is unnecessary. In loadStructure, does it ever get past your null check or is the "template" variable always null? If it is always null, step into the "templateManager#getTemplate" method and see where it's trying to load your structure file from. This part seems unnecessary since the block is staying the same state. 14 hours ago, HarryTechReviews said: IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3);
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.