Search in sources :

Example 21 with RfToolsDimensionManager

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

the class ForgeEventHandlers method onPlayerInterractEvent.

@SubscribeEvent
public void onPlayerInterractEvent(PlayerInteractEvent event) {
    if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
        World world = event.world;
        if (!world.isRemote) {
            Block block = world.getBlock(event.x, event.y, event.z);
            if (block instanceof BlockBed) {
                RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
                if (dimensionManager.getDimensionInformation(world.provider.dimensionId) != null) {
                    // We are in an RFTools dimension.
                    switch(DimletConfiguration.bedBehaviour) {
                        case 0:
                            event.setCanceled(true);
                            Logging.message(event.entityPlayer, "You cannot sleep in this dimension!");
                            break;
                        case 1:
                            // Just do the usual thing (this typically mean explosion).
                            break;
                        case 2:
                            event.setCanceled(true);
                            int meta = BedControl.getBedMeta(world, event.x, event.y, event.z);
                            if (meta != -1) {
                                BedControl.trySleep(world, event.entityPlayer, event.x, event.y, event.z, meta);
                            }
                            break;
                    }
                }
            }
        }
    }
}
Also used : Block(net.minecraft.block.Block) BlockBed(net.minecraft.block.BlockBed) World(net.minecraft.world.World) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 22 with RfToolsDimensionManager

use of mcjty.rftools.dimension.RfToolsDimensionManager 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 23 with RfToolsDimensionManager

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

the class ForgeEventHandlers method onReplaceBiomeBlocks.

@SubscribeEvent
public void onReplaceBiomeBlocks(ChunkProviderEvent.ReplaceBiomeBlocks event) {
    World world = event.world;
    if (world == null) {
        return;
    }
    int id = world.provider.dimensionId;
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation information = dimensionManager.getDimensionInformation(id);
    if (information != null && information.hasFeatureType(FeatureType.FEATURE_CLEAN)) {
        event.setResult(Event.Result.DENY);
    }
}
Also used : World(net.minecraft.world.World) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 24 with RfToolsDimensionManager

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

the class ForgeTerrainGenHandlers method onDecorateBiome.

@SubscribeEvent
public void onDecorateBiome(DecorateBiomeEvent.Decorate event) {
    World world = event.world;
    int id = world.provider.dimensionId;
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation information = dimensionManager.getDimensionInformation(id);
    if (information != null && information.hasFeatureType(FeatureType.FEATURE_CLEAN)) {
        event.setResult(Event.Result.DENY);
    }
}
Also used : World(net.minecraft.world.World) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 25 with RfToolsDimensionManager

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

the class BedControl method trySleep.

public static boolean trySleep(World world, EntityPlayer player, int x, int y, int z, int meta) {
    if (BlockBed.func_149976_c(meta)) {
        EntityPlayer entityplayer1 = null;
        for (Object playerEntity : world.playerEntities) {
            EntityPlayer entityplayer2 = (EntityPlayer) playerEntity;
            if (entityplayer2.isPlayerSleeping()) {
                ChunkCoordinates chunkcoordinates = entityplayer2.playerLocation;
                if (chunkcoordinates.posX == x && chunkcoordinates.posY == y && chunkcoordinates.posZ == z) {
                    entityplayer1 = entityplayer2;
                }
            }
        }
        if (entityplayer1 != null) {
            player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.occupied"));
            return true;
        }
        BlockBed.func_149979_a(world, x, y, z, false);
    }
    EntityPlayer.EnumStatus enumstatus = player.sleepInBedAt(x, y, z);
    if (enumstatus == EntityPlayer.EnumStatus.OK) {
        BlockBed.func_149979_a(world, x, y, z, true);
        RfToolsDimensionManager manager = RfToolsDimensionManager.getDimensionManager(world);
        DimensionInformation information = manager.getDimensionInformation(world.provider.dimensionId);
        if (DimletConfiguration.respawnSameDim || (information != null && information.isRespawnHere())) {
            player.addChatComponentMessage(new ChatComponentText("Somehow this place feels more like home now."));
        }
        return true;
    } else {
        if (enumstatus == EntityPlayer.EnumStatus.NOT_POSSIBLE_NOW) {
            player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.noSleep"));
        } else if (enumstatus == EntityPlayer.EnumStatus.NOT_SAFE) {
            player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.notSafe"));
        }
        return true;
    }
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ChunkCoordinates(net.minecraft.util.ChunkCoordinates) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) ChatComponentText(net.minecraft.util.ChatComponentText) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Aggregations

RfToolsDimensionManager (mcjty.rftools.dimension.RfToolsDimensionManager)43 DimensionInformation (mcjty.rftools.dimension.DimensionInformation)29 World (net.minecraft.world.World)27 ChatComponentText (net.minecraft.util.ChatComponentText)16 DimensionStorage (mcjty.rftools.dimension.DimensionStorage)11 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 DimensionDescriptor (mcjty.rftools.dimension.description.DimensionDescriptor)5 ItemStack (net.minecraft.item.ItemStack)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 File (java.io.File)3 Coordinate (mcjty.lib.varia.Coordinate)3 EffectType (mcjty.rftools.dimension.world.types.EffectType)3 IOException (java.io.IOException)2 Map (java.util.Map)2 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)2 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)2 TeleportDestinations (mcjty.rftools.blocks.teleporter.TeleportDestinations)2 IMob (net.minecraft.entity.monster.IMob)2 IAnimals (net.minecraft.entity.passive.IAnimals)2