Search in sources :

Example 26 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager 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 27 with RfToolsDimensionManager

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

the class ForgeEventHandlers method onPlayerLoggedIn.

@SubscribeEvent
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
    Logging.log("SMP: Player logged in: Sync diminfo to clients");
    EntityPlayer player = event.player;
    RfToolsDimensionManager manager = RfToolsDimensionManager.getDimensionManager(player.getEntityWorld());
    manager.syncDimletRules(player);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 28 with RfToolsDimensionManager

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

the class DimensionEnscriberTileEntity 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 29 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager 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 30 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager 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

RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)30 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)21 ItemStack (net.minecraft.item.ItemStack)10 EntityPlayer (net.minecraft.entity.player.EntityPlayer)9 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)8 World (net.minecraft.world.World)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 TextComponentString (net.minecraft.util.text.TextComponentString)7 ITextComponent (net.minecraft.util.text.ITextComponent)5 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)4 IBlockState (net.minecraft.block.state.IBlockState)4 ActionResult (net.minecraft.util.ActionResult)4 EnumActionResult (net.minecraft.util.EnumActionResult)4 BlockPos (net.minecraft.util.math.BlockPos)3 File (java.io.File)2 IOException (java.io.IOException)2 DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)2 PacketGetDimensionEnergy (mcjty.rftoolsdim.network.PacketGetDimensionEnergy)2 Block (net.minecraft.block.Block)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2