Java Code Examples for net.minecraft.world.World#setTileEntity()

The following examples show how to use net.minecraft.world.World#setTileEntity() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: TofuCraftReload   File: BlockSaltFurnace.java    License: MIT License 6 votes vote down vote up
public static void setState(boolean active, World worldIn, BlockPos pos)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    TileEntity tileentity = worldIn.getTileEntity(pos);
    keepInventory = true;

    if (active)
    {
        worldIn.setBlockState(pos, BlockLoader.SALTFURNACE_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.SALTFURNACE_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }
    else
    {
        worldIn.setBlockState(pos, BlockLoader.SALTFURNACE.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.SALTFURNACE.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }

    keepInventory = false;

    if (tileentity != null)
    {
        tileentity.validate();
        worldIn.setTileEntity(pos, tileentity);
    }
}
 
Example 2
Source Project: TofuCraftReload   File: BlockTFOven.java    License: MIT License 6 votes vote down vote up
public static void setState(boolean active, World worldIn, BlockPos pos)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    TileEntity tileentity = worldIn.getTileEntity(pos);
    keepInventory = true;

    if (active)
    {
        worldIn.setBlockState(pos, BlockLoader.TFOVEN_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.TFOVEN_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }
    else
    {
        worldIn.setBlockState(pos, BlockLoader.TFOVEN.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.TFOVEN.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }

    keepInventory = false;

    if (tileentity != null)
    {
        tileentity.validate();
        worldIn.setTileEntity(pos, tileentity);
    }
}
 
Example 3
public static void setState(boolean active, World worldIn, BlockPos pos)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    TileEntity tileentity = worldIn.getTileEntity(pos);
    keepInventory = true;

    if (active)
    {
        worldIn.setBlockState(pos, BlockLoader.TFAdvancedAGGREGATOR_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.TFAdvancedAGGREGATOR_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }
    else
    {
        worldIn.setBlockState(pos, BlockLoader.TFAdvancedAGGREGATOR.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.TFAdvancedAGGREGATOR.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }

    keepInventory = false;

    if (tileentity != null)
    {
        tileentity.validate();
        worldIn.setTileEntity(pos, tileentity);
    }
}
 
Example 4
Source Project: TofuCraftReload   File: BlockTFCrasher.java    License: MIT License 6 votes vote down vote up
public static void setState(boolean active, World worldIn, BlockPos pos)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    TileEntity tileentity = worldIn.getTileEntity(pos);
    keepInventory = true;

    if (active)
    {
        worldIn.setBlockState(pos, BlockLoader.TFCRASHER_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.TFCRASHER_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }
    else
    {
        worldIn.setBlockState(pos, BlockLoader.TFCRASHER.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.TFCRASHER.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }

    keepInventory = false;

    if (tileentity != null)
    {
        tileentity.validate();
        worldIn.setTileEntity(pos, tileentity);
    }
}
 
Example 5
Source Project: TofuCraftReload   File: BlockTFCompressor.java    License: MIT License 6 votes vote down vote up
public static void setState(boolean active, World worldIn, BlockPos pos)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    TileEntity tileentity = worldIn.getTileEntity(pos);
    keepInventory = true;

    if (active)
    {
        worldIn.setBlockState(pos, BlockLoader.TFCOMPRESSOR_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.TFCOMPRESSOR_LIT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }
    else
    {
        worldIn.setBlockState(pos, BlockLoader.TFCOMPRESSOR.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
        worldIn.setBlockState(pos, BlockLoader.TFCOMPRESSOR.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
    }

    keepInventory = false;

    if (tileentity != null)
    {
        tileentity.validate();
        worldIn.setTileEntity(pos, tileentity);
    }
}
 
Example 6
Source Project: Sakura_mod   File: BlockCampfirePot.java    License: MIT License 6 votes vote down vote up
public static void setState(boolean active, World worldIn, BlockPos pos) {
    TileEntity tileentity = worldIn.getTileEntity(pos);
    keepInventory = true;
    if (active) {
        worldIn.setBlockState(pos, BlockLoader.CAMPFIRE_POT_LIT.getDefaultState());
        worldIn.setBlockState(pos, BlockLoader.CAMPFIRE_POT_LIT.getDefaultState());
    } else {
    	worldIn.setBlockState(pos, BlockLoader.CAMPFIRE_POT_IDLE.getDefaultState());
        worldIn.setBlockState(pos, BlockLoader.CAMPFIRE_POT_IDLE.getDefaultState());
    }
    keepInventory = false;
    if (tileentity != null) {
        tileentity.validate();
        worldIn.setTileEntity(pos, tileentity);
    }
}
 
Example 7
Source Project: Sakura_mod   File: BlockCampfire.java    License: MIT License 6 votes vote down vote up
public static void setState(boolean active, World worldIn, BlockPos pos) {
    TileEntity tileentity = worldIn.getTileEntity(pos);
    keepInventory = true;

    if (active) {
        worldIn.setBlockState(pos, BlockLoader.CAMPFIRE_LIT.getDefaultState());
    } else {
        worldIn.setBlockState(pos, BlockLoader.CAMPFIRE_IDLE.getDefaultState());
    }

    keepInventory = false;

    if (tileentity != null) {
        tileentity.validate();
        worldIn.setTileEntity(pos, tileentity);
    }
}
 
Example 8
Source Project: EmergingTechnology   File: Harvester.java    License: MIT License 6 votes vote down vote up
public static void rotateFacing(EnumFacing facing, World worldIn, BlockPos pos) {
    
    if (!worldIn.isBlockLoaded(pos)) {
        return;
    }

    IBlockState state = worldIn.getBlockState(pos);
    TileEntity tileEntity = worldIn.getTileEntity(pos);

    worldIn.setBlockState(pos, state.withProperty(FACING, facing), 3);

    if (tileEntity != null) {
        tileEntity.validate();
        worldIn.setTileEntity(pos, tileEntity);
    }
}
 
Example 9
private void generateBlock (World world, int x, int y, int z, Block block, int meta) {
    Block existingBlock = world.getBlock(x, y, z);
    if (existingBlock.isAir(world, x, y, z) || existingBlock.isLeaves(world, x, y, z)) {
        if (block == Blocks.log)
            setBlockAndNotifyAdequately(world, x, y, z, ModBlocks.thinLog, meta % 4);
        else if (block == Blocks.log2)
            setBlockAndNotifyAdequately(world, x, y, z, ModBlocks.thinLog, meta % 4 + 4);
        else if (WoodRegistry.instance().contains(block, meta)) {
            setBlockAndNotifyAdequately(world, x, y, z, block, 0);
            TileEntityWoodProxy te = new TileEntityWoodProxy();
            te.setProtoBlock(block, meta);

            setBlockAndNotifyAdequately(world, x, y, z, ModBlocks.thinLog, 0);
            world.setTileEntity(x, y, z, te);
        }
        else
            setBlockAndNotifyAdequately(world, x, y, z, block, meta);
    }
}
 
Example 10
Source Project: GardenCollection   File: TileEntityWoodProxy.java    License: MIT License 6 votes vote down vote up
public static void syncTileEntityWithData (World world, int x, int y, int z, int metadata) {
    if (metadata < 16) {
        world.removeTileEntity(x, y, z);
        return;
    }

    TileEntityWoodProxy te = (TileEntityWoodProxy) world.getTileEntity(x, y, z);
    if (te == null) {
        te = new TileEntityWoodProxy();
        world.setTileEntity(x, y, z, te);
    }

    Block block = getBlockFromComposedMetadata(metadata);
    int protoMeta = getMetaFromComposedMetadata(metadata);

    if (block != null)
        te.setProtoBlock(block, protoMeta);

    te.markDirty();
}
 
Example 11
public void syncTileEntityWithData (World world, int x, int y, int z, int metadata) {
    if (metadata < 16) {
        world.removeTileEntity(x, y, z);
        return;
    }

    TileEntityBlockMateralProxy te = (TileEntityBlockMateralProxy) world.getTileEntity(x, y, z);
    if (te == null) {
        te = createTileEntity();
        world.setTileEntity(x, y, z, te);
    }

    Block block = getBlockFromComposedMetadata(metadata);
    int protoMeta = getMetaFromComposedMetadata(metadata);

    if (block != null)
        te.setProtoBlock(block, protoMeta);

    te.markDirty();
}
 
Example 12
Source Project: GardenCollection   File: BlockGarden.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    if (side != ForgeDirection.UP.ordinal())
        return false;

    TileEntityGarden tileEntity = getTileEntity(world, x, y, z);
    if (tileEntity == null) {
        tileEntity = createNewTileEntity(world, 0);
        world.setTileEntity(x, y, z, tileEntity);
    }

    return applyItemToGarden(world, x, y, z, player, null, hitX, hitY, hitZ);
}
 
Example 13
Source Project: EmergingTechnology   File: Light.java    License: MIT License 5 votes vote down vote up
public static void setState(boolean hasPower, int bulbType, World worldIn, BlockPos pos) {
    IBlockState state = worldIn.getBlockState(pos);
    TileEntity tileEntity = worldIn.getTileEntity(pos);

    worldIn.setBlockState(pos, ModBlocks.light.getDefaultState().withProperty(FACING, state.getValue(FACING))
            .withProperty(POWERED, hasPower).withProperty(BULBTYPE, bulbType), 3);

    if (tileEntity != null) {
        tileEntity.validate();
        worldIn.setTileEntity(pos, tileEntity);
    }
}
 
Example 14
@Override
protected void onActiveModeChange(World world, BlockPos pos, boolean isActiveNow, boolean isInitialChange) {
    TileEntityFluidPipe oldTileEntity = (TileEntityFluidPipe) world.getTileEntity(pos);
    if (!(oldTileEntity instanceof TileEntityFluidPipeTickable) && isActiveNow) {
        TileEntityFluidPipeTickable newTileEntity = new TileEntityFluidPipeTickable();
        newTileEntity.transferDataFrom(oldTileEntity);
        newTileEntity.setActive(true);
        world.setTileEntity(pos, newTileEntity);
    } else if (oldTileEntity instanceof TileEntityFluidPipeTickable) {
        ((TileEntityFluidPipeTickable) oldTileEntity).setActive(isActiveNow);
    }
}
 
Example 15
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
    TileEntity tile = world.getTileEntity(x, y, z);
    if (tile != null && tile instanceof TileStickyJar && ((TileStickyJar) tile).isValid()) {

        ((TileStickyJar) tile).getParent().validate(); //Ugh...
        world.setTileEntity(x, y, z, ((TileStickyJar) tile).getParent()); //Ugh. that fix...

        ArrayList<ItemStack> drops = ((TileStickyJar) tile).getParentBlock()
                .getDrops(world, x, y, z, ((TileStickyJar) tile).getParentMetadata(), fortune);

        ((TileStickyJar) tile).getParent().invalidate(); //Uhm...
        world.setTileEntity(x, y, z, tile); //Revert. xD

        boolean found = false;
        for (ItemStack drop : drops) {
            if (RegisteredItems.isStickyableJar(drop)) {
                NBTHelper.getData(drop).setBoolean("isStickyJar", true);
                found = true;
                break;
            }
        }

        if (!found) {
            ItemStack item = new ItemStack(Items.slime_ball, 1);
            drops.add(item);
        }
        return drops;
    }
    return new ArrayList<ItemStack>();
}
 
Example 16
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
	if (world.isRemote) {
		return EnumActionResult.PASS;
	}
	IBlockState state = world.getBlockState(pos);
	TileEntity te = world.getTileEntity(pos);
	if (state.getBlock() == Blocks.CHEST && te instanceof TileEntityChest) {
		TileEntityChest chest = (TileEntityChest) te;
		ItemStack[] items = new ItemStack[chest.getSizeInventory()];
		for (int i = 0; i < items.length; i++) {
			items[i] = chest.getStackInSlot(i);
			chest.setInventorySlotContents(i, ItemStack.EMPTY);
		}
		IBlockState newState = BlocksItemsBetterChests.betterchest.getDefaultState().withProperty(BlockBetterChest.directions, state.getValue(BlockChest.FACING));
		world.setBlockState(pos, newState, 2);
		TileEntityBChest newte = new TileEntityBChest();
		world.setTileEntity(pos, newte);
		for (int i = 0; i < items.length; i++) {
			newte.getChestPart().setInventorySlotContents(i, items[i]);
		}
		world.notifyBlockUpdate(pos, state, newState, 1);
		ItemStack heldItem = player.getHeldItem(hand);
		heldItem.setCount(heldItem.getCount() - 1);
		return EnumActionResult.SUCCESS;
	}
	return EnumActionResult.PASS;
}
 
Example 17
public void apply(World world, BlockPos pos) {
    world.setBlockState(pos, blockState);
    if (tileEntity != null) {
        world.setTileEntity(pos, tileEntity);
    }
}
 
Example 18
Source Project: Valkyrien-Skies   File: MoveBlocks.java    License: Apache License 2.0 4 votes vote down vote up
private static void copyTileEntityToPos(World world, BlockPos oldPos, BlockPos newPos,
    Optional<PhysicsObject> physicsObjectOptional) {
    // Make a copy of the tile entity at oldPos to newPos
    TileEntity worldTile = world.getTileEntity(oldPos);
    if (worldTile != null) {
        NBTTagCompound tileEntNBT = new NBTTagCompound();
        TileEntity newInstance;
        if (worldTile instanceof IRelocationAwareTile) {
            CoordinateSpaceType coordinateSpaceType =
                physicsObjectOptional.isPresent() ? CoordinateSpaceType.SUBSPACE_COORDINATES
                    : CoordinateSpaceType.GLOBAL_COORDINATES;

            ShipTransform transform = new ShipTransform(newPos.getX() - oldPos.getX(),
                newPos.getY() - oldPos.getY(), newPos.getZ() - oldPos.getZ());

            newInstance = ((IRelocationAwareTile) worldTile)
                .createRelocatedTile(newPos, transform, coordinateSpaceType);
        } else {
            tileEntNBT = worldTile.writeToNBT(tileEntNBT);
            // Change the block position to be inside of the Ship
            tileEntNBT.setInteger("x", newPos.getX());
            tileEntNBT.setInteger("y", newPos.getY());
            tileEntNBT.setInteger("z", newPos.getZ());
            newInstance = TileEntity.create(world, tileEntNBT);
        }
        // Order the IVSNodeProvider to move by the given offset.
        if (newInstance instanceof IVSNodeProvider) {
            ((IVSNodeProvider) newInstance).shiftInternalData(newPos.subtract(oldPos));
            if (physicsObjectOptional.isPresent()) {
                ((IVSNodeProvider) newInstance)
                    .getNode()
                    .setParentPhysicsObject(physicsObjectOptional.get());
            } else {
                ((IVSNodeProvider) newInstance)
                    .getNode()
                    .setParentPhysicsObject(null);
            }
        }

        try {
            world.setTileEntity(newPos, newInstance);
            physicsObjectOptional
                .ifPresent(physicsObject -> physicsObject.onSetTileEntity(newPos, newInstance));
            newInstance.markDirty();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 19
Source Project: AdvancedRocketry   File: BlockPress.java    License: MIT License 4 votes vote down vote up
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param)
{
	EnumFacing enumfacing = EnumFacing.DOWN;

	if (!worldIn.isRemote)
	{
		boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing);

		if (flag && id == 1)
		{
			worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2);
			return false;
		}

		if (!flag && id == 0)
		{
			return false;
		}
	}

	if (id == 0)
	{
		if (!this.doMove(worldIn, pos, enumfacing, true))
		{
			return false;
		}

		worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2);
		worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_PISTON_EXTEND, SoundCategory.BLOCKS, 0.5F, worldIn.rand.nextFloat() * 0.25F + 0.6F);
	}
	else if (id == 1)
	{

		worldIn.setBlockState(pos, Blocks.PISTON_EXTENSION.getDefaultState().withProperty(BlockPistonMoving.FACING, enumfacing).withProperty(BlockPistonMoving.TYPE, BlockPistonExtension.EnumPistonType.DEFAULT), 3);
		worldIn.setTileEntity(pos, BlockPistonMoving.createTilePiston(this.getStateFromMeta(param), enumfacing, false, true));


		worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_PISTON_CONTRACT, SoundCategory.BLOCKS, 0.5F, worldIn.rand.nextFloat() * 0.15F + 0.6F);
	}

	return true;
}
 
