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));
}
}
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"));
}
}
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("")));
}
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);
}
}
Aggregations