use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class CmdSetPower method execute.
@Override
public void execute(ICommandSender sender, String[] args) {
if (args.length > 2) {
ITextComponent component = new TextComponentString(TextFormatting.RED + "Too many parameters!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
return;
}
int rf = fetchInt(sender, args, 1, PowerConfiguration.MAX_DIMENSION_POWER);
World world = sender.getEntityWorld();
int dim = world.provider.getDimension();
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
DimensionInformation information = dimensionManager.getDimensionInformation(dim);
if (information == null) {
ITextComponent component = new TextComponentString(TextFormatting.RED + "Not an RFTools dimension!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
return;
}
DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
storage.setEnergyLevel(dim, rf);
storage.save(world);
}
use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class ForgeEventHandlers method onEntitySpawnEvent.
@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
World world = event.getWorld();
WorldProvider provider = world.provider;
if (!(provider instanceof GenericWorldProvider))
return;
DimensionInformation dimensionInformation = ((GenericWorldProvider) provider).getDimensionInformation();
if (PowerConfiguration.preventSpawnUnpowered) {
DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
if (storage.getEnergyLevel(provider.getDimension()) <= 0) {
event.setResult(Event.Result.DENY);
Logging.logDebug("Dimension power low: Prevented a spawn of " + event.getEntity().getClass().getName());
}
}
if (dimensionInformation.hasEffectType(EffectType.EFFECT_STRONGMOBS) || dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
if (event.getEntity() instanceof EntityLivingBase) {
EntityLivingBase entityLivingBase = (EntityLivingBase) event.getEntity();
IAttributeInstance entityAttribute = entityLivingBase.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH);
double newMax = entityAttribute.getBaseValue() * (dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS) ? GeneralConfiguration.brutalMobsFactor : GeneralConfiguration.strongMobsFactor);
entityAttribute.setBaseValue(newMax);
entityLivingBase.setHealth((float) newMax);
}
}
if (event.getEntity() instanceof IMob) {
/* BlockPos coordinate = new BlockPos((int) event.getEntity().posX, (int) event.getEntity().posY, (int) event.getEntity().posZ);
if (PeacefulAreaManager.isPeaceful(new GlobalCoordinate(coordinate, id))) {
event.setResult(Event.Result.DENY);
Logging.logDebug("Peaceful manager: Prevented a spawn of " + event.entity.getClass().getName());
} else */
if (dimensionInformation.isPeaceful()) {
// RFTools dimension.
event.setResult(Event.Result.DENY);
Logging.logDebug("Peaceful dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
}
} else if (event.getEntity() instanceof IAnimals && dimensionInformation.isNoanimals()) {
// RFTools dimension.
event.setResult(Event.Result.DENY);
Logging.logDebug("Noanimals dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
}
// @todo
}
use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class EnergyExtractorTileEntity method checkStateServer.
private void checkStateServer() {
int energyStored = getEnergyStored();
if (energyStored < MachineConfiguration.EXTRACTOR_MAXENERGY) {
// Get energy out of the dimension.
DimensionStorage storage = DimensionStorage.getDimensionStorage(getWorld());
int dimensionEnergy = storage.getEnergyLevel(getWorld().provider.getDimension());
int needed = MachineConfiguration.EXTRACTOR_MAXENERGY - energyStored;
if (needed > dimensionEnergy) {
needed = dimensionEnergy;
}
if (needed > 0) {
energyStored += needed;
dimensionEnergy -= needed;
modifyEnergyStored(needed);
storage.setEnergyLevel(getWorld().provider.getDimension(), dimensionEnergy);
storage.save(getWorld());
}
}
if (energyStored <= 0) {
return;
}
int rf = MachineConfiguration.EXTRACTOR_SENDPERTICK;
for (EnumFacing facing : EnumFacing.values()) {
BlockPos pos = getPos().offset(facing);
TileEntity te = getWorld().getTileEntity(pos);
EnumFacing opposite = facing.getOpposite();
if (EnergyTools.isEnergyTE(te) || (te != null && te.hasCapability(CapabilityEnergy.ENERGY, opposite))) {
int rfToGive = rf <= energyStored ? rf : energyStored;
int received;
if (McJtyLib.redstoneflux && RedstoneFluxCompatibility.isEnergyConnection(te)) {
if (RedstoneFluxCompatibility.canConnectEnergy(te, opposite)) {
received = EnergyTools.receiveEnergy(te, opposite, rfToGive);
} else {
received = 0;
}
} else {
// Forge unit
received = EnergyTools.receiveEnergy(te, opposite, rfToGive);
}
energyStored -= storage.extractEnergy(received, false);
if (energyStored <= 0) {
break;
}
}
}
}
use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class DimensionMonitorItem method addInformation.
// @SideOnly(Side.CLIENT)
// @Override
// public IIcon getIconIndex(ItemStack stack) {
// EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
// int id = player.worldObj.provider.dimensionId;
// DimensionStorage storage = DimensionStorage.getDimensionStorage(player.worldObj);
// int energyLevel = storage.getEnergyLevel(id);
// int level = (9*energyLevel) / DimletConfiguration.MAX_DIMENSION_POWER;
// if (level < 0) {
// level = 0;
// } else if (level > 8) {
// level = 8;
// }
// return powerLevel[8-level];
// }
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemStack, World world, List<String> list, ITooltipFlag whatIsThis) {
super.addInformation(itemStack, world, list, whatIsThis);
if (world == null || world.provider == null) {
return;
}
int id = world.provider.getDimension();
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManagerClientNullable(world);
DimensionInformation dimensionInformation = dimensionManager == null ? null : dimensionManager.getDimensionInformation(id);
if (dimensionInformation == null) {
list.add("Not an RFTools dimension!");
} else {
if (System.currentTimeMillis() - lastTime > 500) {
lastTime = System.currentTimeMillis();
RFToolsDimMessages.INSTANCE.sendToServer(new PacketGetDimensionEnergy(id));
}
String name = dimensionInformation.getName();
DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
int power = storage != null ? storage.getEnergyLevel(id) : 0;
list.add(TextFormatting.BLUE + "Name: " + name + " (Id " + id + ")");
list.add(TextFormatting.YELLOW + "Power: " + power + " RF");
}
}
use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.
the class DimensionMonitorItem method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
int id = player.getEntityWorld().provider.getDimension();
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(player.getEntityWorld());
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, TextFormatting.BLUE + "Name: " + name + " (Id " + id + ")" + TextFormatting.YELLOW + " Power: " + power + " RF");
if (player.isSneaking()) {
Logging.message(player, TextFormatting.RED + "Description: " + dimensionInformation.getDescriptor().getDescriptionString());
System.out.println("Description: = " + dimensionInformation.getDescriptor().getDescriptionString());
}
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
Aggregations