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);
}
}
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");
}
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);
}
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;
}
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;
}
Aggregations