use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.
the class DimensionEditorTileEntity method canDeleteDimension.
private ItemStack canDeleteDimension(ItemStack itemStack) {
if (!DimletConfiguration.playersCanDeleteDimensions) {
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Players cannot delete dimensions!", 10);
return null;
}
if (!DimletConfiguration.editorCanDeleteDimensions) {
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Dimension deletion with the editor is not enabled!", 10);
return null;
}
ItemStack dimensionStack = inventoryHelper.getStackInSlot(DimensionEditorContainer.SLOT_DIMENSIONTARGET);
if (dimensionStack == null || dimensionStack.stackSize == 0) {
return null;
}
NBTTagCompound tagCompound = dimensionStack.getTagCompound();
int id = tagCompound.getInteger("id");
if (id == 0) {
return null;
}
DimensionInformation information = RfToolsDimensionManager.getDimensionManager(worldObj).getDimensionInformation(id);
if (getOwnerUUID() != null && getOwnerUUID().equals(information.getOwner())) {
return itemStack;
}
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "This machine's owner differs from the dimensions owner!", 10);
return null;
}
use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.
the class DimensionMonitorItem method onItemRightClick.
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (!world.isRemote) {
int id = player.worldObj.provider.dimensionId;
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(player.worldObj);
DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
if (dimensionInformation == null) {
Logging.message(player, "Not an RFTools dimension!");
} else {
String name = dimensionInformation.getName();
DimensionStorage storage = DimensionStorage.getDimensionStorage(player.getEntityWorld());
int power = storage != null ? storage.getEnergyLevel(id) : 0;
Logging.message(player, EnumChatFormatting.BLUE + "Name: " + name + " (Id " + id + ")" + EnumChatFormatting.YELLOW + " Power: " + power + " RF");
if (player.isSneaking()) {
Logging.message(player, EnumChatFormatting.RED + "Description: " + dimensionInformation.getDescriptor().getDescriptionString());
System.out.println("Description: = " + dimensionInformation.getDescriptor().getDescriptionString());
}
}
return stack;
}
return stack;
}
use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.
the class CmdSaveDims method execute.
@Override
public void execute(ICommandSender sender, String[] args) {
if (args.length < 2) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "The directory parameters is missing!"));
return;
} else if (args.length > 2) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Too many parameters!"));
return;
}
String directory = fetchString(sender, args, 1, null);
if (!directory.endsWith(File.separator)) {
directory += File.separator;
}
if (!new File(directory).mkdirs()) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Failed to create directory!"));
return;
}
World world = sender.getEntityWorld();
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
for (Integer dim : dimensionManager.getDimensions().keySet()) {
DimensionInformation information = dimensionManager.getDimensionInformation(dim);
if (information != null) {
String filename = directory + "dimension" + dim;
String error = information.buildJson(filename);
if (error != null) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Error: " + error));
}
}
}
}
use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.
the class PacketSyncDimensionInfo method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
int size = buf.readInt();
dimensions = new HashMap<Integer, DimensionDescriptor>();
for (int i = 0; i < size; i++) {
int id = buf.readInt();
PacketBuffer buffer = new PacketBuffer(buf);
NBTTagCompound tagCompound;
try {
tagCompound = buffer.readNBTTagCompoundFromBuffer();
} catch (IOException e) {
e.printStackTrace();
return;
}
DimensionDescriptor descriptor = new DimensionDescriptor(tagCompound);
dimensions.put(id, descriptor);
}
size = buf.readInt();
dimensionInformation = new HashMap<Integer, DimensionInformation>();
for (int i = 0; i < size; i++) {
int id = buf.readInt();
String name = NetworkTools.readString(buf);
DimensionInformation dimInfo = new DimensionInformation(name, dimensions.get(id), buf);
dimensionInformation.put(id, dimInfo);
}
}
use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.
the class PacketSyncDimensionInfo method toBytes.
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(dimensions.size());
for (Map.Entry<Integer, DimensionDescriptor> me : dimensions.entrySet()) {
buf.writeInt(me.getKey());
NBTTagCompound tagCompound = new NBTTagCompound();
me.getValue().writeToNBT(tagCompound);
PacketBuffer buffer = new PacketBuffer(buf);
try {
buffer.writeNBTTagCompoundToBuffer(tagCompound);
} catch (IOException e) {
e.printStackTrace();
}
}
buf.writeInt(dimensionInformation.size());
for (Map.Entry<Integer, DimensionInformation> me : dimensionInformation.entrySet()) {
buf.writeInt(me.getKey());
DimensionInformation dimInfo = me.getValue();
NetworkTools.writeString(buf, dimInfo.getName());
dimInfo.toBytes(buf);
}
}
Aggregations