Added a static helper class to determine whether an Entity can be spectated or not - this results in DRY code. While doing so, excluded mc.thePlayer from the spectateable Entities, resolving https://trello.com/c/anFRmsfM/
This commit is contained in:
@@ -3,9 +3,6 @@ package eu.crushedpixel.replaymod.events.handlers;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.item.EntityItemFrame;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@@ -17,7 +14,7 @@ public class CrosshairRenderHandler {
|
||||
public void preCrosshairRender(RenderGameOverlayEvent.Pre event) {
|
||||
//Crosshair should only render if hovered Entity can actually be spectated
|
||||
if(ReplayHandler.isInReplay() && ReplayHandler.isCamera() && event.type == RenderGameOverlayEvent.ElementType.CROSSHAIRS) {
|
||||
boolean cancel = !(mc.pointedEntity instanceof EntityPlayer || mc.pointedEntity instanceof EntityLiving || mc.pointedEntity instanceof EntityItemFrame);
|
||||
boolean cancel = !SpectatingHandler.canSpectate(mc.pointedEntity);
|
||||
event.setCanceled(cancel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ package eu.crushedpixel.replaymod.events.handlers;
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.item.EntityItemFrame;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -31,7 +28,7 @@ public class MouseInputHandler {
|
||||
if(!leftDown) {
|
||||
leftDown = true;
|
||||
if(mc.pointedEntity != null && ReplayHandler.isCamera() && mc.currentScreen == null) {
|
||||
if(mc.pointedEntity instanceof EntityPlayer || mc.pointedEntity instanceof EntityLiving || mc.pointedEntity instanceof EntityItemFrame)
|
||||
if(SpectatingHandler.canSpectate(mc.pointedEntity))
|
||||
ReplayHandler.spectateEntity(mc.pointedEntity);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +40,7 @@ public class MouseInputHandler {
|
||||
if(!rightDown) {
|
||||
rightDown = true;
|
||||
if(mc.pointedEntity != null && ReplayHandler.isCamera() && mc.currentScreen == null) {
|
||||
if(mc.pointedEntity instanceof EntityPlayer || mc.pointedEntity instanceof EntityLiving || mc.pointedEntity instanceof EntityItemFrame)
|
||||
if(SpectatingHandler.canSpectate(mc.pointedEntity))
|
||||
ReplayHandler.spectateEntity(mc.pointedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package eu.crushedpixel.replaymod.events.handlers;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.item.EntityItemFrame;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class SpectatingHandler {
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public static boolean canSpectate(Entity e) {
|
||||
return ((e instanceof EntityPlayer || e instanceof EntityLiving || e instanceof EntityItemFrame) && e != mc.thePlayer);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class PathPreviewRenderer {
|
||||
|
||||
@SubscribeEvent
|
||||
public void renderCameraPath(RenderWorldLastEvent event) {
|
||||
if(!ReplayHandler.isInReplay() || ReplayHandler.isInPath() || !ReplayMod.replaySettings.showPathPreview()) return;
|
||||
if(!ReplayHandler.isInReplay() || ReplayHandler.isInPath() || !ReplayMod.replaySettings.showPathPreview() || mc.gameSettings.hideGUI) return;
|
||||
|
||||
Entity entity = ReplayHandler.getCameraEntity();
|
||||
if(entity == null) return;
|
||||
|
||||
Reference in New Issue
Block a user