use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions 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(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension cannot be deleted. It is still in use!", 10);
return;
}
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
DimensionInformation information = dimensionManager.getDimensionInformation(id);
if (information.getOwner() == null) {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "You cannot delete a dimension without an owner!", 10);
return;
}
if (getOwnerUUID() == null) {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "This machine has no proper owner and cannot delete dimensions!", 10);
return;
}
if (!getOwnerUUID().equals(information.getOwner())) {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "This machine's owner differs from the dimensions owner!", 10);
return;
}
RFToolsDim.teleportationManager.removeReceiverDestinations(getWorld(), id);
dimensionManager.removeDimension(id);
dimensionManager.reclaimId(id);
dimensionManager.save(getWorld());
DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(getWorld());
dimensionStorage.removeDimension(id);
dimensionStorage.save(getWorld());
if (GeneralConfiguration.dimensionFolderIsDeletedWithSafeDel) {
File rootDirectory = DimensionManager.getCurrentSaveRootDirectory();
try {
FileUtils.deleteDirectory(new File(rootDirectory.getPath() + File.separator + "RFTOOLS" + id));
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension deleted and dimension folder succesfully wiped!", 10);
} catch (IOException e) {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension deleted but dimension folder could not be completely wiped!", 10);
}
} else {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "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.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class ReturnEnergyHelper method setEnergyLevel.
public static void setEnergyLevel(PacketReturnEnergy message) {
World world = MinecraftTools.getWorld(Minecraft.getMinecraft());
DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(world);
dimensionStorage.setEnergyLevel(message.getId(), message.getEnergy());
}
use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class DimensionBuilderTileEntity method maintainDimensionTick.
private void maintainDimensionTick(NBTTagCompound tagCompound) {
int id = tagCompound.getInteger("id");
if (id != 0) {
DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(getWorld());
int rf;
if (isCheaterDimension(tagCompound)) {
rf = MachineConfiguration.BUILDER_MAXENERGY;
} else {
rf = getEnergyStored(EnumFacing.DOWN);
}
int energy = dimensionStorage.getEnergyLevel(id);
// Max energy the dimension can still get.
int maxEnergy = PowerConfiguration.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 (!isCheaterDimension(tagCompound)) {
consumeEnergy(rf);
}
dimensionStorage.setEnergyLevel(id, energy + rf);
dimensionStorage.save(getWorld());
}
}
use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class RealizedDimensionTab method addInformation.
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List<String> list, boolean whatIsThis) {
super.addInformation(itemStack, player, list, whatIsThis);
NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound != null) {
String name = tagCompound.getString("name");
int id = 0;
if (name != null) {
id = tagCompound.getInteger("id");
if (id == 0) {
list.add(TextFormatting.BLUE + "Name: " + name);
} else {
list.add(TextFormatting.BLUE + "Name: " + name + " (Id " + id + ")");
}
}
String descriptionString = tagCompound.getString("descriptionString");
constructDescriptionHelp(list, descriptionString);
Integer ticksLeft = tagCompound.getInteger("ticksLeft");
if (ticksLeft == 0) {
DimensionInformation information = RfToolsDimensionManager.getDimensionManager(player.getEntityWorld()).getDimensionInformation(id);
if (information == null) {
list.add(TextFormatting.RED + "Dimension information Missing!");
} else {
list.add(TextFormatting.BLUE + "Dimension ready!");
int maintainCost = tagCompound.getInteger("rfMaintainCost");
int actualCost = information.getActualRfCost();
if (actualCost == maintainCost || actualCost == 0) {
list.add(TextFormatting.YELLOW + " Maintenance cost: " + maintainCost + " RF/tick");
} else {
list.add(TextFormatting.YELLOW + " Maintenance cost: " + actualCost + " RF/tick (Specified: " + maintainCost + " RF/tick)");
}
if (id != 0) {
if (System.currentTimeMillis() - lastTime > 500) {
lastTime = System.currentTimeMillis();
RFToolsDimMessages.INSTANCE.sendToServer(new PacketGetDimensionEnergy(id));
}
DimensionStorage storage = DimensionStorage.getDimensionStorage(player.getEntityWorld());
int power = storage.getEnergyLevel(id);
list.add(TextFormatting.YELLOW + " Current power: " + power + " RF");
}
}
} else {
int createCost = tagCompound.getInteger("rfCreateCost");
int maintainCost = tagCompound.getInteger("rfMaintainCost");
int tickCost = tagCompound.getInteger("tickCost");
int percentage = (tickCost - ticksLeft) * 100 / tickCost;
list.add(TextFormatting.BLUE + "Dimension progress: " + percentage + "%");
list.add(TextFormatting.YELLOW + " Creation cost: " + createCost + " RF/tick");
list.add(TextFormatting.YELLOW + " Maintenance cost: " + maintainCost + " RF/tick");
list.add(TextFormatting.YELLOW + " Tick cost: " + tickCost + " ticks");
}
}
}
use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class DimensionMonitorItem method initModel.
@Override
@SideOnly(Side.CLIENT)
public void initModel() {
for (int i = 0; i <= 8; i++) {
ResourceLocation registryName = getRegistryName();
registryName = new ResourceLocation(registryName.getResourceDomain(), registryName.getResourcePath() + i);
ModelBakery.registerItemVariants(this, new ModelResourceLocation(registryName, "inventory"));
// ModelBakery.addVariantName(this, getRegistryName() + i);
}
ModelLoader.setCustomMeshDefinition(this, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
WorldClient world = MinecraftTools.getWorld(Minecraft.getMinecraft());
int id = world.provider.getDimension();
DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
int energyLevel = storage.getEnergyLevel(id);
int level = (9 * energyLevel) / PowerConfiguration.MAX_DIMENSION_POWER;
if (level < 0) {
level = 0;
} else if (level > 8) {
level = 8;
}
ResourceLocation registryName = getRegistryName();
registryName = new ResourceLocation(registryName.getResourceDomain(), registryName.getResourcePath() + (8 - level));
return new ModelResourceLocation(registryName, "inventory");
}
});
}
Aggregations