Search in sources :

Example 16 with WorldServer

use of net.minecraft.world.WorldServer in project GregTech by GregTechCE.

the class ICustomDataTile method writeCustomData.

default void writeCustomData(int discriminator, Consumer<PacketBuffer> dataWriter) {
    // unsafe
    TileEntity tileEntity = (TileEntity) this;
    WorldServer worldServer = (WorldServer) tileEntity.getWorld();
    BlockPos pos = tileEntity.getPos();
    PlayerChunkMapEntry chunkLoaderEntry = worldServer.getPlayerChunkMap().getEntry(pos.getX() / 16, pos.getZ() / 16);
    // nobody is watching chunk, so...
    if (chunkLoaderEntry == null)
        return;
    PacketBuffer backedData = new PacketBuffer(Unpooled.buffer());
    backedData.writeBoolean(false);
    backedData.writeInt(discriminator);
    dataWriter.accept(backedData);
    PacketCustomTileData packet = new PacketCustomTileData(pos, backedData);
    for (EntityPlayerMP watcher : chunkLoaderEntry.players) {
        NetworkHandler.channel.sendTo(packet.toFMLPacket(), watcher);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PacketCustomTileData(gregtech.api.net.PacketCustomTileData) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) PlayerChunkMapEntry(net.minecraft.server.management.PlayerChunkMapEntry) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 17 with WorldServer

use of net.minecraft.world.WorldServer in project RecurrentComplex by Ivorforce.

the class CommandDecorateOne method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    WorldServer entityWorld = (WorldServer) commandSender.getEntityWorld();
    BlockSurfacePos pos = parameters.iv().surfacePos(commandSender.getPosition(), false).require();
    if (!WorldGenStructures.generateRandomStructureInChunk(entityWorld.rand, pos.chunkCoord(), entityWorld, entityWorld.getBiome(pos.blockPos(0))))
        throw ServerTranslations.commandException("commands.rcdecorateone.none");
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) WorldServer(net.minecraft.world.WorldServer)

Example 18 with WorldServer

use of net.minecraft.world.WorldServer in project RecurrentComplex by Ivorforce.

the class CommandSelectDuplicate method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "mirror");
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    BlockArea area = selectionOwner.getSelection();
    BlockPos pos = parameters.pos("x", "y", "z", commandSender.getPosition(), false).require();
    AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
    NBTTagCompound worldDataCompound = worldData.createTagCompound();
    GenericStructure structureInfo = GenericStructure.createDefaultStructure();
    structureInfo.worldDataCompound = worldDataCompound;
    OperationRegistry.queueOperation(new OperationGenerateStructure(structureInfo, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld()), commandSender);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) OperationGenerateStructure(ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 19 with WorldServer

use of net.minecraft.world.WorldServer in project Bookshelf by Darkhax-Minecraft.

the class TileEntityMessage method handleMessage.

@Override
public final IMessage handleMessage(MessageContext context) {
    this.context = context;
    final World world = context.getServerHandler().player.getEntityWorld();
    final TileEntity tile = world.getTileEntity(this.pos);
    if (tile != null) {
        try {
            final T castTile = (T) tile;
            this.tile = castTile;
            ((WorldServer) world).addScheduledTask(() -> this.getAction());
        } catch (final ClassCastException e) {
            Constants.LOG.warn("Could not cast?", e);
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World)

Example 20 with WorldServer

use of net.minecraft.world.WorldServer in project VanillaTeleporter by dyeo.

the class TeleporterNetwork method getNextNode.

/**
	 * Gets the next node that can be teleported to from the target teleporter
	 * @param entityIn The entity being teleported (for messaging purposes)
	 * @param sourceNode The beginning node
	 * @return A valid node if one exists, or null otherwise
	 */
public TeleporterNode getNextNode(Entity entityIn, TeleporterNode sourceNode) {
    // get the top-most entity (rider) for sending messages
    Entity livingEntity = entityIn;
    while (!livingEntity.getPassengers().isEmpty()) {
        livingEntity = livingEntity.getControllingPassenger();
    }
    ArrayList<TeleporterNode> subnet = this.network.get(sourceNode.key);
    System.out.println("Checking teleporter subnet " + sourceNode.key);
    TeleporterNode destinationNode = null;
    int sourceIndex = subnet.indexOf(sourceNode);
    for (int i = (sourceIndex + 1) % subnet.size(); i != sourceIndex; i = (i + 1) % subnet.size()) {
        TeleporterNode currentNode = subnet.get(i);
        WorldServer destinationWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(currentNode.dimension);
        if (destinationWorld != null) {
            // if a tile entity doesn't exist at the specified node location, remove the node and continue
            TileEntityTeleporter tEntDest = currentNode.getTileEntity();
            if (tEntDest == null) {
                System.out.println("Invalid node found! Deleting...");
                removeNode(currentNode);
                continue;
            }
            // if the teleporter types are different, continue
            if (sourceNode.type.isEnder() != currentNode.type.isEnder()) {
                continue;
            }
            // if the teleporter isn't inter-dimensional and the dimensions are different, continue
            if (!sourceNode.type.isEnder() && sourceNode.dimension != currentNode.dimension) {
                continue;
            }
            // if the destination node is obstructed, continue
            if (isObstructed(destinationWorld, currentNode)) {
                if (livingEntity instanceof EntityPlayer) {
                    EntityPlayer entityPlayer = (EntityPlayer) livingEntity;
                    entityPlayer.sendMessage(this.getMessage("teleporterBlocked"));
                }
                continue;
            }
            // if the destination node is powered, continue
            if (tEntDest.isPowered() == true) {
                if (livingEntity instanceof EntityPlayer) {
                    EntityPlayer entityPlayer = (EntityPlayer) livingEntity;
                    entityPlayer.sendMessage(this.getMessage("teleporterDisabled"));
                }
                continue;
            }
            // if all above conditions are met, we've found a valid destination node.
            destinationNode = currentNode;
            break;
        }
    }
    if (destinationNode == null && livingEntity instanceof EntityPlayer) {
        EntityPlayer entityPlayer = (EntityPlayer) livingEntity;
        entityPlayer.sendMessage(this.getMessage("teleporterNotFound"));
    }
    return destinationNode;
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Aggregations

WorldServer (net.minecraft.world.WorldServer)322 BlockPos (net.minecraft.util.math.BlockPos)96 EntityPlayer (net.minecraft.entity.player.EntityPlayer)63 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)51 ItemStack (net.minecraft.item.ItemStack)48 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)48 TileEntity (net.minecraft.tileentity.TileEntity)42 Entity (net.minecraft.entity.Entity)41 IBlockState (net.minecraft.block.state.IBlockState)39 MinecraftServer (net.minecraft.server.MinecraftServer)35 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)31 World (net.minecraft.world.World)29 Block (net.minecraft.block.Block)26 EntityLivingBase (net.minecraft.entity.EntityLivingBase)23 ArrayList (java.util.ArrayList)20 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)18 Nullable (javax.annotation.Nullable)17 PotionEffect (net.minecraft.potion.PotionEffect)16 Chunk (net.minecraft.world.chunk.Chunk)16 World (org.spongepowered.api.world.World)13