diff --git a/src/main/java/net/jomcraft/frustrator/ClientEventHandler.java b/src/main/java/net/jomcraft/frustrator/ClientEventHandler.java index 1413371..d6f1e79 100644 --- a/src/main/java/net/jomcraft/frustrator/ClientEventHandler.java +++ b/src/main/java/net/jomcraft/frustrator/ClientEventHandler.java @@ -8,12 +8,14 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatStyle; import net.minecraft.util.MathHelper; import net.minecraft.util.Vec3; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.living.LivingEvent; import org.lwjgl.opengl.GL11; + import javax.annotation.Nullable; import java.sql.Array; import java.util.ArrayList; @@ -42,6 +44,8 @@ public class ClientEventHandler { public static boolean showAllMainAreas = false; public static boolean showAllTriggerAreas = false; + public static final ChatStyle style = new ChatStyle(); + public static boolean frustumCheck(final int x, final int y, final int z, final FrustumBounds frustum) { if ((x >= frustum.minX && x <= (frustum.maxX)) && (y >= frustum.minY && y <= (frustum.maxY)) && (z >= frustum.minZ && z <= (frustum.maxZ))) { return true; @@ -78,7 +82,7 @@ public void livingUpdate(LivingEvent.LivingUpdateEvent event) { return; final FrustumBounds frustum = ((IMixinEntity) event.entity).getFrustum(); - if(frustum != null) { + if (frustum != null) { boolean success = false; for (int ii = 0; ii < ClientEventHandler.localFrustums.size(); ii++) { final FrustumBounds localFrustum = ClientEventHandler.localFrustums.get(ii); @@ -88,7 +92,7 @@ public void livingUpdate(LivingEvent.LivingUpdateEvent event) { } } - if(!success) { + if (!success) { event.setCanceled(true); } } @@ -186,45 +190,40 @@ public void playerTick(TickEvent.PlayerTickEvent event) { if (!localFrustums.contains(frustum)) { Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1); } - dummyFrustums.add(frustum); + dummyFrustums.add(frustum); inFrustum = true; - //TODO: Change this! - break; } } - if (!inFrustum) { - for (int i = 0; i < triggerBounds.length; i++) { - final FrustumBounds trigger = triggerBounds[i]; - if (frustumCheck(x, y, z, trigger)) { - for(int ii = 0; ii < trigger.parents.length; ii++){ - final FrustumBounds parent = trigger.parents[ii]; - if(!localFrustums.contains(parent)) { - Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(parent.minX - 1, parent.minY - 1, parent.minZ - 1, parent.maxX + 1, parent.maxY + 1, parent.maxZ + 1); - } - dummyFrustums.add(parent); - + for (int i = 0; i < triggerBounds.length; i++) { + final FrustumBounds trigger = triggerBounds[i]; + if (frustumCheck(x, y, z, trigger)) { + for (int ii = 0; ii < trigger.parents.length; ii++) { + final FrustumBounds parent = trigger.parents[ii]; + if (!localFrustums.contains(parent)) { + Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(parent.minX - 1, parent.minY - 1, parent.minZ - 1, parent.maxX + 1, parent.maxY + 1, parent.maxZ + 1); } + dummyFrustums.add(parent); - inFrustum = true; - //break; } + + inFrustum = true; } } if (!inFrustum) { - for(int i = 0; i < localFrustums.size(); i++){ + for (int i = 0; i < localFrustums.size(); i++) { final FrustumBounds frustum = localFrustums.get(i); Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1); } localFrustums.clear(); } else { - for(int i = 0; i < localFrustums.size(); i++){ + for (int i = 0; i < localFrustums.size(); i++) { final FrustumBounds frustum = localFrustums.get(i); - if(!dummyFrustums.contains(frustum)) + if (!dummyFrustums.contains(frustum)) Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1); } @@ -289,7 +288,7 @@ public void renderWorldLast(RenderWorldLastEvent e) { boolean isTrigger = false; - for(int ii = 0; ii < frustum.parents.length; ii++){ + for (int ii = 0; ii < frustum.parents.length; ii++) { final FrustumBounds parent = frustum.parents[ii]; if (parent.equalsArea(selectedFrustum)) { isTrigger = true; diff --git a/src/main/java/net/jomcraft/frustrator/Frustrator.java b/src/main/java/net/jomcraft/frustrator/Frustrator.java index b8ea035..f2cc2df 100644 --- a/src/main/java/net/jomcraft/frustrator/Frustrator.java +++ b/src/main/java/net/jomcraft/frustrator/Frustrator.java @@ -71,7 +71,6 @@ public static void construction(FMLPreInitializationEvent event) { network.registerMessage(C2SAddTriggerPacket.Handler.class, C2SAddTriggerPacket.class, 3, Side.SERVER); network.registerMessage(S2CSyncAllAreas.Handler.class, S2CSyncAllAreas.class, 4, Side.CLIENT); network.registerMessage(S2CClearSelection.Handler.class, S2CClearSelection.class, 5, Side.CLIENT); - } @EventHandler diff --git a/src/main/java/net/jomcraft/frustrator/FrustumBounds.java b/src/main/java/net/jomcraft/frustrator/FrustumBounds.java index edac036..1f75ba3 100644 --- a/src/main/java/net/jomcraft/frustrator/FrustumBounds.java +++ b/src/main/java/net/jomcraft/frustrator/FrustumBounds.java @@ -21,9 +21,9 @@ public class FrustumBounds { @Deprecated public FrustumBounds parent; - public FrustumBounds [] parents; + public FrustumBounds[] parents; - public FrustumBounds(final int minX, final int minY, final int minZ, final int maxX, final int maxY, final int maxZ, boolean trigger, FrustumBounds [] parents) { + public FrustumBounds(final int minX, final int minY, final int minZ, final int maxX, final int maxY, final int maxZ, boolean trigger, FrustumBounds[] parents) { this.minX = minX; this.minY = minY; this.minZ = minZ; diff --git a/src/main/java/net/jomcraft/frustrator/items/ItemFrustrator.java b/src/main/java/net/jomcraft/frustrator/items/ItemFrustrator.java index cb05b05..412dcd6 100644 --- a/src/main/java/net/jomcraft/frustrator/items/ItemFrustrator.java +++ b/src/main/java/net/jomcraft/frustrator/items/ItemFrustrator.java @@ -9,10 +9,12 @@ import net.jomcraft.frustrator.network.C2SNewAreaPacket; import net.jomcraft.frustrator.network.C2SResizeAreaPacket; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.command.CommandHelp; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; +import net.minecraft.item.ItemPotion; import net.minecraft.item.ItemStack; import net.minecraft.util.*; import net.minecraft.world.World; @@ -94,20 +96,13 @@ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPl } } } else { - - if(ClientEventHandler.focusedFrustum != null && ClientEventHandler.selectedFrustum == null && ClientEventHandler.selectedTrigger != null) { - // System.out.println("CONFIRM!"); + if (ClientEventHandler.focusedFrustum != null && ClientEventHandler.selectedFrustum == null && ClientEventHandler.selectedTrigger != null) { Frustrator.network.sendToServer(new C2SAddTriggerPacket(Vec3.createVectorHelper(ClientEventHandler.selectedTrigger.minX, ClientEventHandler.selectedTrigger.minY, ClientEventHandler.selectedTrigger.minZ), Vec3.createVectorHelper(ClientEventHandler.selectedTrigger.maxX, ClientEventHandler.selectedTrigger.maxY, ClientEventHandler.selectedTrigger.maxZ), Vec3.createVectorHelper(ClientEventHandler.focusedFrustum.minX, ClientEventHandler.focusedFrustum.minY, ClientEventHandler.focusedFrustum.minZ), Vec3.createVectorHelper(ClientEventHandler.focusedFrustum.maxX, ClientEventHandler.focusedFrustum.maxY, ClientEventHandler.focusedFrustum.maxZ))); - // ClientEventHandler.selectedTrigger = null; - // pos1 = null; - // pos2 = null; } - //} else { - ClientEventHandler.selectedFrustum = ClientEventHandler.focusedFrustum; - pos1 = Vec3.createVectorHelper(ClientEventHandler.selectedFrustum.minX, ClientEventHandler.selectedFrustum.minY, ClientEventHandler.selectedFrustum.minZ); - pos2 = Vec3.createVectorHelper(ClientEventHandler.selectedFrustum.maxX, ClientEventHandler.selectedFrustum.maxY, ClientEventHandler.selectedFrustum.maxZ); - // } + ClientEventHandler.selectedFrustum = ClientEventHandler.focusedFrustum; + pos1 = Vec3.createVectorHelper(ClientEventHandler.selectedFrustum.minX, ClientEventHandler.selectedFrustum.minY, ClientEventHandler.selectedFrustum.minZ); + pos2 = Vec3.createVectorHelper(ClientEventHandler.selectedFrustum.maxX, ClientEventHandler.selectedFrustum.maxY, ClientEventHandler.selectedFrustum.maxZ); } return itemStackIn; @@ -124,10 +119,11 @@ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPl Frustrator.network.sendToServer(new C2SResizeAreaPacket(pos1, pos2, oldPos1, oldPos2)); } else { - if (ClientEventHandler.selectedFrustum == null) + if (ClientEventHandler.selectedFrustum == null) { player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "No parent main area is selected!")); - else + } else { Frustrator.network.sendToServer(new C2SNewAreaPacket(pos1, pos2, ClientEventHandler.selectedFrustum)); + } } if (ClientEventHandler.selectedFrustum != null) { @@ -195,9 +191,55 @@ public void registerIcons(IIconRegister register) { @Override public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); - p_77624_3_.add(new ChatComponentText(EnumChatFormatting.GOLD + "Right Click on block: " + EnumChatFormatting.AQUA + "First marker").getUnformattedTextForChat()); - p_77624_3_.add(new ChatComponentText(EnumChatFormatting.GOLD + "SHIFT + Right Click on block: " + EnumChatFormatting.AQUA + "Second marker").getUnformattedTextForChat()); - p_77624_3_.add(new ChatComponentText("").getUnformattedTextForChat()); - p_77624_3_.add(new ChatComponentText(EnumChatFormatting.GOLD + "SHIFT + Right Click on air: " + EnumChatFormatting.AQUA + "Confirm area modification/creation").getUnformattedTextForChat()); + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.onBlock") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.rightClick.firstMarker")); + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.shiftOnBlock") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.rightClick.secondMarker")); + + if (p_77624_1_.getItemDamage() == 0) { + if (ClientEventHandler.focusedFrustum == null) { + if (pos1 != null && pos2 != null) { + if (ClientEventHandler.selectedFrustum != null) { + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.onAir") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.confirm.resizeMainArea")); + } else { + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.onAir") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.confirm.creationMainArea")); + } + } + + } else { + if (ClientEventHandler.focusedFrustum != null && ClientEventHandler.selectedFrustum == null && ClientEventHandler.selectedTrigger != null) { + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.onMainArea") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.confirm.linking")); + } else { + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.onMainArea") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.select.mainArea")); + } + } + + } else if (p_77624_1_.getItemDamage() == 1) { + if (ClientEventHandler.focusedTrigger == null) { + + if (pos1 != null && pos2 != null) { + + if (ClientEventHandler.selectedTrigger != null) { + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.onAir") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.confirm.resizeTriggerArea")); + } else { + if (ClientEventHandler.selectedFrustum != null) { + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.onAir") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.confirm.creationTriggerArea")); + } + } + } + + } else { + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.rightClick.onTriggerArea") + " " + EnumChatFormatting.GREEN + StatCollector.translateToLocal("frustrator.select.triggerArea")); + } + } + + if (ClientEventHandler.selectedFrustum != null && p_77624_1_.getItemDamage() == 0) { + p_77624_3_.add(""); + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.leftClick.onAir") + " " + EnumChatFormatting.AQUA + StatCollector.translateToLocal("frustrator.deselect.mainArea")); + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.leftClick.shiftOnAir") + " " + EnumChatFormatting.AQUA + StatCollector.translateToLocal("frustrator.delete.mainArea")); + + } else if (ClientEventHandler.selectedTrigger != null && p_77624_1_.getItemDamage() == 1) { + p_77624_3_.add(""); + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.leftClick.onAir") + " " + EnumChatFormatting.AQUA + StatCollector.translateToLocal("frustrator.deselect.triggerArea")); + p_77624_3_.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("frustrator.leftClick.shiftOnAir") + " " + EnumChatFormatting.AQUA + StatCollector.translateToLocal("frustrator.delete.triggerArea")); + } } } \ No newline at end of file diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEffectRenderer.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEffectRenderer.java index cc8aff1..10a4710 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEffectRenderer.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEffectRenderer.java @@ -15,8 +15,7 @@ public class MixinEffectRenderer { @Inject(method = "addEffect", at = @At(value = "HEAD"), cancellable = true, remap = true) public void addEffect(EntityFX p_78873_1_, CallbackInfo info) { - if (ClientEventHandler.showAllMainAreas) - return; + if (ClientEventHandler.showAllMainAreas) return; final int x = MathHelper.floor_double(p_78873_1_.posX); final int y = MathHelper.floor_double(p_78873_1_.posY); @@ -25,7 +24,7 @@ public void addEffect(EntityFX p_78873_1_, CallbackInfo info) { for (int i = 0; i < ClientEventHandler.frustumBounds.length; i++) { final FrustumBounds frustum = ClientEventHandler.frustumBounds[i]; if (ClientEventHandler.frustumCheck(x, y, z, frustum)) { - if(ClientEventHandler.localFrustums.isEmpty()){ + if (ClientEventHandler.localFrustums.isEmpty()) { info.cancel(); return; } @@ -33,13 +32,13 @@ public void addEffect(EntityFX p_78873_1_, CallbackInfo info) { boolean success = false; for (int ii = 0; ii < ClientEventHandler.localFrustums.size(); ii++) { final FrustumBounds localFrustum = ClientEventHandler.localFrustums.get(ii); - if (frustum.equalsArea(localFrustum)){ + if (frustum.equalsArea(localFrustum)) { success = true; break; } } - if(!success) { + if (!success) { info.cancel(); return; } diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEntity.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEntity.java index d8baca7..1e11b2d 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEntity.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEntity.java @@ -5,6 +5,7 @@ import net.minecraft.entity.Entity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; + import javax.annotation.Nullable; @Mixin(Entity.class) diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEntityRenderer.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEntityRenderer.java index cfa1bf1..284f24e 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEntityRenderer.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinEntityRenderer.java @@ -21,8 +21,7 @@ public class MixinEntityRenderer { @Inject(method = "getMouseOver", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getEntitiesWithinAABBExcludingEntity(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/AxisAlignedBB;)Ljava/util/List;", shift = At.Shift.BEFORE), cancellable = true, remap = true) public void getMouseOver(float p_78473_1_, CallbackInfo info) { - if (!ClientEventHandler.showAllMainAreas && !ClientEventHandler.showAllTriggerAreas) - return; + if (!ClientEventHandler.showAllMainAreas && !ClientEventHandler.showAllTriggerAreas) return; double d1 = (double) this.mc.playerController.getBlockReachDistance(); @@ -81,11 +80,9 @@ public void getMouseOver(float p_78473_1_, CallbackInfo info) { } } - if (!main) - ClientEventHandler.focusedFrustum = null; + if (!main) ClientEventHandler.focusedFrustum = null; - if (!trigger) - ClientEventHandler.focusedTrigger = null; + if (!trigger) ClientEventHandler.focusedTrigger = null; } } \ No newline at end of file diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinNetHandlerPlayClient.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinNetHandlerPlayClient.java index 627c694..d11de56 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinNetHandlerPlayClient.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinNetHandlerPlayClient.java @@ -19,8 +19,7 @@ public class MixinNetHandlerPlayClient { @Inject(method = "handleEntityMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPositionAndRotation2(DDDFFI)V", shift = At.Shift.BEFORE), cancellable = true, remap = true) public void handleEntityMovement(S14PacketEntity packetIn, CallbackInfo info) { final Entity e = packetIn.func_149065_a(Minecraft.getMinecraft().theWorld); - if (e.ticksExisted % 3 != 0) - return; + if (e.ticksExisted % 3 != 0) return; final int x = MathHelper.floor_double((double) e.serverPosX / 32.0D); final int y = MathHelper.floor_double((double) e.serverPosY / 32.0D); diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinRenderBlocks.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinRenderBlocks.java index eec95d7..bb04942 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinRenderBlocks.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinRenderBlocks.java @@ -14,15 +14,14 @@ public class MixinRenderBlocks { @Inject(method = "renderBlockByRenderType", at = @At(value = "HEAD"), cancellable = true, remap = true) public boolean renderWorldBlock(Block p_147805_1_, int p_147805_2_, int p_147805_3_, int p_147805_4_, CallbackInfoReturnable info) { - if (ClientEventHandler.showAllMainAreas) - return false; + if (ClientEventHandler.showAllMainAreas) return false; for (int a = 0; a < ClientEventHandler.frustumBounds.length; a++) { final FrustumBounds frustum = ClientEventHandler.frustumBounds[a]; if (ClientEventHandler.frustumCheck(p_147805_2_, p_147805_3_, p_147805_4_, frustum)) { - if(ClientEventHandler.localFrustums.isEmpty()){ + if (ClientEventHandler.localFrustums.isEmpty()) { info.setReturnValue(false); info.cancel(); return false; @@ -37,7 +36,7 @@ public boolean renderWorldBlock(Block p_147805_1_, int p_147805_2_, int p_147805 } } - if(!success) { + if (!success) { info.setReturnValue(false); info.cancel(); return false; diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinRenderManager.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinRenderManager.java index e2694ed..facabd3 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinRenderManager.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinRenderManager.java @@ -17,16 +17,14 @@ public class MixinRenderManager { @Inject(method = "func_147939_a", at = @At(value = "HEAD"), cancellable = true, remap = false) public boolean func_147939_a(Entity p_147939_1_, double p_147939_2_, double p_147939_4_, double p_147939_6_, float p_147939_8_, float p_147939_9_, boolean p_147939_10_, CallbackInfoReturnable info) { - if (ClientEventHandler.showAllMainAreas) - return false; + if (ClientEventHandler.showAllMainAreas) return false; final FrustumBounds entityFrustum = ((IMixinEntity) p_147939_1_).getFrustum(); - if (entityFrustum == null) - return false; + if (entityFrustum == null) return false; if (!(p_147939_1_ instanceof EntityPlayer)) { - if(ClientEventHandler.localFrustums.isEmpty()) { + if (ClientEventHandler.localFrustums.isEmpty()) { info.setReturnValue(false); info.cancel(); return false; @@ -41,7 +39,7 @@ public boolean func_147939_a(Entity p_147939_1_, double p_147939_2_, double p_14 } } - if(!success) { + if (!success) { info.setReturnValue(false); info.cancel(); return false; diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinTileEntity.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinTileEntity.java index f9fd269..bfd7696 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinTileEntity.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinTileEntity.java @@ -38,12 +38,11 @@ public void setFrustum(final FrustumBounds frustum) { public void updateEntity(CallbackInfo info) { if (worldObj.isRemote) { - if (ClientEventHandler.showAllMainAreas) - return; + if (ClientEventHandler.showAllMainAreas) return; - if(this.frustumBounds != null) { + if (this.frustumBounds != null) { - if(ClientEventHandler.localFrustums.isEmpty()){ + if (ClientEventHandler.localFrustums.isEmpty()) { info.cancel(); return; } @@ -58,7 +57,7 @@ public void updateEntity(CallbackInfo info) { } } - if(!success) { + if (!success) { info.cancel(); return; } diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinTileEntityRendererDispatcher.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinTileEntityRendererDispatcher.java index 3c25e79..2fe649f 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinTileEntityRendererDispatcher.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinTileEntityRendererDispatcher.java @@ -15,13 +15,12 @@ public class MixinTileEntityRendererDispatcher { @Inject(method = "renderTileEntityAt", at = @At(value = "HEAD"), cancellable = true, remap = true) public void renderTileEntityAt(TileEntity p_147549_1_, double p_147549_2_, double p_147549_4_, double p_147549_6_, float p_147549_8_, CallbackInfo info) { - if (ClientEventHandler.showAllMainAreas) - return; + if (ClientEventHandler.showAllMainAreas) return; final FrustumBounds frustum = ((IMixinEntity) p_147549_1_).getFrustum(); if (frustum != null) { - if(ClientEventHandler.localFrustums.isEmpty()){ + if (ClientEventHandler.localFrustums.isEmpty()) { info.cancel(); return; } @@ -36,7 +35,7 @@ public void renderTileEntityAt(TileEntity p_147549_1_, double p_147549_2_, doubl } } - if(!success) { + if (!success) { info.cancel(); return; } diff --git a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinWorldClient.java b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinWorldClient.java index 5814822..6fc3744 100644 --- a/src/main/java/net/jomcraft/frustrator/mixins/client/MixinWorldClient.java +++ b/src/main/java/net/jomcraft/frustrator/mixins/client/MixinWorldClient.java @@ -18,14 +18,13 @@ public void playSound(double x, double y, double z, String soundName, float volu final int yCoord = MathHelper.floor_double(y); final int zCoord = MathHelper.floor_double(z); - if (ClientEventHandler.showAllMainAreas) - return; + if (ClientEventHandler.showAllMainAreas) return; for (int i = 0; i < ClientEventHandler.frustumBounds.length; i++) { final FrustumBounds frustum = ClientEventHandler.frustumBounds[i]; if (ClientEventHandler.frustumCheck(xCoord, yCoord, zCoord, frustum)) { - if(ClientEventHandler.localFrustums.isEmpty()){ + if (ClientEventHandler.localFrustums.isEmpty()) { info.cancel(); return; } @@ -39,7 +38,7 @@ public void playSound(double x, double y, double z, String soundName, float volu } } - if(!success) { + if (!success) { info.cancel(); return; } diff --git a/src/main/java/net/jomcraft/frustrator/network/C2SAddTriggerPacket.java b/src/main/java/net/jomcraft/frustrator/network/C2SAddTriggerPacket.java index fd33dd3..fa9057b 100644 --- a/src/main/java/net/jomcraft/frustrator/network/C2SAddTriggerPacket.java +++ b/src/main/java/net/jomcraft/frustrator/network/C2SAddTriggerPacket.java @@ -4,11 +4,12 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; +import net.jomcraft.frustrator.ClientEventHandler; import net.jomcraft.frustrator.Frustrator; import net.jomcraft.frustrator.FrustumBounds; import net.jomcraft.frustrator.storage.FileManager; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.Vec3; +import net.minecraft.util.*; import javax.annotation.Nullable; import java.util.ArrayList; @@ -102,25 +103,27 @@ public IMessage onMessage(C2SAddTriggerPacket message, MessageContext ctx) { } if (index != null) { - if(parents == null) - parents = new FrustumBounds[0]; + if (parents == null) parents = new FrustumBounds[0]; ArrayList parentList = new ArrayList(Arrays.asList(parents)); - parentList.add(new FrustumBounds(mainMinX, mainMinY, mainMinZ, mainMaxX, mainMaxY, mainMaxZ, false, null)); - bounds.set((int) index, new FrustumBounds(triggerMinX, triggerMinY, triggerMinZ, triggerMaxX, triggerMaxY, triggerMaxZ, trigger, parentList.toArray(new FrustumBounds[parentList.size()]))); - } - - /*if (!trigger) { - for (int i = 0; i < bounds.size(); i++) { - final FrustumBounds frustum = bounds.get(i); - for(int ii = 0; ii < frustum.parents.length; ii++) { - final FrustumBounds parent = frustum.parents[ii]; - if (frustum.trigger && parent.minX == message.oldPos1.xCoord && parent.minY == message.oldPos1.yCoord && parent.minZ == message.oldPos1.zCoord && parent.maxX == message.oldPos2.xCoord && parent.maxY == message.oldPos2.yCoord && parent.maxZ == message.oldPos2.zCoord) { - frustum.parents[ii] = new FrustumBounds(minX, minY, minZ, maxX, maxY, maxZ, false, null); - } + boolean alreadyContained = false; + final FrustumBounds newFrustum = new FrustumBounds(mainMinX, mainMinY, mainMinZ, mainMaxX, mainMaxY, mainMaxZ, false, null); + for (FrustumBounds parent : parentList) { + if (parent.equalsArea(newFrustum)) { + alreadyContained = true; + break; } } - }*/ + if (!alreadyContained) { + parentList.add(newFrustum); + bounds.set((int) index, new FrustumBounds(triggerMinX, triggerMinY, triggerMinZ, triggerMaxX, triggerMaxY, triggerMaxZ, trigger, parentList.toArray(new FrustumBounds[parentList.size()]))); + player.addChatMessage(new ChatComponentTranslation("frustrator.addTrigger.success", new Object[0]).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.GREEN))); + } else { + player.addChatMessage(new ChatComponentTranslation("frustrator.addTrigger.alreadyExists", new Object[0]).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.YELLOW))); + } + } else { + player.addChatMessage(new ChatComponentTranslation("frustrator.addTrigger.fail", new Object[0]).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.RED))); + } FileManager.getFrustumJSON().save(); diff --git a/src/main/java/net/jomcraft/frustrator/network/C2SDeleteAreaPacket.java b/src/main/java/net/jomcraft/frustrator/network/C2SDeleteAreaPacket.java index e056830..663fab5 100644 --- a/src/main/java/net/jomcraft/frustrator/network/C2SDeleteAreaPacket.java +++ b/src/main/java/net/jomcraft/frustrator/network/C2SDeleteAreaPacket.java @@ -4,10 +4,14 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; +import net.jomcraft.frustrator.ClientEventHandler; import net.jomcraft.frustrator.Frustrator; import net.jomcraft.frustrator.FrustumBounds; import net.jomcraft.frustrator.storage.FileManager; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Vec3; import java.util.ArrayList; @@ -70,6 +74,9 @@ public IMessage onMessage(C2SDeleteAreaPacket message, MessageContext ctx) { if (index != null) { bounds.remove((int) index); + player.addChatMessage(new ChatComponentTranslation("frustrator.delete.success", new Object[]{(trigger ? "trigger" : "main")}).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.GREEN))); + } else { + player.addChatMessage(new ChatComponentTranslation("frustrator.delete.fail", new Object[0]).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.RED))); } if (!trigger) { @@ -83,13 +90,7 @@ public IMessage onMessage(C2SDeleteAreaPacket message, MessageContext ctx) { } } } else { - ArrayList removeParents = new ArrayList(); - for (int ii = 0; ii < frustum.parents.length; ii++) { - final FrustumBounds parent = frustum.parents[ii]; - if (frustum.trigger && parent.minX == message.min.xCoord && parent.minY == message.min.yCoord && parent.minZ == message.min.zCoord && parent.maxX == message.max.xCoord && parent.maxY == message.max.yCoord && parent.maxZ == message.max.zCoord) { - removeParents.add(parent); - } - } + ArrayList removeParents = getFrustumBounds(message, frustum); ArrayList originalParents = new ArrayList(Arrays.asList(frustum.parents)); for (FrustumBounds toRemove : removeParents) { originalParents.remove(toRemove); @@ -111,5 +112,16 @@ public IMessage onMessage(C2SDeleteAreaPacket message, MessageContext ctx) { } return null; } + + private static ArrayList getFrustumBounds(C2SDeleteAreaPacket message, FrustumBounds frustum) { + final ArrayList removeParents = new ArrayList(); + for (int ii = 0; ii < frustum.parents.length; ii++) { + final FrustumBounds parent = frustum.parents[ii]; + if (frustum.trigger && parent.minX == message.min.xCoord && parent.minY == message.min.yCoord && parent.minZ == message.min.zCoord && parent.maxX == message.max.xCoord && parent.maxY == message.max.yCoord && parent.maxZ == message.max.zCoord) { + removeParents.add(parent); + } + } + return removeParents; + } } } \ No newline at end of file diff --git a/src/main/java/net/jomcraft/frustrator/network/C2SNewAreaPacket.java b/src/main/java/net/jomcraft/frustrator/network/C2SNewAreaPacket.java index 3ab25fb..b7f4712 100644 --- a/src/main/java/net/jomcraft/frustrator/network/C2SNewAreaPacket.java +++ b/src/main/java/net/jomcraft/frustrator/network/C2SNewAreaPacket.java @@ -4,11 +4,17 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; +import net.jomcraft.frustrator.ClientEventHandler; import net.jomcraft.frustrator.Frustrator; import net.jomcraft.frustrator.FrustumBounds; import net.jomcraft.frustrator.storage.FileManager; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Vec3; +import net.minecraft.world.World; + import javax.annotation.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -91,14 +97,18 @@ public IMessage onMessage(C2SNewAreaPacket message, MessageContext ctx) { } if (index == null) { - bounds.add(new FrustumBounds(minX, minY, minZ, maxX, maxY, maxZ, message.parent == null ? false : true, new FrustumBounds[] {message.parent})); + bounds.add(new FrustumBounds(minX, minY, minZ, maxX, maxY, maxZ, message.parent == null ? false : true, new FrustumBounds[]{message.parent})); + player.addChatMessage(new ChatComponentTranslation("frustrator.create.success", new Object[]{(message.parent == null ? "main" : "trigger")}).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.GREEN))); + FileManager.getFrustumJSON().save(); Frustrator.network.sendToAll(new S2CSyncAllAreas(bounds.toArray(new FrustumBounds[bounds.size()]), true, Vec3.createVectorHelper(minX, minY, minZ), Vec3.createVectorHelper(maxX, maxY, maxZ))); + } else { + player.addChatMessage(new ChatComponentTranslation("frustrator.create.fail", new Object[]{(message.parent == null ? "main" : "trigger")}).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.YELLOW))); } } else { bounds = new ArrayList(); - bounds.add(new FrustumBounds(minX, minY, minZ, maxX, maxY, maxZ, message.parent == null ? false : true, new FrustumBounds[] {message.parent})); - + bounds.add(new FrustumBounds(minX, minY, minZ, maxX, maxY, maxZ, message.parent == null ? false : true, new FrustumBounds[]{message.parent})); + player.addChatMessage(new ChatComponentTranslation("frustrator.create.success", new Object[]{(message.parent == null ? "main" : "trigger")}).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.GREEN))); dimMap.put(player.worldObj.provider.dimensionId, bounds); FileManager.getFrustumJSON().save(); Frustrator.network.sendToAll(new S2CSyncAllAreas(bounds.toArray(new FrustumBounds[bounds.size()]), true, Vec3.createVectorHelper(minX, minY, minZ), Vec3.createVectorHelper(maxX, maxY, maxZ))); diff --git a/src/main/java/net/jomcraft/frustrator/network/C2SResizeAreaPacket.java b/src/main/java/net/jomcraft/frustrator/network/C2SResizeAreaPacket.java index 160da23..3447f39 100644 --- a/src/main/java/net/jomcraft/frustrator/network/C2SResizeAreaPacket.java +++ b/src/main/java/net/jomcraft/frustrator/network/C2SResizeAreaPacket.java @@ -4,11 +4,16 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; +import net.jomcraft.frustrator.ClientEventHandler; import net.jomcraft.frustrator.Frustrator; import net.jomcraft.frustrator.FrustumBounds; import net.jomcraft.frustrator.storage.FileManager; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Vec3; + import java.util.ArrayList; import java.util.HashMap; @@ -91,12 +96,15 @@ public IMessage onMessage(C2SResizeAreaPacket message, MessageContext ctx) { if (index != null) { bounds.set((int) index, new FrustumBounds(minX, minY, minZ, maxX, maxY, maxZ, trigger, parents)); + player.addChatMessage(new ChatComponentTranslation("frustrator.resize.success", new Object[]{(trigger ? "trigger" : "main")}).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.GREEN))); + } else { + player.addChatMessage(new ChatComponentTranslation("frustrator.resize.fail", new Object[0]).setChatStyle(ClientEventHandler.style.setColor(EnumChatFormatting.RED))); } if (!trigger) { for (int i = 0; i < bounds.size(); i++) { final FrustumBounds frustum = bounds.get(i); - for(int ii = 0; ii < frustum.parents.length; ii++) { + for (int ii = 0; ii < frustum.parents.length; ii++) { final FrustumBounds parent = frustum.parents[ii]; if (frustum.trigger && parent.minX == message.oldPos1.xCoord && parent.minY == message.oldPos1.yCoord && parent.minZ == message.oldPos1.zCoord && parent.maxX == message.oldPos2.xCoord && parent.maxY == message.oldPos2.yCoord && parent.maxZ == message.oldPos2.zCoord) { frustum.parents[ii] = new FrustumBounds(minX, minY, minZ, maxX, maxY, maxZ, false, null); diff --git a/src/main/java/net/jomcraft/frustrator/network/S2CSyncAllAreas.java b/src/main/java/net/jomcraft/frustrator/network/S2CSyncAllAreas.java index 8e9a151..625899f 100644 --- a/src/main/java/net/jomcraft/frustrator/network/S2CSyncAllAreas.java +++ b/src/main/java/net/jomcraft/frustrator/network/S2CSyncAllAreas.java @@ -8,6 +8,7 @@ import net.jomcraft.frustrator.FrustumBounds; import net.minecraft.client.Minecraft; import net.minecraft.util.Vec3; + import java.util.ArrayList; public class S2CSyncAllAreas implements IMessage { @@ -45,7 +46,7 @@ public void fromBytes(ByteBuf buf) { if (trigger) { int parentLength = buf.readInt(); parents = new FrustumBounds[parentLength]; - for(int i = 0; i < parentLength; i++){ + for (int i = 0; i < parentLength; i++) { parents[i] = new FrustumBounds(buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt(), false, null); } } @@ -74,7 +75,7 @@ public void toBytes(ByteBuf buf) { buf.writeBoolean(frustum.trigger); if (frustum.trigger) { buf.writeInt(frustum.parents.length); - for(int i = 0; i < frustum.parents.length; i++) { + for (int i = 0; i < frustum.parents.length; i++) { final FrustumBounds parent = frustum.parents[i]; buf.writeInt(parent.minX); buf.writeInt(parent.minY); diff --git a/src/main/java/net/jomcraft/frustrator/storage/FileManager.java b/src/main/java/net/jomcraft/frustrator/storage/FileManager.java index 3d74b02..59ced78 100644 --- a/src/main/java/net/jomcraft/frustrator/storage/FileManager.java +++ b/src/main/java/net/jomcraft/frustrator/storage/FileManager.java @@ -45,8 +45,8 @@ public static void initialize() { for (FrustumBounds frustum : list) { if (frustum.parent != null) { ArrayList parents; - if(frustum.parents != null){ - parents = new ArrayList(Arrays.asList(frustum.parents)); + if (frustum.parents != null) { + parents = new ArrayList(Arrays.asList(frustum.parents)); } else { parents = new ArrayList(); } @@ -55,7 +55,7 @@ public static void initialize() { frustum.parents = parents.toArray(new FrustumBounds[parents.size()]); } - if(frustum.parents == null){ + if (frustum.parents == null) { frustum.parents = new FrustumBounds[0]; } } @@ -64,10 +64,10 @@ public static void initialize() { } catch (Exception e) { Frustrator.log.log(Level.ERROR, "Exception while reading frustum file: ", e); - // if (e instanceof JsonSyntaxException) { - frustratorFile.renameTo(new File(frustratorFolder, "frustums_malformed.json")); - initJSON(); - // } + // if (e instanceof JsonSyntaxException) { + frustratorFile.renameTo(new File(frustratorFolder, "frustums_malformed.json")); + initJSON(); + // } } } else { diff --git a/src/main/java/net/jomcraft/frustrator/storage/FrustumJSON.java b/src/main/java/net/jomcraft/frustrator/storage/FrustumJSON.java index 38fce7e..fa89b92 100644 --- a/src/main/java/net/jomcraft/frustrator/storage/FrustumJSON.java +++ b/src/main/java/net/jomcraft/frustrator/storage/FrustumJSON.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; + import net.jomcraft.frustrator.Frustrator; import net.jomcraft.frustrator.FrustumBounds; import org.apache.logging.log4j.Level; diff --git a/src/main/resources/assets/frustrator/lang/en_US.lang b/src/main/resources/assets/frustrator/lang/en_US.lang index 4e7764e..03d25e8 100644 --- a/src/main/resources/assets/frustrator/lang/en_US.lang +++ b/src/main/resources/assets/frustrator/lang/en_US.lang @@ -1,2 +1,41 @@ item.frustrator.mainArea.name=Frustrator Main Area Tool -item.frustrator.triggerArea.name=Frustrator Trigger Area Tool \ No newline at end of file +item.frustrator.triggerArea.name=Frustrator Trigger Area Tool + +frustrator.create.success=Successfully created new %s area +frustrator.create.fail=Could not create %s area as it already exists + +frustrator.delete.fail=No area has been deleted +frustrator.delete.success=Successfully deleted formerly selected %s area + +frustrator.addTrigger.success=Successfully linked the clicked main area to the selected trigger area. To unlink please delete the trigger area +frustrator.addTrigger.alreadyExists=This main area and trigger area are already linked +frustrator.addTrigger.fail=No area has been modified + +frustrator.resize.success=Successfully resized selected %s area +frustrator.resize.fail=No area has been resized + +frustrator.leftClick.onAir=Left Click on air: +frustrator.leftClick.shiftOnAir=SHIFT + Left Click on air: + +frustrator.deselect.mainArea=Deselect currently selected main area +frustrator.deselect.triggerArea=Deselect currently selected trigger area + +frustrator.delete.mainArea=Delete selected main area +frustrator.delete.triggerArea=Delete selected trigger area + +frustrator.rightClick.onBlock=Right Click on block: +frustrator.rightClick.shiftOnBlock=SHIFT + Right Click on block: +frustrator.rightClick.onAir=Right Click on air: +frustrator.rightClick.onMainArea=Right Click on main area (red): +frustrator.rightClick.onTriggerArea=Right Click on trigger area (yellow): +frustrator.rightClick.firstMarker=Set first marker position +frustrator.rightClick.secondMarker=Set second marker position + +frustrator.select.triggerArea=Select new trigger area +frustrator.select.mainArea=Select new main area + +frustrator.confirm.creationMainArea=Confirm creation of new main area (red) +frustrator.confirm.creationTriggerArea=Confirm creation of new trigger area (yellow) +frustrator.confirm.resizeMainArea=Confirm new positions of selected main area (confirm resize) +frustrator.confirm.resizeTriggerArea=Confirm new positions of selected trigger area (confirm resize) +frustrator.confirm.linking=Confirm linking selected trigger area (yellow) to clicked main area \ No newline at end of file