From 4575c3a6ca37351658b91741af97e90af4c83ac5 Mon Sep 17 00:00:00 2001 From: Liruxo Date: Fri, 26 Jul 2019 02:45:12 +0200 Subject: [PATCH 1/6] Merge --- src/main/java/com/flansmod/client/ClientRenderHooks.java | 2 +- .../java/com/flansmod/client/handlers/ClientEventHandler.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/flansmod/client/ClientRenderHooks.java b/src/main/java/com/flansmod/client/ClientRenderHooks.java index 1db11a925..fe744f102 100644 --- a/src/main/java/com/flansmod/client/ClientRenderHooks.java +++ b/src/main/java/com/flansmod/client/ClientRenderHooks.java @@ -155,7 +155,7 @@ public void renderHeldItem(RenderSpecificHandEvent event) if(customRenderers[typeType.ordinal()] != null && type.GetModel() != null) { // Cancel the hand render event so that we can do our own. - event.setCanceled(true); + //event.setCanceled(true); float partialTicks = event.getPartialTicks(); EntityRenderer renderer = mc.entityRenderer; diff --git a/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java b/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java index c8619b3b6..56950676d 100644 --- a/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java +++ b/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java @@ -13,6 +13,7 @@ import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.client.event.RenderSpecificHandEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -130,7 +131,7 @@ public void renderItemFrame(RenderItemInFrameEvent event) renderHooks.renderItemFrame(event); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.LOW) public void renderHeldItem(RenderSpecificHandEvent event) { renderHooks.renderHeldItem(event); From d10d12f6df66ab5fb35e7bdb98ea7bc83c65c697 Mon Sep 17 00:00:00 2001 From: Liruxo Date: Fri, 26 Jul 2019 03:25:18 +0200 Subject: [PATCH 2/6] Patch --- .../com/flansmod/common/guns/ItemGun.java | 5 ++--- .../com/flansmod/common/guns/ShotHandler.java | 13 ++++++++----- .../com/flansmod/common/teams/TeamsRound.java | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/flansmod/common/guns/ItemGun.java b/src/main/java/com/flansmod/common/guns/ItemGun.java index 717ab6a68..0041e0621 100644 --- a/src/main/java/com/flansmod/common/guns/ItemGun.java +++ b/src/main/java/com/flansmod/common/guns/ItemGun.java @@ -540,8 +540,6 @@ public void shoot(EnumHand hand, EntityPlayer player, ItemStack gunstack, Player FlansModClient.playerRecoil += recoil; animations.recoil += recoil; - boolean silenced = type.getBarrel(gunstack) != null && type.getBarrel(gunstack).silencer; - playShotSound(world, rayTraceOrigin, silenced); } else { Vector3f rayTraceDirection = new Vector3f(player.getLookVec()); @@ -562,7 +560,8 @@ else if (shootableType instanceof GrenadeType) handler.shooting(false); } - //TODO make server based sound + boolean silenced = type.getBarrel(gunstack) != null && type.getBarrel(gunstack).silencer; + playShotSound(world, rayTraceOrigin, silenced); } int gunSlot = player.inventory.currentItem; if(type.consumeGunUponUse) diff --git a/src/main/java/com/flansmod/common/guns/ShotHandler.java b/src/main/java/com/flansmod/common/guns/ShotHandler.java index bb4d8c1c1..b95fd9433 100644 --- a/src/main/java/com/flansmod/common/guns/ShotHandler.java +++ b/src/main/java/com/flansmod/common/guns/ShotHandler.java @@ -23,6 +23,7 @@ import com.flansmod.common.network.PacketPlaySound; import com.flansmod.common.teams.Team; import com.flansmod.common.teams.TeamsManager; +import com.flansmod.common.teams.TeamsRound; import com.flansmod.common.types.InfoType; import com.flansmod.common.vector.Vector3f; @@ -189,11 +190,13 @@ else if(bulletHit instanceof PlayerBulletHit) { EntityPlayerMP player = optionalPlayer.get(); - if(FlansModClient.teamInfo != null) + if(TeamsManager.getInstance() != null) { - Team shooterTeam = FlansModClient.teamInfo.getTeam(player); - Team victimTeam = FlansModClient.teamInfo.getTeam(playerHit.hitbox.player); - if(shooterTeam == null || shooterTeam != victimTeam) + TeamsRound round = TeamsManager.getInstance().currentRound; + + Team shooterTeam = round.getTeam(player); + Team victimTeam = round.getTeam(playerHit.hitbox.player); + { FlansMod.getPacketHandler().sendTo(new PacketHitMarker(), player); } @@ -264,7 +267,7 @@ else if(bulletHit instanceof BlockHit) for (EntityPlayer player : world.playerEntities) { - //Checks if the player is in a radius of 300 Blocks (300² = 90000) + //Checks if the player is in a radius of 300 Blocks (300 squared = 90000) if (player.getDistanceSq(pos) < 90000) { FlansMod.getPacketHandler().sendTo(new PacketBlockHitEffect(hit, bulletDir, pos, faceing), (EntityPlayerMP) player); diff --git a/src/main/java/com/flansmod/common/teams/TeamsRound.java b/src/main/java/com/flansmod/common/teams/TeamsRound.java index d3f17f5bb..ab7efb333 100644 --- a/src/main/java/com/flansmod/common/teams/TeamsRound.java +++ b/src/main/java/com/flansmod/common/teams/TeamsRound.java @@ -1,5 +1,8 @@ package com.flansmod.common.teams; +import com.flansmod.common.network.PacketTeamInfo.TeamData; + +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; /** @@ -113,6 +116,22 @@ public Team getOtherTeam(Team team) return teams[0]; } + public Team getTeam(EntityPlayer player) + { + String username = player.getName(); + for(Team team : teams) + { + for (String name : team.members) + { + if (username.equals(name)) + { + return team; + } + } + } + return null; + } + public float getWeight() { return popularity * 4F + roundsSincePlayed; From 95df85da590548e4f258708c58a55790b837602a Mon Sep 17 00:00:00 2001 From: Liruxo Date: Fri, 26 Jul 2019 03:32:19 +0200 Subject: [PATCH 3/6] Fix --- src/main/java/com/flansmod/client/ClientRenderHooks.java | 2 +- .../java/com/flansmod/client/handlers/ClientEventHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/flansmod/client/ClientRenderHooks.java b/src/main/java/com/flansmod/client/ClientRenderHooks.java index fe744f102..1db11a925 100644 --- a/src/main/java/com/flansmod/client/ClientRenderHooks.java +++ b/src/main/java/com/flansmod/client/ClientRenderHooks.java @@ -155,7 +155,7 @@ public void renderHeldItem(RenderSpecificHandEvent event) if(customRenderers[typeType.ordinal()] != null && type.GetModel() != null) { // Cancel the hand render event so that we can do our own. - //event.setCanceled(true); + event.setCanceled(true); float partialTicks = event.getPartialTicks(); EntityRenderer renderer = mc.entityRenderer; diff --git a/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java b/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java index 56950676d..d31c720a6 100644 --- a/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java +++ b/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java @@ -131,7 +131,7 @@ public void renderItemFrame(RenderItemInFrameEvent event) renderHooks.renderItemFrame(event); } - @SubscribeEvent(priority = EventPriority.LOW) + @SubscribeEvent public void renderHeldItem(RenderSpecificHandEvent event) { renderHooks.renderHeldItem(event); From b79cea8ce85c90d435706f20f204141db61df85d Mon Sep 17 00:00:00 2001 From: Liruxo Date: Fri, 26 Jul 2019 03:33:21 +0200 Subject: [PATCH 4/6] Remove import --- .../java/com/flansmod/client/handlers/ClientEventHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java b/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java index d31c720a6..c8619b3b6 100644 --- a/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java +++ b/src/main/java/com/flansmod/client/handlers/ClientEventHandler.java @@ -13,7 +13,6 @@ import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.client.event.RenderSpecificHandEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; -import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; From 9eb87ab5450e168d7bd0fc919456ea9fabd98451 Mon Sep 17 00:00:00 2001 From: Liruxo Date: Fri, 26 Jul 2019 03:35:11 +0200 Subject: [PATCH 5/6] Remove another unused import --- src/main/java/com/flansmod/common/teams/TeamsRound.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/flansmod/common/teams/TeamsRound.java b/src/main/java/com/flansmod/common/teams/TeamsRound.java index ab7efb333..3f0ab7524 100644 --- a/src/main/java/com/flansmod/common/teams/TeamsRound.java +++ b/src/main/java/com/flansmod/common/teams/TeamsRound.java @@ -1,7 +1,5 @@ package com.flansmod.common.teams; -import com.flansmod.common.network.PacketTeamInfo.TeamData; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; From cccb90c9cf6b05b6602bcc32cb297857dc0b989e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 30 Jul 2019 14:56:07 +0200 Subject: [PATCH 6/6] Added Optional and fixed Crash --- .../java/com/flansmod/common/guns/ShotHandler.java | 13 ++++++++----- .../java/com/flansmod/common/teams/TeamsRound.java | 8 +++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/flansmod/common/guns/ShotHandler.java b/src/main/java/com/flansmod/common/guns/ShotHandler.java index b95fd9433..19a380a66 100644 --- a/src/main/java/com/flansmod/common/guns/ShotHandler.java +++ b/src/main/java/com/flansmod/common/guns/ShotHandler.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Optional; -import com.flansmod.client.FlansModClient; import com.flansmod.client.debug.EntityDebugDot; import com.flansmod.client.debug.EntityDebugVector; import com.flansmod.common.FlansMod; @@ -194,11 +193,15 @@ else if(bulletHit instanceof PlayerBulletHit) { TeamsRound round = TeamsManager.getInstance().currentRound; - Team shooterTeam = round.getTeam(player); - Team victimTeam = round.getTeam(playerHit.hitbox.player); - + if (round != null) { - FlansMod.getPacketHandler().sendTo(new PacketHitMarker(), player); + Optional shooterTeam = round.getTeam(player); + Optional victimTeam = round.getTeam(playerHit.hitbox.player); + + if (!shooterTeam.isPresent() || !victimTeam.isPresent() || !shooterTeam.get().equals(victimTeam.get())) + { + FlansMod.getPacketHandler().sendTo(new PacketHitMarker(), player); + } } } else // No teams mod, just add marker diff --git a/src/main/java/com/flansmod/common/teams/TeamsRound.java b/src/main/java/com/flansmod/common/teams/TeamsRound.java index 3f0ab7524..2405d4ac1 100644 --- a/src/main/java/com/flansmod/common/teams/TeamsRound.java +++ b/src/main/java/com/flansmod/common/teams/TeamsRound.java @@ -1,5 +1,7 @@ package com.flansmod.common.teams; +import java.util.Optional; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; @@ -114,7 +116,7 @@ public Team getOtherTeam(Team team) return teams[0]; } - public Team getTeam(EntityPlayer player) + public Optional getTeam(EntityPlayer player) { String username = player.getName(); for(Team team : teams) @@ -123,11 +125,11 @@ public Team getTeam(EntityPlayer player) { if (username.equals(name)) { - return team; + return Optional.of(team); } } } - return null; + return Optional.empty(); } public float getWeight()