Search in sources :

Example 11 with DimensionStorage

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);
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 12 with DimensionStorage

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
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) IAnimals(net.minecraft.entity.passive.IAnimals) IMob(net.minecraft.entity.monster.IMob) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 13 with DimensionStorage

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;
            }
        }
    }
}
Also used : GenericEnergyProviderTileEntity(mcjty.lib.entity.GenericEnergyProviderTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Example 14 with DimensionStorage

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");
    }
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) PacketGetDimensionEnergy(mcjty.rftoolsdim.network.PacketGetDimensionEnergy) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 15 with DimensionStorage

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);
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Aggregations

DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)16 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)11 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)8 World (net.minecraft.world.World)5 PacketGetDimensionEnergy (mcjty.rftoolsdim.network.PacketGetDimensionEnergy)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ITextComponent (net.minecraft.util.text.ITextComponent)3 TextComponentString (net.minecraft.util.text.TextComponentString)3 File (java.io.File)2 IOException (java.io.IOException)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ActionResult (net.minecraft.util.ActionResult)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 Map (java.util.Map)1 GenericEnergyProviderTileEntity (mcjty.lib.entity.GenericEnergyProviderTileEntity)1 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)1 GenericWorldProvider (mcjty.rftoolsdim.dimensions.world.GenericWorldProvider)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1