Search in sources :

Example 11 with DimensionStorage

use of mcjty.rftools.dimension.DimensionStorage in project RFTools by McJty.

the class ReturnEnergyHelper method setEnergyLevel.

public static void setEnergyLevel(PacketReturnEnergy message) {
    World world = Minecraft.getMinecraft().theWorld;
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(world);
    dimensionStorage.setEnergyLevel(message.getId(), message.getEnergy());
}
Also used : DimensionStorage(mcjty.rftools.dimension.DimensionStorage) World(net.minecraft.world.World)

Example 12 with DimensionStorage

use of mcjty.rftools.dimension.DimensionStorage in project RFTools by McJty.

the class ForgeEventHandlers method onAttackEntityEvent.

@SubscribeEvent
public void onAttackEntityEvent(AttackEntityEvent event) {
    World world = event.entityPlayer.getEntityWorld();
    int id = world.provider.dimensionId;
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    if (dimensionManager.getDimensionInformation(id) != null) {
        // RFTools dimension.
        DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
        int energy = storage.getEnergyLevel(id);
        if (energy <= 0) {
            event.setCanceled(true);
        }
    }
}
Also used : DimensionStorage(mcjty.rftools.dimension.DimensionStorage) World(net.minecraft.world.World) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 13 with DimensionStorage

use of mcjty.rftools.dimension.DimensionStorage in project RFTools by McJty.

the class ForgeEventHandlers method onEntitySpawnEvent.

@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
    World world = event.world;
    int id = world.provider.dimensionId;
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
    if (DimletConfiguration.preventSpawnUnpowered) {
        if (dimensionInformation != null) {
            // RFTools dimension.
            DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
            int energy = storage.getEnergyLevel(id);
            if (energy <= 0) {
                event.setResult(Event.Result.DENY);
                Logging.logDebug("Dimension power low: Prevented a spawn of " + event.entity.getClass().getName());
            }
        }
    }
    if (dimensionInformation != null) {
        if (dimensionInformation.hasEffectType(EffectType.EFFECT_STRONGMOBS) || dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
            if (event.entity instanceof EntityLivingBase) {
                EntityLivingBase entityLivingBase = (EntityLivingBase) event.entity;
                IAttributeInstance entityAttribute = entityLivingBase.getEntityAttribute(SharedMonsterAttributes.maxHealth);
                double newMax;
                if (dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
                    newMax = entityAttribute.getBaseValue() * DimletConfiguration.brutalMobsFactor;
                } else {
                    newMax = entityAttribute.getBaseValue() * DimletConfiguration.strongMobsFactor;
                }
                entityAttribute.setBaseValue(newMax);
                entityLivingBase.setHealth((float) newMax);
            }
        }
    }
    if (event.entity instanceof IMob) {
        Coordinate coordinate = new Coordinate((int) event.entity.posX, (int) event.entity.posY, (int) event.entity.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 != null && dimensionInformation.isPeaceful()) {
            // RFTools dimension.
            event.setResult(Event.Result.DENY);
            Logging.logDebug("Peaceful dimension: Prevented a spawn of " + event.entity.getClass().getName());
        }
    } else if (event.entity instanceof IAnimals) {
        if (dimensionInformation != null && dimensionInformation.isNoanimals()) {
            // RFTools dimension.
            event.setResult(Event.Result.DENY);
            Logging.logDebug("Noanimals dimension: Prevented a spawn of " + event.entity.getClass().getName());
        }
    }
}
Also used : DimensionStorage(mcjty.rftools.dimension.DimensionStorage) IAnimals(net.minecraft.entity.passive.IAnimals) IMob(net.minecraft.entity.monster.IMob) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 14 with DimensionStorage

use of mcjty.rftools.dimension.DimensionStorage in project RFTools by McJty.

the class MatterTransmitterTileEntity method checkReceiverStatus.

