Java Code Examples for net.minecraft.world.WorldServer#getTileEntity()

The following examples show how to use net.minecraft.world.WorldServer#getTileEntity() . 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: GTTileTesseractSlave.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void update() {
	this.handleEnergy();
	if (world.getTotalWorldTime() % 20 == 0 && this.targetPos != null) {
		WorldServer targetWorld = DimensionManager.getWorld(this.targetDim);
		if (targetWorld == null) {
			setTarget(null);
			return;
		}
		TileEntity destination = targetWorld.getTileEntity(this.targetPos);
		if (destination instanceof GTTileTesseractMaster && ((GTTileTesseractMaster) destination).getActive()) {
			setTarget((GTTileTesseractMaster) destination);
			return;
		}
		setTarget(null);
	}
}
 
Example 2
Source File: PacketRequestTE.java    From LookingGlass with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handle(ByteBuf data, EntityPlayer player) {
	if (ModConfigs.disabled) return;
	int dim = data.readInt();
	int xPos = data.readInt();
	int yPos = data.readInt();
	int zPos = data.readInt();

	if (!DimensionManager.isDimensionRegistered(dim)) return;
	WorldServer world = MinecraftServer.getServer().worldServerForDimension(dim);
	if (world == null) return;
	TileEntity tile = world.getTileEntity(xPos, yPos, zPos);
	if (tile != null) {
		//FIXME: This is currently a very "forceful" method of doing this, and not technically guaranteed to produce correct results
		// This would be much better handled by using the getDescriptionPacket method and wrapping that packet in a LookingGlass
		// packet to control delivery timing, allowing for processing the packet while the correct target world is the active world
		// This idea requires that that system be in place, though, so until then this hack will hopefully hold.
		NBTTagCompound tag = new NBTTagCompound();
		tile.writeToNBT(tag);
		ServerPacketDispatcher.getInstance().addPacket(player, PacketTileEntityNBT.createPacket(xPos, yPos, zPos, tag, dim));
	}
}
 
Example 3
Source File: EntityBlock.java    From OpenModsLib with MIT License 6 votes vote down vote up
private boolean tryPlaceBlock(EntityPlayer player, WorldServer world, BlockPos pos, EnumFacing fromSide) {
	if (!world.isAirBlock(pos)) return false;

	boolean blockPlaced = new BlockManipulator(world, player, pos).place(blockState, fromSide, EnumHand.MAIN_HAND);
	if (!blockPlaced) return false;

	if (tileEntity != null) {
		tileEntity.setInteger("x", pos.getX());
		tileEntity.setInteger("y", pos.getY());
		tileEntity.setInteger("z", pos.getZ());
		TileEntity te = world.getTileEntity(pos);
		te.readFromNBT(tileEntity);
	}

	return true;
}
 
Example 4
Source File: ItemRemote.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private boolean isAllowedToEdit(EntityPlayer player, ItemStack remote){
    NBTTagCompound tag = remote.getTagCompound();
    if(tag != null) {
        if(tag.hasKey("securityX")) {
            int x = tag.getInteger("securityX");
            int y = tag.getInteger("securityY");
            int z = tag.getInteger("securityZ");
            int dimensionId = tag.getInteger("securityDimension");
            WorldServer world = null;
            for(WorldServer w : MinecraftServer.getServer().worldServers) {
                if(w.provider.dimensionId == dimensionId) {
                    world = w;
                    break;
                }
            }
            if(world != null) {
                TileEntity te = world.getTileEntity(x, y, z);
                if(te instanceof TileEntitySecurityStation) {
                    boolean canAccess = ((TileEntitySecurityStation)te).doesAllowPlayer(player);
                    if(!canAccess) {
                        player.addChatComponentMessage(new ChatComponentTranslation("gui.remote.noEditRights", x, y, z));
                    }
                    return canAccess;
                }
            }
        }
    }
    return true;
}
 
Example 5
Source File: ItemRemote.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate(ItemStack remote, World worl, Entity entity, int slot, boolean holdingItem){
    if(!worl.isRemote) {
        NBTTagCompound tag = remote.getTagCompound();
        if(tag != null) {
            if(tag.hasKey("securityX")) {
                int x = tag.getInteger("securityX");
                int y = tag.getInteger("securityY");
                int z = tag.getInteger("securityZ");
                int dimensionId = tag.getInteger("securityDimension");
                WorldServer world = null;
                for(WorldServer w : MinecraftServer.getServer().worldServers) {
                    if(w.provider.dimensionId == dimensionId) {
                        world = w;
                        break;
                    }
                }
                if(world != null) {
                    TileEntity te = world.getTileEntity(x, y, z);
                    if(!(te instanceof TileEntitySecurityStation)) {
                        tag.removeTag("securityX");
                        tag.removeTag("securityY");
                        tag.removeTag("securityZ");
                        tag.removeTag("securityDimension");
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: PlatformCommand.java    From YUNoMakeGoodMap with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
        throw new WrongUsageException(getUsage(sender));

    String cmd = args[0].toLowerCase(Locale.ENGLISH);
    if ("list".equals(cmd))
    {
        sender.sendMessage(new TextComponentString("Known Platforms:"));
        for (ResourceLocation rl : getPlatforms())
        {
            sender.sendMessage(new TextComponentString("  " + rl.toString()));
        }
    }
    else if ("spawn".equals(cmd) || "preview".equals(cmd))
    {
        if (args.length < 2)
            throw new WrongUsageException(getUsage(sender));

        Entity ent = sender.getCommandSenderEntity();
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer)sender.getEntityWorld();

        if (args.length >= 3)
        {
            //TODO: Preview doesnt quite work correctly with rotations....
            String rot = args[2].toLowerCase(Locale.ENGLISH);
            if ("0".equals(rot) || "none".equals(rot))
                settings.setRotation(Rotation.NONE);
            else if ("90".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_90);
            else if ("180".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_180);
            else if ("270".equals(rot))
                settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            else
                throw new WrongUsageException("Only rotations none, 0, 90, 180, and 270 allowed.");
        }

        BlockPos pos;
        if (args.length >= 6)
            pos = CommandBase.parseBlockPos(sender, args, 3, false);
        else if (ent != null)
            pos = ent.getPosition();
        else
            throw new WrongUsageException("Must specify a position if the command sender is not an entity");

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[1]), world, true);

        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        if (spawn != null)
            pos = pos.subtract(spawn);

        if ("spawn".equals(cmd))
        {
            sender.sendMessage(new TextComponentString("Building \"" + args[1] +"\" at " + pos.toString()));
            temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications!
            world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
        }
        else
        {
            BlockPos tpos = pos.down();
            if (spawn != null)
                tpos = tpos.add(spawn);
            sender.sendMessage(new TextComponentString("Previewing \"" + args[1] +"\" at " + pos.toString()));
            world.setBlockState(tpos, Blocks.STRUCTURE_BLOCK.getDefaultState().withProperty(BlockStructure.MODE, TileEntityStructure.Mode.LOAD));
            TileEntityStructure te = (TileEntityStructure)world.getTileEntity(tpos);
            if (spawn != null)
                te.setPosition(te.getPosition().subtract(spawn));
            te.setSize(temp.getSize());
            te.setMode(Mode.LOAD);
            te.markDirty();
        }
    }
    else
        throw new WrongUsageException(getUsage(sender));
}