mirror of
https://github.com/GTNewHorizons/ThaumicHorizons.git
synced 2026-10-26 14:33:47 +00:00
Fix Illumine Lens interaction with other sources of night vision. (#91)
This commit is contained in:
1 parent
e94bc0d510
commit
5c7028c645
2 files changed
+41
-12
No files matched your search
@@ -36,6 +36,7 @@ import com.kentington.thaumichorizons.common.ThaumicHorizons;
|
||||
import com.kentington.thaumichorizons.common.entities.EntityBoatThaumium;
|
||||
import com.kentington.thaumichorizons.common.items.lenses.ILens;
|
||||
import com.kentington.thaumichorizons.common.items.lenses.ItemLensCase;
|
||||
import com.kentington.thaumichorizons.common.items.lenses.ItemLensFire;
|
||||
import com.kentington.thaumichorizons.common.items.lenses.LensManager;
|
||||
import com.kentington.thaumichorizons.common.lib.THKeyHandler;
|
||||
import com.kentington.thaumichorizons.common.lib.networking.PacketHandler;
|
||||
@@ -97,8 +98,7 @@ public class RenderEventHandler {
|
||||
if (LensManager.nightVisionOffTime > 0L
|
||||
&& (goggles == null || !(goggles.getItem() instanceof IRevealer)
|
||||
|| goggles.stackTagCompound == null)
|
||||
&& mc.thePlayer.getActivePotionEffect(Potion.nightVision) != null
|
||||
&& mc.thePlayer.getActivePotionEffect(Potion.nightVision).getIsAmbient()) {
|
||||
&& ItemLensFire.isEffectGrantedByLens(mc.thePlayer.getActivePotionEffect(Potion.nightVision))) {
|
||||
mc.thePlayer.removePotionEffect(Potion.nightVision.id);
|
||||
LensManager.nightVisionOffTime = 0L;
|
||||
}
|
||||
|
||||
+39
-10
@@ -36,14 +36,20 @@ public class ItemLensFire extends Item implements ILens {
|
||||
|
||||
public void handleRender(final Minecraft mc, final float partialTicks) {
|
||||
final boolean inWater = mc.thePlayer.isInsideOfMaterial(Material.water);
|
||||
if (!inWater
|
||||
&& (mc.thePlayer.getActivePotionEffect(Potion.nightVision) == null
|
||||
|| mc.thePlayer.getActivePotionEffect(Potion.nightVision).getDuration() < 242)
|
||||
&& Minecraft.getSystemTime() > LensManager.nightVisionOffTime) {
|
||||
LensManager.nightVisionOffTime = Minecraft.getSystemTime();
|
||||
mc.thePlayer.addPotionEffect(new PotionEffect(Potion.nightVision.id, 255, 0, true));
|
||||
} else if (inWater) {
|
||||
mc.thePlayer.removePotionEffect(Potion.nightVision.id);
|
||||
final PotionEffect effect = mc.thePlayer.getActivePotionEffect(Potion.nightVision);
|
||||
|
||||
if (!inWater) {
|
||||
// Apply effect.
|
||||
if ((effect == null || (isEffectGrantedByLens(effect) && effect.getDuration() < 242))
|
||||
&& Minecraft.getSystemTime() > LensManager.nightVisionOffTime) {
|
||||
LensManager.nightVisionOffTime = Minecraft.getSystemTime();
|
||||
mc.thePlayer.addPotionEffect(new IlluminePotionEffect(Potion.nightVision.id, 255, -1, true));
|
||||
}
|
||||
} else {
|
||||
// Remove effect.
|
||||
if (isEffectGrantedByLens(effect)) {
|
||||
mc.thePlayer.removePotionEffect(Potion.nightVision.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +68,30 @@ public class ItemLensFire extends Item implements ILens {
|
||||
}
|
||||
|
||||
public void handleRemoval(final EntityPlayer p) {
|
||||
p.removePotionEffect(Potion.nightVision.id);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketRemoveNightvision(), (EntityPlayerMP) p);
|
||||
if (isEffectGrantedByLens(p.getActivePotionEffect(Potion.nightVision))) {
|
||||
p.removePotionEffect(Potion.nightVision.id);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketRemoveNightvision(), (EntityPlayerMP) p);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEffectGrantedByLens(PotionEffect effect) {
|
||||
return effect instanceof IlluminePotionEffect illumineEffect && illumineEffect.isGrantedByLens;
|
||||
}
|
||||
|
||||
private static class IlluminePotionEffect extends PotionEffect {
|
||||
|
||||
public boolean isGrantedByLens;
|
||||
|
||||
public IlluminePotionEffect(int potionID, int duration, int amplifier, boolean isAmbient) {
|
||||
super(potionID, duration, amplifier, isAmbient);
|
||||
isGrantedByLens = true;
|
||||
}
|
||||
|
||||
public void combine(PotionEffect effect) {
|
||||
// If this is replaced by another night vision effect, for example from drinking a potion, it should not be
|
||||
// turned off by the lens.
|
||||
super.combine(effect);
|
||||
isGrantedByLens = effect instanceof IlluminePotionEffect;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user