Search in sources :

Example 21 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.

the class ActivityProbeBlock method clGetStateForPlacement.

@Override
protected IBlockState clGetStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    IBlockState state = super.clGetStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer);
    if (!world.isRemote) {
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
        DimensionInformation information = dimensionManager.getDimensionInformation(world.provider.getDimension());
        if (information != null) {
            information.addProbe();
        }
        dimensionManager.save(world);
    }
    return state;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 22 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.

the class EssencePainterTileEntity method setName.

private void setName(String name) {
    ItemStack realizedTab = inventoryHelper.getStackInSlot(EssencePainterContainer.SLOT_TAB);
    if (realizedTab != null) {
        NBTTagCompound tagCompound = realizedTab.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            realizedTab.setTagCompound(tagCompound);
        }
        tagCompound.setString("name", name);
        if (tagCompound.hasKey("id")) {
            Integer id = tagCompound.getInteger("id");
            RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
            DimensionInformation information = dimensionManager.getDimensionInformation(id);
            if (information != null) {
                information.setName(name);
                dimensionManager.save(getWorld());
            }
        }
        markDirty();
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 23 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.

the class EssencePainterTileEntity method createRealizedTab.

/**
     * Create a realized dimension tab by taking a map of ids per type and storing
     * that in the NBT of the realized dimension tab.
     */
public static ItemStack createRealizedTab(DimensionDescriptor descriptor, World world) {
    ItemStack realizedTab = new ItemStack(ModItems.realizedDimensionTabItem, 1, 0);
    NBTTagCompound tagCompound = new NBTTagCompound();
    descriptor.writeToNBT(tagCompound);
    // Check if the dimension already exists and if so set the progress to 100%.
    RfToolsDimensionManager manager = RfToolsDimensionManager.getDimensionManager(world);
    Integer id = manager.getDimensionID(descriptor);
    if (id != null) {
        // The dimension was already created.
        tagCompound.setInteger("ticksLeft", 0);
        tagCompound.setInteger("id", id);
    }
    realizedTab.setTagCompound(tagCompound);
    return realizedTab;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 24 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onEntitySpawnEvent.

@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
    World world = event.getWorld();
    int id = world.provider.getDimension();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
    if (PowerConfiguration.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.getEntity().getClass().getName());
            }
        }
    }
    if (dimensionInformation != null) {
        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;
                if (dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
                    newMax = entityAttribute.getBaseValue() * GeneralConfiguration.brutalMobsFactor;
                } else {
                    newMax = entityAttribute.getBaseValue() * 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 != null && 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) {
        if (dimensionInformation != null && 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) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 25 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onPlayerRightClickEvent.

@SubscribeEvent
public void onPlayerRightClickEvent(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    if (!world.isRemote) {
        Block block = world.getBlockState(event.getPos()).getBlock();
        if (block instanceof BlockBed) {
            RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
            if (dimensionManager.getDimensionInformation(world.provider.getDimension()) != null) {
                // We are in an RFTools dimension.
                switch(GeneralConfiguration.bedBehaviour) {
                    case 0:
                        event.setCanceled(true);
                        Logging.message(event.getEntityPlayer(), "You cannot sleep in this dimension!");
                        break;
                    case 1:
                        // Just do the usual thing (this typically mean explosion).
                        break;
                    case 2:
                        event.setCanceled(true);
                        event.getEntityPlayer().setSpawnChunk(event.getPos(), true, event.getWorld().provider.getDimension());
                        Logging.message(event.getEntityPlayer(), "Spawn point set!");
                        break;
                }
            }
        }
    }
}
Also used : Block(net.minecraft.block.Block) BlockBed(net.minecraft.block.BlockBed) World(net.minecraft.world.World) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)31 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)22 World (net.minecraft.world.World)14 ItemStack (net.minecraft.item.ItemStack)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)8 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 TextComponentString (net.minecraft.util.text.TextComponentString)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)4 BlockPos (net.minecraft.util.math.BlockPos)4 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 File (java.io.File)2 IOException (java.io.IOException)2 DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 IMob (net.minecraft.entity.monster.IMob)2 IAnimals (net.minecraft.entity.passive.IAnimals)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2