Java Code Examples for net.minecraft.tileentity.TileEntity#markDirty()

The following examples show how to use net.minecraft.tileentity.TileEntity#markDirty() . 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: TemplateEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 8 votes vote down vote up
public void notifyBlocks(World world, BlockPos posStart)
{
    for (TemplateEnderUtilities.TemplateBlockInfo blockInfo : this.blocks)
    {
        BlockPos pos = transformedBlockPos(this.placement, blockInfo.pos).add(posStart);
        IBlockState state = world.getBlockState(pos);

        if (blockInfo.tileEntityData != null)
        {
            TileEntity te = world.getTileEntity(pos);

            if (te != null)
            {
                te.markDirty();
            }

            world.notifyBlockUpdate(pos, state, state, 7);
        }
        else
        {
            world.notifyNeighborsRespectDebug(pos, blockInfo.blockState.getBlock(), false);
        }
    }
}
 
Example 2
Source File: Spawnable.java    From minecraft-roguelike with GNU General Public License v3.0 6 votes vote down vote up
public void generate(IWorldEditor editor, Random rand, Coord cursor, int level){
	Coord pos = new Coord(cursor);
	editor.setBlock(pos, new MetaBlock(Blocks.MOB_SPAWNER.getDefaultState()), true,	true);
	
	TileEntity tileentity = editor.getTileEntity(pos);
	if (!(tileentity instanceof TileEntityMobSpawner)) return;
	
	TileEntityMobSpawner spawner = (TileEntityMobSpawner)tileentity;
	MobSpawnerBaseLogic spawnerLogic = spawner.getSpawnerBaseLogic();
	
	NBTTagCompound nbt = new NBTTagCompound();
	nbt.setInteger("x", pos.getX());
	nbt.setInteger("y", pos.getY());
	nbt.setInteger("z", pos.getZ());
	
	nbt.setTag("SpawnPotentials", getSpawnPotentials(rand, level));
	
	spawnerLogic.readFromNBT(nbt);
	spawnerLogic.updateSpawner();
	tileentity.markDirty();
}
 
Example 3
Source File: CraftBlockEntityState.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean update(boolean force, boolean applyPhysics) {
    boolean result = super.update(force, applyPhysics);

    if (result && this.isPlaced()) {
        TileEntity tile = getTileEntityFromWorld();

        if (isApplicable(tile)) {
            applyTo(tileEntityClass.cast(tile));
            tile.markDirty();
        }
    }

    return result;
}
 
Example 4
Source File: BlockCreativeManaBattery.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	if (playerIn.isCreative() && playerIn.isSneaking()) {
		buildStructure(worldIn, pos);
	} else {
		TileEntity tile = worldIn.getTileEntity(pos);
		if (!(tile instanceof TileManaBattery)) return false;
		else {
			((TileManaBattery) tile).revealStructure = !((TileManaBattery) tile).revealStructure;
			tile.markDirty();
		}
	}
	return true;
}
 
Example 5
Source File: NEIServerPacketHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private void handleMobSpawnerID(World world, BlockPos coord, String mobtype) {
    TileEntity tile = world.getTileEntity(coord);
    if (tile instanceof TileEntityMobSpawner) {
        ((TileEntityMobSpawner) tile).getSpawnerBaseLogic().setEntityId(new ResourceLocation(mobtype));
        tile.markDirty();
        IBlockState state = world.getBlockState(coord);
        world.notifyBlockUpdate(coord, state, state, 4);
    }
}
 
Example 6
Source File: BlockAuraPylon.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float par7, float par8, float par9) {
    if(world.getBlockMetadata(x, y, z) != 1) {
        Block up = world.getBlock(x, y + 1, z);
        return up != null && up instanceof BlockAuraPylon && up.onBlockActivated(world, x, y + 1, z, player, side, par7, par8, par9);
    }
    ItemStack heldItem = player.getHeldItem();
    if(!world.isRemote && heldItem != null && heldItem.getItem() instanceof ItemWandCasting &&
            ResearchManager.isResearchComplete(player.getCommandSenderName(), Gadomancy.MODID.toUpperCase() + ".AURA_PYLON")) {
        TileAuraPylon tileAuraPylon = (TileAuraPylon) world.getTileEntity(x, y - 1, z);
        if(MultiblockHelper.isMultiblockPresent(world, x, y, z, RegisteredMultiblocks.auraPylonPattern) &&
                !tileAuraPylon.isPartOfMultiblock() &&
                ThaumcraftApiHelper.consumeVisFromWandCrafting(player.getCurrentEquippedItem(), player, RegisteredRecipes.costsAuraPylonMultiblock, true)) {
            PacketStartAnimation pkt = new PacketStartAnimation(PacketStartAnimation.ID_SPARKLE_SPREAD, x, y, z);
            NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(world.provider.dimensionId, x, y, z, 32);
            PacketHandler.INSTANCE.sendToAllAround(pkt, point);
            TileAuraPylon ta = (TileAuraPylon) world.getTileEntity(x, y - 1, z);
            ta.setTileInformation(true, false);
            ta = (TileAuraPylon) world.getTileEntity(x, y - 3, z);
            ta.setTileInformation(false, true);
            int count = 1;
            TileEntity iter = world.getTileEntity(x, y - count, z);
            while(iter != null && iter instanceof TileAuraPylon) {
                ((TileAuraPylon) iter).setPartOfMultiblock(true);
                world.markBlockForUpdate(x, y - count, z);
                iter.markDirty();
                pkt = new PacketStartAnimation(PacketStartAnimation.ID_SPARKLE_SPREAD, x, y - count, z);
                PacketHandler.INSTANCE.sendToAllAround(pkt, point);
                count++;
                iter = world.getTileEntity(x, y - count, z);
            }
        }
    }
    return false;
}
 