// Server side only
private int checkReceiverStatus() {
    TeleportDestination destination = getTeleportDestination();
    if (destination == null) {
        return TeleportationTools.STATUS_WARN;
    }
    int dimension = destination.getDimension();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(worldObj);
    if (dimensionManager.getDimensionInformation(dimension) != null) {
        // This is an RFTools dimension. Check power.
        DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(worldObj);
        int energyLevel = dimensionStorage.getEnergyLevel(dimension);
        if (energyLevel < DimletConfiguration.DIMPOWER_WARN_TP) {
            return TeleportationTools.STATUS_WARN;
        }
    }
    World w = DimensionManager.getWorld(dimension);
    // By default we will not check if the dimension is not loaded. Can be changed in config.
    if (w == null) {
        if (TeleportConfiguration.matterTransmitterLoadWorld == -1) {
            return TeleportationTools.STATUS_UNKNOWN;
        } else {
            w = MinecraftServer.getServer().worldServerForDimension(dimension);
            checkReceiverStatusCounter = TeleportConfiguration.matterTransmitterLoadWorld;
        }
    }
    Coordinate c = destination.getCoordinate();
    boolean exists = w.getChunkProvider().chunkExists(c.getX() >> 4, c.getZ() >> 4);
    if (!exists) {
        if (TeleportConfiguration.matterTransmitterLoadChunk == -1) {
            return TeleportationTools.STATUS_UNKNOWN;
        } else {
            checkReceiverStatusCounter = TeleportConfiguration.matterTransmitterLoadChunk;
        }
    }
    TileEntity tileEntity = w.getTileEntity(c.getX(), c.getY(), c.getZ());
    if (!(tileEntity instanceof MatterReceiverTileEntity)) {
        return TeleportationTools.STATUS_WARN;
    }
    MatterReceiverTileEntity matterReceiverTileEntity = (MatterReceiverTileEntity) tileEntity;
    int status = matterReceiverTileEntity.checkStatus();
    return (status == DialingDeviceTileEntity.DIAL_OK) ? TeleportationTools.STATUS_OK : TeleportationTools.STATUS_WARN;
}
Also used : GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) DimensionStorage(mcjty.rftools.dimension.DimensionStorage) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) World(net.minecraft.world.World) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Example 15 with DimensionStorage

use of mcjty.rftools.dimension.DimensionStorage in project RFTools by McJty.

the class CmdListDimensions method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    WorldServer[] worlds = DimensionManager.getWorlds();
    for (WorldServer world : worlds) {
        int id = world.provider.dimensionId;
        String dimName = world.provider.getDimensionName();
        sender.addChatMessage(new ChatComponentText("    Loaded: id:" + id + ", " + dimName));
    }
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(sender.getEntityWorld());
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(sender.getEntityWorld());
    for (Map.Entry<Integer, DimensionDescriptor> me : dimensionManager.getDimensions().entrySet()) {
        int id = me.getKey();
        DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
        String dimName = dimensionInformation.getName();
        int energy = dimensionStorage.getEnergyLevel(id);
        String ownerName = dimensionInformation.getOwnerName();
        if (ownerName != null && !ownerName.isEmpty()) {
            sender.addChatMessage(new ChatComponentText("    RfTools: id:" + id + ", " + dimName + " (power " + energy + ") (owner " + ownerName + ")"));
        } else {
            sender.addChatMessage(new ChatComponentText("    RfTools: id:" + id + ", " + dimName + " (power " + energy + ")"));
        }
    }
}
Also used : DimensionStorage(mcjty.rftools.dimension.DimensionStorage) DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor) WorldServer(net.minecraft.world.WorldServer) ChatComponentText(net.minecraft.util.ChatComponentText) Map(java.util.Map) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Aggregations

DimensionStorage (mcjty.rftools.dimension.DimensionStorage)20 RfToolsDimensionManager (mcjty.rftools.dimension.RfToolsDimensionManager)11 World (net.minecraft.world.World)10 DimensionInformation (mcjty.rftools.dimension.DimensionInformation)8 ChatComponentText (net.minecraft.util.ChatComponentText)4 TileEntity (net.minecraft.tileentity.TileEntity)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 File (java.io.File)2 IOException (java.io.IOException)2 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)2 Coordinate (mcjty.lib.varia.Coordinate)2 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)2 TeleportDestinations (mcjty.rftools.blocks.teleporter.TeleportDestinations)2 PacketGetDimensionEnergy (mcjty.rftools.dimension.network.PacketGetDimensionEnergy)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 IEnergyConnection (cofh.api.energy.IEnergyConnection)1 Map (java.util.Map)1 GenericEnergyProviderTileEntity (mcjty.lib.entity.GenericEnergyProviderTileEntity)1 DimensionDescriptor (mcjty.rftools.dimension.description.DimensionDescriptor)1