From 8ce4ae8d22f31587c600bf8190cfb88e1a4f2ea2 Mon Sep 17 00:00:00 2001 From: moller21 <42100910+moller21@users.noreply.github.com> Date: Sun, 19 Jul 2020 19:08:59 +0200 Subject: Rework clientside pollution (#302) * Rework clientside pollution * Pollution rework * removed debug --- src/main/java/gregtech/common/misc/GT_Command.java | 50 ++++++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'src/main/java/gregtech/common/misc/GT_Command.java') diff --git a/src/main/java/gregtech/common/misc/GT_Command.java b/src/main/java/gregtech/common/misc/GT_Command.java index 66ae7058bc..f3272ee341 100644 --- a/src/main/java/gregtech/common/misc/GT_Command.java +++ b/src/main/java/gregtech/common/misc/GT_Command.java @@ -1,11 +1,15 @@ package gregtech.common.misc; +import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; import gregtech.api.objects.GT_ChunkManager; +import gregtech.common.GT_Pollution; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.command.WrongUsageException; import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChunkCoordinates; + import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; @@ -21,10 +25,10 @@ public final class GT_Command extends CommandBase { @Override public String getCommandUsage(ICommandSender sender) { - return "Usage: gt . Valid subcommands are: toggle, chunks."; + return "Usage: gt . Valid subcommands are: toggle, chunks, pollution."; } private void printHelp(ICommandSender sender) { - sender.addChatMessage(new ChatComponentText("Usage: gt ")); + sender.addChatMessage(new ChatComponentText("Usage: gt ")); sender.addChatMessage(new ChatComponentText("\"toggle D1\" - toggles general.Debug (D1)")); sender.addChatMessage(new ChatComponentText("\"toggle D2\" - toggles general.Debug2 (D2)")); sender.addChatMessage(new ChatComponentText("\"toggle debugCleanroom\" - toggles cleanroom debug log")); @@ -38,6 +42,10 @@ public final class GT_Command extends CommandBase { sender.addChatMessage(new ChatComponentText("\"toggle debugStones\" - toggles worldgen stones debug")); sender.addChatMessage(new ChatComponentText("\"toggle debugChunkloaders\" - toggles chunkloaders debug")); sender.addChatMessage(new ChatComponentText("\"chunks\" - print a list of the force loaded chunks")); + sender.addChatMessage(new ChatComponentText( + "\"pollution \" - adds the of the pollution to the current chunk, " + + "\n if isnt specified, will add" + GT_Mod.gregtechproxy.mPollutionSmogLimit + "gibbl." + )); } @Override @@ -45,25 +53,24 @@ public final class GT_Command extends CommandBase { List l = new ArrayList<>(); Stream keywords = Arrays.stream(new String[]{"toggle", "chunks"}); String test = ss.length == 0 ? "" : ss[0].trim(); - if (ss.length == 0 || ss.length == 1 && (test.isEmpty() || keywords.anyMatch(s -> s.startsWith(test)))) { - keywords.forEach(s -> { - if (test.isEmpty() || s.startsWith(test)) - l.add(s); - }); + if (ss.length == 0 || ss.length == 1 && (test.isEmpty() || Stream.of("toggle", "chunks", "pollution").anyMatch(s -> s.startsWith(test)))) { + Stream.of("toggle", "chunks", "pollution") + .filter(s -> test.isEmpty() || s.startsWith(test)) + .forEach(l::add); } else if (test.equals("toggle")) { - String test1 = ss.length == 1 ? "" : ss[1].trim(); - Arrays.stream(new String[]{"D1", "D2", "debugCleanroom", "debugDriller", "debugBlockPump", "debugBlockMiner", "debugWorldGen", "debugEntityCramming", - "debugOrevein", "debugSmallOres", "debugStones", "debugChunkloaders"}).forEach(s -> { - if (test1.isEmpty() || s.startsWith(test1)) - l.add(s); - }); + String test1 = ss[1].trim(); + Stream.of("D1", "D2", "debugCleanroom", "debugDriller", "debugBlockPump", "debugBlockMiner", "debugWorldGen", "debugEntityCramming", + "debugOrevein", "debugSmallOres", "debugStones", "debugChunkloaders") + .filter(s -> test1.isEmpty() || s.startsWith(test1)) + .forEach(l::add); + } return l; } @Override public void processCommand(ICommandSender sender, String[] strings) { - if (strings.length < 1 || (!strings[0].equals("toggle") && !strings[0].equals("chunks"))) { + if (strings.length < 1) { printHelp(sender); return; } @@ -90,6 +97,21 @@ public final class GT_Command extends CommandBase { GT_ChunkManager.printTickets(); sender.addChatMessage(new ChatComponentText("Forced chunks logged to GregTech.log")); break; + case "pollution": { + ChunkCoordinates coordinates = sender.getPlayerCoordinates(); + int amount = (strings.length < 2) ? GT_Mod.gregtechproxy.mPollutionSmogLimit : Integer.parseInt(strings[1]); + GT_Pollution.addPollution(sender + .getEntityWorld() + .getChunkFromBlockCoords( + coordinates.posX, + coordinates.posZ + ), + amount + ); + break; + } + default: + printHelp(sender); } } } -- cgit