Example 7
Source File: TileAuraPylon.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void distributeAspectInformation() {
    if(!isMasterTile()) return;
    int count = 1;
    TileEntity iter = worldObj.getTileEntity(xCoord, yCoord - count, zCoord);
    while(iter != null && iter instanceof TileAuraPylon) {
        ((TileAuraPylon) iter).holdingAspect = holdingAspect;
        worldObj.markBlockForUpdate(xCoord, yCoord - count, zCoord);
        iter.markDirty();
        count++;
        iter = worldObj.getTileEntity(xCoord, yCoord - count, zCoord);
    }
}
 
Example 8
Source File: NEISPH.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private void handleMobSpawnerID(World world, BlockCoord coord, String mobtype) {
    TileEntity tile = world.getTileEntity(coord.pos());
    if (tile instanceof TileEntityMobSpawner) {
        ((TileEntityMobSpawner) tile).getSpawnerBaseLogic().setEntityName(mobtype);
        tile.markDirty();
        world.markBlockForUpdate(coord.pos());
    }
}
 
Example 9
Source File: TileManaBattery.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void update() {
	super.update();

	if (getBlockType() == ModBlocks.MANA_BATTERY && !((BlockManaBattery) getBlockType()).testStructure(getWorld(), getPos()).isEmpty())
		return;

	if (getStructurePos() != getPos()) {
		setStructurePos(getPos());
		markDirty();
	}

	if (getBlockType() != ModBlocks.CREATIVE_MANA_BATTERY) {
		for (BlockPos relative : poses) {
			BlockPos target = getPos().add(relative);
			TileEntity tile = world.getTileEntity(target);
			if (tile instanceof TileOrbHolder) {
				if (!((TileOrbHolder) tile).isPartOfStructure() || ((TileOrbHolder) tile).canSuckFromOutside() || !((TileOrbHolder) tile).canGiveToOutside()) {
					((TileOrbHolder) tile).setStructurePos(getPos());
					((TileOrbHolder) tile).setCanSuckFromOutside(false);
					((TileOrbHolder) tile).setCanGiveToOutside(true);
					tile.markDirty();
				}
			}
		}


		if (world.getTotalWorldTime() % 20 == 0 && !ManaManager.forObject(getWizardryCap()).isManaFull()) {
			ManaManager.forObject(getWizardryCap())
					.addMana(5)
					.removeBurnout(5)
					.close();

			if (world.isRemote)
				ClientRunnable.run(new ClientRunnable() {
					@Override
					@SideOnly(Side.CLIENT)
					public void runIfClient() {
						Vec3d from = new Vec3d(getPos()).add(0.5, 1, 0.5);
						Vec3d to = from.add(RandUtil.nextDouble(-1, 1), -3, RandUtil.nextDouble(-1, 1));

						ParticleBuilder helix = new ParticleBuilder(200);
						helix.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
						helix.setAlphaFunction(new InterpFloatInOut(0.1f, 0.1f));
						ParticleSpawner.spawn(helix, world, new StaticInterp<>(to), 5, 0, (someFloat, particleBuilder) -> {
							particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0x0097FF), RandUtil.nextInt(50, 200)));
							particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
							particleBuilder.setPositionFunction(new InterpBezier3D(Vec3d.ZERO,
									from.subtract(to),
									new Vec3d(0, 5, 0), new Vec3d(0, 1, 0)));
							particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
						});
					}
				});
		}

	} else {
		ManaManager.forObject(getWizardryCap())
				.setMana(ManaManager.getMaxMana(getWizardryCap()))
				.setBurnout(0)
				.close();
	}
}
 
Example 10
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();
        }
    }
}