Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

  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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.