use of mcjty.rftools.dimension.DimensionStorage in project RFTools by McJty.
the class EnergyExtractorTileEntity method checkStateServer.
@Override
protected void checkStateServer() {
super.checkStateServer();
int energyStored = getEnergyStored(ForgeDirection.DOWN);
if (energyStored < DimletConfiguration.EXTRACTOR_MAXENERGY) {
// Get energy out of the dimension.
DimensionStorage storage = DimensionStorage.getDimensionStorage(worldObj);
int dimensionEnergy = storage.getEnergyLevel(worldObj.provider.dimensionId);
int needed = DimletConfiguration.EXTRACTOR_MAXENERGY - energyStored;
if (needed > dimensionEnergy) {
needed = dimensionEnergy;
}
if (needed > 0) {
energyStored += needed;
dimensionEnergy -= needed;
modifyEnergyStored(needed);
storage.setEnergyLevel(worldObj.provider.dimensionId, dimensionEnergy);
storage.save(worldObj);
}
}
if (energyStored <= 0) {
return;
}
int rf = DimletConfiguration.EXTRACTOR_SENDPERTICK;
for (int i = 0; i < 6; i++) {
ForgeDirection dir = ForgeDirection.getOrientation(i);
TileEntity te = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
if (EnergyTools.isEnergyTE(te)) {
IEnergyConnection connection = (IEnergyConnection) te;
ForgeDirection opposite = dir.getOpposite();
if (connection.canConnectEnergy(opposite)) {
int rfToGive;
if (rf <= energyStored) {
rfToGive = rf;
} else {
rfToGive = energyStored;
}
int received = EnergyTools.receiveEnergy(te, opposite, rfToGive);
energyStored -= extractEnergy(ForgeDirection.DOWN, received, false);
if (energyStored <= 0) {
return;
}
}
}
}
}
use of mcjty.rftools.dimension.DimensionStorage in project RFTools by McJty.
the class DimensionEditorTileEntity method safeDeleteDimension.
private void safeDeleteDimension(int id, ItemStack dimensionTab) {
World w = DimensionManager.getWorld(id);
if (w != null) {
// Dimension is still loaded. Do nothing.
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Dimension cannot be deleted. It is still in use!", 10);
return;
}
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(worldObj);
DimensionInformation information = dimensionManager.getDimensionInformation(id);
if (information.getOwner() == null) {
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "You cannot delete a dimension without an owner!", 10);
return;
}
if (getOwnerUUID() == null) {
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "This machine has no proper owner and cannot delete dimensions!", 10);
return;
}
if (!getOwnerUUID().equals(information.getOwner())) {
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "This machine's owner differs from the dimensions owner!", 10);
return;
}
TeleportDestinations destinations = TeleportDestinations.getDestinations(worldObj);
destinations.removeDestinationsInDimension(id);
destinations.save(worldObj);
dimensionManager.removeDimension(id);
dimensionManager.reclaimId(id);
dimensionManager.save(worldObj);
DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(worldObj);
dimensionStorage.removeDimension(id);
dimensionStorage.save(worldObj);
if (DimletConfiguration.dimensionFolderIsDeletedWithSafeDel) {
File rootDirectory = DimensionManager.getCurrentSaveRootDirectory();
try {
FileUtils.deleteDirectory(new File(rootDirectory.getPath() + File.separator + "DIM" + id));
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Dimension deleted and dimension folder succesfully wiped!", 10);
} catch (IOException e) {
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Dimension deleted but dimension folder could not be completely wiped!", 10);
}
} else {
Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Dimension deleted. Please remove the dimension folder from disk!", 10);
}
dimensionTab.getTagCompound().removeTag("id");
int tickCost = dimensionTab.getTagCompound().getInteger("tickCost");
dimensionTab.getTagCompound().setInteger("ticksLeft", tickCost);
}
use of mcjty.rftools.dimension.DimensionStorage 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.DimensionStorage in project RFTools by McJty.
the class DimensionBuilderTileEntity method maintainDimensionTick.
private void maintainDimensionTick(NBTTagCompound tagCompound) {
int id = tagCompound.getInteger("id");
if (id != 0) {
DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(worldObj);
int rf;
if (isCreative()) {
rf = DimletConfiguration.BUILDER_MAXENERGY;
} else {
rf = getEnergyStored(ForgeDirection.DOWN);
}
int energy = dimensionStorage.getEnergyLevel(id);
// Max energy the dimension can still get.
int maxEnergy = DimletConfiguration.MAX_DIMENSION_POWER - energy;
if (rf > maxEnergy) {
rf = maxEnergy;
}
counter--;
if (counter < 0) {
counter = 20;
if (Logging.debugMode) {
Logging.log("#################### id:" + id + ", rf:" + rf + ", energy:" + energy + ", max:" + maxEnergy);
}
}
if (!isCreative()) {
consumeEnergy(rf);
}
dimensionStorage.setEnergyLevel(id, energy + rf);
dimensionStorage.save(worldObj);
}
}
use of mcjty.rftools.dimension.DimensionStorage in project RFTools by McJty.
the class CmdSafeDelete method execute.
@Override
public void execute(ICommandSender sender, String[] args) {
if (args.length < 2) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "The dimension parameter is missing!"));
return;
} else if (args.length > 2) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Too many parameters!"));
return;
}
int dim = fetchInt(sender, args, 1, 0);
World world = sender.getEntityWorld();
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
if (dimensionManager.getDimensionDescriptor(dim) == null) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Not an RFTools dimension!"));
return;
}
World w = DimensionManager.getWorld(dim);
if (w != null) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dimension is still in use!"));
return;
}
if (!sender.canCommandSenderUseCommand(3, "safedel")) {
DimensionInformation information = dimensionManager.getDimensionInformation(dim);
if (information.getOwner() == null) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This dimension has no owner. You cannot delete it!"));
return;
}
if (!(sender instanceof EntityPlayerMP)) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This command must be run as a player!"));
return;
}
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) sender;
if (!information.getOwner().equals(entityPlayerMP.getGameProfile().getId())) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You are not the owner of this dimension. You cannot delete it!"));
return;
}
}
TeleportDestinations destinations = TeleportDestinations.getDestinations(world);
destinations.removeDestinationsInDimension(dim);
destinations.save(world);
dimensionManager.removeDimension(dim);
dimensionManager.reclaimId(dim);
dimensionManager.save(world);
DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(world);
dimensionStorage.removeDimension(dim);
dimensionStorage.save(world);
if (DimletConfiguration.dimensionFolderIsDeletedWithSafeDel) {
File rootDirectory = DimensionManager.getCurrentSaveRootDirectory();
try {
FileUtils.deleteDirectory(new File(rootDirectory.getPath() + File.separator + "DIM" + dim));
sender.addChatMessage(new ChatComponentText("Dimension deleted and dimension folder succesfully wiped!"));
} catch (IOException e) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dimension deleted but dimension folder could not be completely wiped!"));
}
} else {
sender.addChatMessage(new ChatComponentText("Dimension deleted. Please remove the dimension folder from disk!"));
}
}
Aggregations