Search in sources :

Example 1 with DimensionChunkCoords

use of blusunrize.immersiveengineering.api.DimensionChunkCoords in project ImmersiveEngineering by BluSunrize.

the class CommandMineral method perform.

@Override
public void perform(CommandHandler handler, MinecraftServer server, ICommandSender sender, String[] args) {
    if (args.length > 1) {
        DimensionChunkCoords coords = new DimensionChunkCoords(sender.getEntityWorld().provider.getDimension(), (sender.getPosition().getX() >> 4), (sender.getPosition().getZ() >> 4));
        switch(args[1]) {
            case "list":
                String s = "";
                int i = 0;
                for (MineralMix mm : ExcavatorHandler.mineralList.keySet()) s += ((i++) > 0 ? ", " : "") + mm.name;
                sender.addChatMessage(new TextComponentString(s));
                break;
            case "get":
                MineralWorldInfo info = ExcavatorHandler.getMineralWorldInfo(sender.getEntityWorld(), coords.chunkXPos, coords.chunkZPos);
                sender.addChatMessage(new TextComponentTranslation(Lib.CHAT_COMMAND + getIdent() + ".get", TextFormatting.GOLD + (info.mineral != null ? info.mineral.name : "null") + TextFormatting.RESET, TextFormatting.GOLD + (info.mineralOverride != null ? info.mineralOverride.name : "null") + TextFormatting.RESET, TextFormatting.GOLD + ("" + info.depletion) + TextFormatting.RESET));
                break;
            case "set":
                info = ExcavatorHandler.getMineralWorldInfo(sender.getEntityWorld(), coords.chunkXPos, coords.chunkZPos);
                if (args.length < 3) {
                    sender.addChatMessage(new TextComponentTranslation(Lib.CHAT_COMMAND + getIdent() + ".set.clear", info.mineralOverride != null ? info.mineralOverride.name : "null"));
                    info.mineralOverride = null;
                    return;
                }
                MineralMix mineral = null;
                for (MineralMix mm : ExcavatorHandler.mineralList.keySet()) if (mm.name.equalsIgnoreCase(args[2]))
                    mineral = mm;
                if (mineral == null) {
                    sender.addChatMessage(new TextComponentTranslation(Lib.CHAT_COMMAND + getIdent() + ".set.invalidMineral", args[2]));
                    return;
                }
                info.mineralOverride = mineral;
                sender.addChatMessage(new TextComponentTranslation(Lib.CHAT_COMMAND + getIdent() + ".set.sucess", mineral.name));
                IESaveData.setDirty(sender.getEntityWorld().provider.getDimension());
                break;
            case "setDepletion":
                info = ExcavatorHandler.getMineralWorldInfo(sender.getEntityWorld(), coords.chunkXPos, coords.chunkZPos);
                if (args.length < 3) {
                    String h = I18n.translateToLocal(getHelp(".setDepletion"));
                    for (String str : h.split("<br>")) sender.addChatMessage(new TextComponentString(str));
                    return;
                }
                int depl = 0;
                try {
                    depl = Integer.parseInt(args[2].trim());
                } catch (Exception e) {
                    sender.addChatMessage(new TextComponentTranslation(Lib.CHAT_COMMAND + getIdent() + ".setDepletion.NFE", args[2].trim()));
                    return;
                }
                info.depletion = depl;
                sender.addChatMessage(new TextComponentTranslation(Lib.CHAT_COMMAND + getIdent() + ".setDepletion.sucess", (depl < 0 ? I18n.translateToLocal(Lib.CHAT_INFO + "coreDrill.infinite") : Integer.toString(depl))));
                IESaveData.setDirty(sender.getEntityWorld().provider.getDimension());
                break;
            default:
                sender.addChatMessage(new TextComponentTranslation(getHelp("")));
                break;
        }
    } else
        sender.addChatMessage(new TextComponentTranslation(getHelp("")));
}
Also used : DimensionChunkCoords(blusunrize.immersiveengineering.api.DimensionChunkCoords) MineralMix(blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MineralWorldInfo(blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with DimensionChunkCoords

use of blusunrize.immersiveengineering.api.DimensionChunkCoords in project ImmersiveEngineering by BluSunrize.

the class ExcavatorHandler method getMineralWorldInfo.

public static MineralWorldInfo getMineralWorldInfo(World world, int chunkX, int chunkZ) {
    if (world.isRemote)
        return null;
    int dim = world.provider.getDimension();
    DimensionChunkCoords coords = new DimensionChunkCoords(dim, chunkX, chunkZ);
    MineralWorldInfo worldInfo = mineralCache.get(coords);
    if (worldInfo == null) {
        MineralMix mix = null;
        Random r = world.getChunkFromChunkCoords(chunkX, chunkZ).getRandomWithSeed(940610);
        double dd = r.nextDouble();
        boolean empty = dd > mineralChance;
        int query = r.nextInt();
        if (!empty) {
            int weight = Math.abs(query % getDimensionTotalWeight(dim));
            for (Map.Entry<MineralMix, Integer> e : mineralList.entrySet()) if (e.getKey().isValid() && e.getKey().validDimension(dim)) {
                weight -= e.getValue();
                if (weight < 0) {
                    mix = e.getKey();
                    break;
                }
            }
        }
        worldInfo = new MineralWorldInfo();
        worldInfo.mineral = mix;
        mineralCache.put(coords, worldInfo);
    }
    return worldInfo;
}
Also used : DimensionChunkCoords(blusunrize.immersiveengineering.api.DimensionChunkCoords)

Example 3 with DimensionChunkCoords

use of blusunrize.immersiveengineering.api.DimensionChunkCoords in project ImmersiveEngineering by BluSunrize.

the class IESaveData method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    Integer[] relDim = ImmersiveNetHandler.INSTANCE.getRelevantDimensions().toArray(new Integer[0]);
    int[] savedDimensions = new int[relDim.length];
    for (int ii = 0; ii < relDim.length; ii++) savedDimensions[ii] = relDim[ii];
    nbt.setIntArray("savedDimensions", savedDimensions);
    for (int dim : savedDimensions) {
        NBTTagList connectionList = new NBTTagList();
        for (Connection con : ImmersiveNetHandler.INSTANCE.getAllConnections(dim)) {
            connectionList.appendTag(con.writeToNBT());
        }
        nbt.setTag("connectionList" + dim, connectionList);
    }
    NBTTagList proxies = new NBTTagList();
    for (IICProxy iic : ImmersiveNetHandler.INSTANCE.proxies.values()) proxies.appendTag(iic.writeToNBT());
    nbt.setTag("iicProxies", proxies);
    NBTTagList mineralList = new NBTTagList();
    for (Map.Entry<DimensionChunkCoords, MineralWorldInfo> e : ExcavatorHandler.mineralCache.entrySet()) if (e.getKey() != null && e.getValue() != null) {
        NBTTagCompound tag = e.getKey().writeToNBT();
        tag.setTag("info", e.getValue().writeToNBT());
        mineralList.appendTag(tag);
    }
    nbt.setTag("mineralDepletion", mineralList);
    NBTTagList receivedShaderList = new NBTTagList();
    for (String player : ShaderRegistry.receivedShaders.keySet()) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setString("player", player);
        NBTTagList playerReceived = new NBTTagList();
        for (String shader : ShaderRegistry.receivedShaders.get(player)) if (shader != null && !shader.isEmpty())
            playerReceived.appendTag(new NBTTagString(shader));
        tag.setTag("received", playerReceived);
        receivedShaderList.appendTag(tag);
    }
    nbt.setTag("receivedShaderList", receivedShaderList);
    return nbt;
}
Also used : MineralWorldInfo(blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo) IICProxy(blusunrize.immersiveengineering.api.energy.wires.IICProxy) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagList(net.minecraft.nbt.NBTTagList) DimensionChunkCoords(blusunrize.immersiveengineering.api.DimensionChunkCoords) NBTTagString(net.minecraft.nbt.NBTTagString) Map(java.util.Map)

