Jump to content

Structure doesn't spawn with if(!world.isRemote) but crashes without it


Recommended Posts

Posted (edited)

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 by HarryTechReviews
Posted
  1. 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.
  2. In loadStructure, does it ever get past your null check or is the "template" variable always null?
    1. If it is always null, step into the "templateManager#getTemplate" method and see where it's trying to load your structure file from.
  3. This part seems unnecessary since the block is staying the same state.
    1. 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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