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

The following examples show how to use net.minecraft.world.World#setTileEntity() . 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 File: BlockTFOven.java    From TofuCraftReload with 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 2
Source File: TileEntityBlockMateralProxy.java    From GardenCollection with MIT License 6 votes vote down vote up
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 3
Source File: TileEntityWoodProxy.java    From GardenCollection with 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 4
Source File: WorldGenOrnamentalTree.java    From GardenCollection with MIT License 6 votes vote down vote up
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 5
Source File: Harvester.java    From EmergingTechnology with 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 6
Source File: BlockCampfire.java    From Sakura_mod with 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 7
Source File: BlockCampfirePot.java    From Sakura_mod with 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 8
Source File: BlockTFCompressor.java    From TofuCraftReload with 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 9
Source File: BlockTFCrasher.java    From TofuCraftReload with 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 10
Source File: BlockAdvancedAggregator.java    From TofuCraftReload with 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.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 11
Source File: BlockSaltFurnace.java    From TofuCraftReload with 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 12
Source File: Light.java    From EmergingTechnology with 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 13
Source File: BlockFluidPipe.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 14
Source File: BlockStickyJar.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 15
Source File: ItemChestUpgrade.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 16
Source File: BlockGarden.java    From GardenCollection with 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 17
Source File: BlockInfo.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void apply(World world, BlockPos pos) {
    world.setBlockState(pos, blockState);
    if (tileEntity != null) {
        world.setTileEntity(pos, tileEntity);
    }
}
 
Example 18
Source File: MoveBlocks.java    From Valkyrien-Skies with 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 File: BlockPress.java    From AdvancedRocketry with 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
Source File: TileEntityEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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());
}