Search in sources :

Example 1 with MineralMix

use of blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix in project ImmersiveEngineering by BluSunrize.

the class EventHandler method onLogin.

@SubscribeEvent(priority = EventPriority.HIGH)
public void onLogin(PlayerLoggedInEvent event) {
    ExcavatorHandler.allowPackets = true;
    if (!event.player.worldObj.isRemote) {
        HashMap<MineralMix, Integer> packetMap = new HashMap<MineralMix, Integer>();
        for (Entry<MineralMix, Integer> e : ExcavatorHandler.mineralList.entrySet()) if (e.getKey() != null && e.getValue() != null)
            packetMap.put(e.getKey(), e.getValue());
        ImmersiveEngineering.packetHandler.sendToAll(new MessageMineralListSync(packetMap));
    }
}
Also used : MessageMineralListSync(blusunrize.immersiveengineering.common.util.network.MessageMineralListSync) MineralMix(blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with MineralMix

use of blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix in project ImmersiveEngineering by BluSunrize.

the class MessageMineralListSync method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    int size = buf.readInt();
    for (int i = 0; i < size; i++) {
        NBTTagCompound tag = ByteBufUtils.readTag(buf);
        MineralMix mix = MineralMix.readFromNBT(tag);
        if (mix != null)
            map.put(mix, tag.getInteger("weight"));
    }
}
Also used : MineralMix(blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with MineralMix

use of blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix 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 4 with MineralMix

use of blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix in project ImmersiveEngineering by BluSunrize.

the class MessageMineralListSync method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(map.size());
    for (Map.Entry<MineralMix, Integer> e : map.entrySet()) {
        NBTTagCompound tag = e.getKey().writeToNBT();
        tag.setInteger("weight", e.getValue());
        ByteBufUtils.writeTag(buf, tag);
    }
}
Also used : MineralMix(blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

MineralMix (blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralMix)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 DimensionChunkCoords (blusunrize.immersiveengineering.api.DimensionChunkCoords)1 MineralWorldInfo (blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo)1 MessageMineralListSync (blusunrize.immersiveengineering.common.util.network.MessageMineralListSync)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1