Example 20
@Override
public void handleUpdateTag(NBTTagCompound tag)
{
    if (tag.hasKey("r"))
    {
        this.setFacing(EnumFacing.byIndex((byte)(tag.getByte("r") & 0x07)));
    }

    if (tag.hasKey("o", Constants.NBT.TAG_STRING))
    {
        this.ownerData = new OwnerData(tag.getString("o"), tag.getBoolean("pu"));
    }

    if (tag.hasKey("Camo", Constants.NBT.TAG_INT))
    {
        this.camoState = Block.getStateById(tag.getInteger("Camo"));

        World world = this.getWorld();
        BlockPos pos = this.getPos();
        IBlockState stateSelf = world.getBlockState(pos);

        // Temporarily place the target block to be able to grab its data
        if (this.camoState != null && this.camoState.getBlock() != Blocks.AIR)
        {
            try
            {
                BlockUtils.setBlockToAirWithoutSpillingContents(world, pos, 16);

                if (world.setBlockState(pos, this.camoState, 16))
                {
                    if (tag.hasKey("CD", Constants.NBT.TAG_COMPOUND))
                    {
                        this.camoData = tag.getCompoundTag("CD");
                        TileEntity te = world.getTileEntity(pos);

                        if (te != null)
                        {
                            te.handleUpdateTag(this.camoData);
                        }
                    }

                    this.camoState = this.camoState.getActualState(world, pos);
                    this.camoStateExtended = this.camoState.getBlock().getExtendedState(this.camoState, world, pos);

                    BlockUtils.setBlockToAirWithoutSpillingContents(world, pos, 16);
                    world.setBlockState(pos, stateSelf, 16);
                    this.validate(); // re-validate after being removed by the setBlockState() to air
                    world.setTileEntity(pos, this);
                }
            }
            catch (Exception e)
            {
                EnderUtilities.logger.warn("Exception while trying to grab the Extended state for a camo block: {}", this.camoState, e);
            }
        }
    }
    else
    {
        this.camoState = null;
        this.camoStateExtended = null;
    }

    this.getWorld().checkLightFor(EnumSkyBlock.BLOCK, this.getPos());
    this.notifyBlockUpdate(this.getPos());
}