Example 4 with DimensionChunkCoords

use of blusunrize.immersiveengineering.api.DimensionChunkCoords in project ImmersiveEngineering by BluSunrize.

the class IESaveData method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    // Load new info from NBT
    int[] savedDimensions = nbt.getIntArray("savedDimensions");
    for (int dim : savedDimensions) {
        NBTTagList connectionList = nbt.getTagList("connectionList" + dim, 10);
        for (int i = 0; i < connectionList.tagCount(); i++) {
            NBTTagCompound conTag = connectionList.getCompoundTagAt(i);
            Connection con = Connection.readFromNBT(conTag);
            if (con != null) {
                ImmersiveNetHandler.INSTANCE.addConnection(dim, con.start, con);
            }
        }
    }
    NBTTagList proxies = nbt.getTagList("iicProxies", 10);
    for (int i = 0; i < proxies.tagCount(); i++) ImmersiveNetHandler.INSTANCE.addProxy(IICProxy.readFromNBT(proxies.getCompoundTagAt(i)));
    EventHandler.validateConnsNextTick = true;
    NBTTagList mineralList = nbt.getTagList("mineralDepletion", 10);
    ExcavatorHandler.mineralCache.clear();
    for (int i = 0; i < mineralList.tagCount(); i++) {
        NBTTagCompound tag = mineralList.getCompoundTagAt(i);
        DimensionChunkCoords coords = DimensionChunkCoords.readFromNBT(tag);
        if (coords != null) {
            MineralWorldInfo info = MineralWorldInfo.readFromNBT(tag.getCompoundTag("info"));
            ExcavatorHandler.mineralCache.put(coords, info);
        }
    }
    NBTTagList receivedShaderList = nbt.getTagList("receivedShaderList", 10);
    for (int i = 0; i < receivedShaderList.tagCount(); i++) {
        NBTTagCompound tag = receivedShaderList.getCompoundTagAt(i);
        String player = tag.getString("player");
        ShaderRegistry.receivedShaders.get(player).clear();
        NBTTagList playerReceived = tag.getTagList("received", 8);
        for (int j = 0; j < playerReceived.tagCount(); j++) {
            String s = playerReceived.getStringTagAt(j);
            if (s != null && !s.isEmpty())
                ShaderRegistry.receivedShaders.put(player, s);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) DimensionChunkCoords(blusunrize.immersiveengineering.api.DimensionChunkCoords) MineralWorldInfo(blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) NBTTagString(net.minecraft.nbt.NBTTagString)

Aggregations

DimensionChunkCoords (blusunrize.immersiveengineering.api.DimensionChunkCoords)4 MineralWorldInfo (blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo)3 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 IICProxy (blusunrize.immersiveengineering.api.energy.wires.IICProxy)1 MineralMix (blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix)1 Map (java.util.Map)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1