Compare commits

..
1 Commits
Author SHA1 Message Date
Harald Korneliussen 6523b26038 Fixes mooshroom infusion crash (#136) 2026-10-25 10:49:27 +01:00
22 changed files with 689 additions and 630 deletions

No files matched your search

@@ -283,7 +283,7 @@ public class ClientProxy extends CommonProxy {
return new GuiVat(player, (TileVat) world.getTileEntity(x, y, z));
}
case 8 -> {
return new GuiCase(player.inventory, world);
return new GuiCase(player.inventory, world, x, y, z);
}
case 9 -> {
return new GuiFingers(player.inventory);
@@ -21,8 +21,9 @@ public class GuiCase extends GuiContainer {
private final int blockSlot;
public GuiCase(final InventoryPlayer par1InventoryPlayer, final World world) {
super(new ContainerCase(par1InventoryPlayer, world));
public GuiCase(final InventoryPlayer par1InventoryPlayer, final World world, final int x, final int y,
final int z) {
super(new ContainerCase(par1InventoryPlayer, world, x, y, z));
this.blockSlot = par1InventoryPlayer.currentItem;
this.xSize = 176;
this.ySize = 233;
@@ -4,9 +4,8 @@
package com.kentington.thaumichorizons.client.lib;
import static com.kentington.thaumichorizons.common.items.lenses.LensPotionEffects.isNightVisionGrantedByLens;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;
import net.minecraft.block.Block;
@@ -37,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;
@@ -53,23 +53,11 @@ import thaumcraft.common.Thaumcraft;
public class RenderEventHandler {
private static class FocusRenderInfo {
int slot;
ItemStack item;
float scale;
boolean hover;
FocusRenderInfo(final int slot, final ItemStack item) {
this.slot = slot;
this.item = item;
this.scale = 1.0f;
this.hover = false;
}
}
public static float radialHudScale;
TreeMap<String, FocusRenderInfo> foci;
static float radialHudScale;
TreeMap<String, Integer> foci;
HashMap<String, ItemStack> fociItem;
HashMap<String, Boolean> fociHover;
HashMap<String, Float> fociScale;
long lastTime;
boolean lastState;
float breakProgress;
@@ -84,6 +72,9 @@ public class RenderEventHandler {
public RenderEventHandler() {
this.foci = new TreeMap<>();
this.fociItem = new HashMap<>();
this.fociHover = new HashMap<>();
this.fociScale = new HashMap<>();
this.lastTime = 0L;
this.lastState = false;
this.breakProgress = 0.0f;
@@ -101,156 +92,159 @@ public class RenderEventHandler {
public void renderOverlay(final RenderGameOverlayEvent event) {
final Minecraft mc = Minecraft.getMinecraft();
final long time = System.nanoTime() / 1000000L;
if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return;
final ItemStack goggles = mc.thePlayer.inventory.armorItemInSlot(3);
final boolean hasRevealerGoggles = goggles != null && goggles.getItem() instanceof IRevealer;
if (LensManager.nightVisionOffTime > 0L && (!hasRevealerGoggles || goggles.stackTagCompound == null)
&& isNightVisionGrantedByLens(mc.thePlayer.getActivePotionEffect(Potion.nightVision))) {
mc.thePlayer.removePotionEffect(Potion.nightVision.id);
LensManager.nightVisionOffTime = 0L;
}
if (!hasRevealerGoggles) return;
this.handleFociRadial(mc, time, event, goggles);
final ILens theLens = LensManager.getLensFromItem(goggles);
if (theLens != null) {
theLens.handleRender(mc, event.partialTicks);
if (event.type == RenderGameOverlayEvent.ElementType.TEXT) {
this.handleFociRadial(mc, time, event);
final ItemStack goggles = mc.thePlayer.inventory.armorItemInSlot(3);
if (LensManager.nightVisionOffTime > 0L
&& (goggles == null || !(goggles.getItem() instanceof IRevealer)
|| goggles.stackTagCompound == null)
&& ItemLensFire.isEffectGrantedByLens(mc.thePlayer.getActivePotionEffect(Potion.nightVision))) {
mc.thePlayer.removePotionEffect(Potion.nightVision.id);
LensManager.nightVisionOffTime = 0L;
}
if (goggles != null && goggles.getItem() instanceof IRevealer
&& goggles.stackTagCompound != null
&& goggles.stackTagCompound.getString("Lens") != null
&& !goggles.stackTagCompound.getString("Lens").equals("")) {
final ILens theLens = (ILens) LensManager.getLens(goggles.stackTagCompound.getString("Lens"));
if (theLens != null) {
theLens.handleRender(mc, event.partialTicks);
}
}
}
}
@SideOnly(Side.CLIENT)
public void handleFociRadial(final Minecraft mc, final long time, final RenderGameOverlayEvent event,
final ItemStack goggles) {
if (!THKeyHandler.radialActive && RenderEventHandler.radialHudScale <= 0.0f) return;
if (THKeyHandler.radialActive) {
if (mc.currentScreen != null) {
THKeyHandler.radialActive = false;
THKeyHandler.radialLock = true;
THKeyHandler.radialSelectionMade = true;
mc.setIngameFocus();
mc.setIngameNotInFocus();
return;
}
if (RenderEventHandler.radialHudScale == 0.0f && !THKeyHandler.radialLock) {
this.foci.clear();
THKeyHandler.radialLock = true;
int pouchcount = 0;
ItemStack item;
final String currentLensName = goggles.stackTagCompound != null
? goggles.stackTagCompound.getString("Lens")
: null;
final IInventory baubles = BaublesApi.getBaubles(mc.thePlayer);
for (int a = 0; a < baubles.getSizeInventory(); ++a) {
if (baubles.getStackInSlot(a) != null
&& baubles.getStackInSlot(a).getItem() instanceof ItemLensCase lensCase) {
++pouchcount;
item = baubles.getStackInSlot(a);
final ItemStack[] inv = lensCase.getInventory(item);
for (int q = 0; q < inv.length; ++q) {
item = inv[q];
if (item != null && item.getItem() instanceof ILens lens) {
final String lensName = lens.lensName();
if (lensName.equals(currentLensName) || this.foci.containsKey(lensName)) continue;
this.foci.put(lensName, new FocusRenderInfo(q + pouchcount * 1000, item.copy()));
public void handleFociRadial(final Minecraft mc, final long time, final RenderGameOverlayEvent event) {
if (THKeyHandler.radialActive || RenderEventHandler.radialHudScale > 0.0f) {
final long timeDiff = System.currentTimeMillis() - THKeyHandler.lastPressV;
if (THKeyHandler.radialActive) {
if (mc.currentScreen != null) {
THKeyHandler.radialActive = false;
THKeyHandler.radialLock = true;
mc.setIngameFocus();
mc.setIngameNotInFocus();
return;
}
if (RenderEventHandler.radialHudScale == 0.0f) {
this.foci.clear();
this.fociItem.clear();
this.fociHover.clear();
this.fociScale.clear();
int pouchcount = 0;
ItemStack item = null;
final IInventory baubles = BaublesApi.getBaubles(mc.thePlayer);
for (int a = 0; a < 4; ++a) {
if (baubles.getStackInSlot(a) != null
&& baubles.getStackInSlot(a).getItem() instanceof ItemLensCase) {
++pouchcount;
item = baubles.getStackInSlot(a);
final ItemStack[] inv = ((ItemLensCase) item.getItem()).getInventory(item);
for (int q = 0; q < inv.length; ++q) {
item = inv[q];
if (item != null && item.getItem() instanceof ILens) {
this.foci.put(((ILens) item.getItem()).lensName(), q + pouchcount * 1000);
this.fociItem.put(((ILens) item.getItem()).lensName(), item.copy());
this.fociScale.put(((ILens) item.getItem()).lensName(), 1.0f);
this.fociHover.put(((ILens) item.getItem()).lensName(), false);
}
}
}
}
}
for (int a = 0; a < 36; ++a) {
item = mc.thePlayer.inventory.mainInventory[a];
if (item != null && item.getItem() instanceof ILens lens) {
final String lensName = lens.lensName();
if (!lensName.equals(currentLensName) && !this.foci.containsKey(lensName)) {
this.foci.put(lensName, new FocusRenderInfo(a, item.copy()));
for (int a = 0; a < 36; ++a) {
item = mc.thePlayer.inventory.mainInventory[a];
if (item != null && item.getItem() instanceof ILens) {
this.foci.put(((ILens) item.getItem()).lensName(), a);
this.fociItem.put(((ILens) item.getItem()).lensName(), item.copy());
this.fociScale.put(((ILens) item.getItem()).lensName(), 1.0f);
this.fociHover.put(((ILens) item.getItem()).lensName(), false);
}
}
if (item != null && item.getItem() instanceof ItemLensCase lensCase) {
++pouchcount;
final ItemStack[] inv = lensCase.getInventory(item);
for (int q = 0; q < inv.length; ++q) {
item = inv[q];
if (item != null && item.getItem() instanceof ILens lens) {
final String lensName = lens.lensName();
if (lensName.equals(currentLensName) || this.foci.containsKey(lensName)) continue;
this.foci.put(lensName, new FocusRenderInfo(q + pouchcount * 1000, item.copy()));
if (item != null && item.getItem() instanceof ItemLensCase) {
++pouchcount;
final ItemStack[] inv = ((ItemLensCase) item.getItem()).getInventory(item);
for (int q = 0; q < inv.length; ++q) {
item = inv[q];
if (item != null && item.getItem() instanceof ILens) {
this.foci.put(((ILens) item.getItem()).lensName(), q + pouchcount * 1000);
this.fociItem.put(((ILens) item.getItem()).lensName(), item.copy());
this.fociScale.put(((ILens) item.getItem()).lensName(), 1.0f);
this.fociHover.put(((ILens) item.getItem()).lensName(), false);
}
}
}
}
if (this.foci.size() > 0 && mc.inGameHasFocus) {
mc.inGameHasFocus = false;
mc.mouseHelper.ungrabMouseCursor();
}
}
if (!this.foci.isEmpty() && mc.inGameHasFocus) {
mc.inGameHasFocus = false;
mc.mouseHelper.ungrabMouseCursor();
} else if (mc.currentScreen == null && this.lastState) {
if (Display.isActive() && !mc.inGameHasFocus) {
mc.inGameHasFocus = true;
mc.mouseHelper.grabMouseCursor();
}
this.lastState = false;
}
} else if (mc.currentScreen == null && this.lastState) {
if (Display.isActive() && !mc.inGameHasFocus) {
mc.inGameHasFocus = true;
mc.mouseHelper.grabMouseCursor();
}
this.lastState = false;
}
this.renderFocusRadialHUD(
event.resolution.getScaledWidth_double(),
event.resolution.getScaledHeight_double(),
event.partialTicks,
goggles);
if (time > this.lastTime) {
for (final var entry : this.foci.entrySet()) {
FocusRenderInfo renderInfo = entry.getValue();
if (renderInfo.hover) {
if (!THKeyHandler.radialActive && !THKeyHandler.radialLock) {
PacketHandler.INSTANCE.sendToServer(new PacketLensChangeToServer(entry.getKey()));
THKeyHandler.radialLock = true;
if (Display.isActive() && !mc.inGameHasFocus) {
mc.inGameHasFocus = true;
mc.mouseHelper.grabMouseCursor();
this.renderFocusRadialHUD(
event.resolution.getScaledWidth_double(),
event.resolution.getScaledHeight_double(),
time,
event.partialTicks);
if (time > this.lastTime) {
for (final String key : this.fociHover.keySet()) {
if (this.fociHover.get(key)) {
if (!THKeyHandler.radialActive && !THKeyHandler.radialLock) {
PacketHandler.INSTANCE.sendToServer(new PacketLensChangeToServer(mc.thePlayer, key));
THKeyHandler.radialLock = true;
}
if (this.fociScale.get(key) >= 1.3f) {
continue;
}
this.fociScale.put(key, this.fociScale.get(key) + 0.025f);
} else {
if (this.fociScale.get(key) <= 1.0f) {
continue;
}
this.fociScale.put(key, this.fociScale.get(key) - 0.025f);
}
if (renderInfo.scale >= 1.3f) {
continue;
}
renderInfo.scale += 0.025f;
} else {
if (renderInfo.scale <= 1.0f) {
continue;
}
renderInfo.scale -= 0.025f;
}
if (!THKeyHandler.radialActive) {
RenderEventHandler.radialHudScale -= 0.05f;
} else if (THKeyHandler.radialActive && RenderEventHandler.radialHudScale < 1.0f) {
RenderEventHandler.radialHudScale += 0.05f;
}
if (RenderEventHandler.radialHudScale > 1.0f) {
RenderEventHandler.radialHudScale = 1.0f;
}
if (RenderEventHandler.radialHudScale < 0.0f) {
RenderEventHandler.radialHudScale = 0.0f;
THKeyHandler.radialLock = false;
}
this.lastTime = time + 5L;
this.lastState = THKeyHandler.radialActive;
}
if (!THKeyHandler.radialActive) {
RenderEventHandler.radialHudScale -= 0.05f;
} else if (RenderEventHandler.radialHudScale < 1.0f) {
RenderEventHandler.radialHudScale += 0.05f;
}
if (RenderEventHandler.radialHudScale > 1.0f) {
RenderEventHandler.radialHudScale = 1.0f;
THKeyHandler.radialLock = false;
}
if (RenderEventHandler.radialHudScale < 0.0f) {
RenderEventHandler.radialHudScale = 0.0f;
THKeyHandler.radialLock = false;
}
this.lastTime = time + 5L;
this.lastState = THKeyHandler.radialActive;
}
}
@SideOnly(Side.CLIENT)
private void renderFocusRadialHUD(final double sw, final double sh, final float partialTicks,
final ItemStack goggles) {
private void renderFocusRadialHUD(final double sw, final double sh, final long time, final float partialTicks) {
final RenderItem ri = new RenderItem();
final Minecraft mc = Minecraft.getMinecraft();
final ILens lens = LensManager.getLensFromItem(goggles);
final int i = (int) (Mouse.getX() * sw / mc.displayWidth);
final int j = (int) (sh - Mouse.getY() * sh / mc.displayHeight - 1.0);
if (mc.thePlayer.inventory.armorItemInSlot(3) == null
|| !(mc.thePlayer.inventory.armorItemInSlot(3).getItem() instanceof IRevealer)) {
return;
}
final ItemStack goggles = mc.thePlayer.inventory.armorItemInSlot(3);
ILens lens = null;
if (goggles.stackTagCompound != null) {
lens = (ILens) LensManager.getLens(goggles.stackTagCompound.getString("Lens"));
}
final int i = (int) (Mouse.getEventX() * sw / mc.displayWidth);
final int j = (int) (sh - Mouse.getEventY() * sh / mc.displayHeight - 1.0);
final int k = Mouse.getEventButton();
if (this.foci.isEmpty()) return;
if (this.fociItem.size() == 0) {
return;
}
GL11.glPushMatrix();
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_PROJECTION);
@@ -264,7 +258,7 @@ public class RenderEventHandler {
GL11.glPushMatrix();
GL11.glTranslated(sw / 2.0, sh / 2.0, 0.0);
ItemStack tt = null;
final float width = 16.0f + this.foci.size() * 2.5f;
final float width = 16.0f + this.fociItem.size() * 2.5f;
UtilsFX.bindTexture("textures/misc/radial.png");
GL11.glPushMatrix();
GL11.glRotatef(partialTicks + mc.thePlayer.ticksExisted % 720 / 2.0f, 0.0f, 0.0f, 1.0f);
@@ -320,45 +314,37 @@ public class RenderEventHandler {
RenderEventHandler.radialHudScale,
RenderEventHandler.radialHudScale);
float currentRot = -90.0f * RenderEventHandler.radialHudScale;
final float pieSlice = 360.0f / this.foci.size();
final float pieSlice = 360.0f / this.fociItem.size();
String key = this.foci.firstKey();
for (int a = 0; a < this.foci.size(); ++a) {
final FocusRenderInfo renderInfo = this.foci.get(key);
for (int a = 0; a < this.fociItem.size(); ++a) {
final double xx = MathHelper.cos(currentRot / 180.0f * (float) Math.PI) * width;
final double yy = MathHelper.sin(currentRot / 180.0f * (float) Math.PI) * width;
currentRot += pieSlice;
GL11.glPushMatrix();
GL11.glTranslated(xx, yy, 100.0);
GL11.glScalef(renderInfo.scale, renderInfo.scale, renderInfo.scale);
GL11.glScalef(this.fociScale.get(key), this.fociScale.get(key), this.fociScale.get(key));
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
RenderHelper.enableGUIStandardItemLighting();
final ItemStack item2 = renderInfo.item.copy();
final ItemStack item2 = this.fociItem.get(key).copy();
item2.stackTagCompound = null;
ri.renderItemIntoGUI(mc.fontRenderer, mc.renderEngine, item2, -8, -8);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
if (!THKeyHandler.radialLock && THKeyHandler.radialActive && RenderEventHandler.radialHudScale >= 1.0f) {
final double scaledXX = xx * RenderEventHandler.radialHudScale;
final double scaledYY = yy * RenderEventHandler.radialHudScale;
final int mx2 = (int) (i - sw / 2.0 - scaledXX);
final int my2 = (int) (j - sh / 2.0 - scaledYY);
if (!THKeyHandler.radialLock && THKeyHandler.radialActive) {
final int mx2 = (int) (i - sw / 2.0 - xx);
final int my2 = (int) (j - sh / 2.0 - yy);
if (mx2 >= -10 && mx2 <= 10 && my2 >= -10 && my2 <= 10) {
renderInfo.hover = true;
tt = renderInfo.item;
this.fociHover.put(key, true);
tt = this.fociItem.get(key);
if (k == 0) {
THKeyHandler.radialActive = false;
THKeyHandler.radialLock = true;
THKeyHandler.radialSelectionMade = true;
PacketHandler.INSTANCE.sendToServer(new PacketLensChangeToServer(key));
if (Display.isActive() && !mc.inGameHasFocus) {
mc.inGameHasFocus = true;
mc.mouseHelper.grabMouseCursor();
}
PacketHandler.INSTANCE.sendToServer(new PacketLensChangeToServer(mc.thePlayer, key));
break;
}
} else {
renderInfo.hover = false;
this.fociHover.put(key, false);
}
}
key = this.foci.higherKey(key);
@@ -386,19 +372,28 @@ public class RenderEventHandler {
public void blockHighlight(final DrawBlockHighlightEvent event) {
final Minecraft mc = Minecraft.getMinecraft();
final ItemStack goggles = mc.thePlayer.inventory.armorItemInSlot(3);
final ILens theLens = LensManager.getLensFromItem(goggles);
if (theLens != null && theLens == ThaumicHorizons.itemLensEarth) {
if (this.cacheX != event.target.blockX || this.cacheY != event.target.blockY
|| this.cacheZ != event.target.blockZ
|| this.tempDir != ForgeDirection.getOrientation(event.target.sideHit)) {
this.resetBlocks(mc.thePlayer);
}
if (event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ)
.getMaterial() != Material.air) {
this.cacheX = event.target.blockX;
this.cacheY = event.target.blockY;
this.cacheZ = event.target.blockZ;
this.tempDir = ForgeDirection.getOrientation(event.target.sideHit);
if (goggles != null && goggles.getItem() instanceof IRevealer && goggles.stackTagCompound != null) {
if (goggles.stackTagCompound.getString("Lens") != null
&& !goggles.stackTagCompound.getString("Lens").equals("")) {
final ILens theLens = (ILens) LensManager.getLens(goggles.stackTagCompound.getString("Lens"));
if (theLens == ThaumicHorizons.itemLensEarth) {
if (this.cacheX != event.target.blockX || this.cacheY != event.target.blockY
|| this.cacheZ != event.target.blockZ
|| this.tempDir != ForgeDirection.getOrientation(event.target.sideHit)) {
this.resetBlocks(mc.thePlayer);
}
if (event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ)
.getMaterial() != Material.air) {
this.cacheX = event.target.blockX;
this.cacheY = event.target.blockY;
this.cacheZ = event.target.blockZ;
this.tempDir = ForgeDirection.getOrientation(event.target.sideHit);
} else {
this.resetBlocks(mc.thePlayer);
}
} else {
this.resetBlocks(mc.thePlayer);
}
} else {
this.resetBlocks(mc.thePlayer);
}
@@ -549,12 +544,18 @@ public class RenderEventHandler {
@SubscribeEvent
public void renderTick(final TickEvent.RenderTickEvent event) {
final Minecraft mc = Minecraft.getMinecraft();
if (mc.thePlayer == null) return;
if (mc.thePlayer == null) {
return;
}
final ItemStack goggles = mc.thePlayer.inventory.armorItemInSlot(3);
final ILens theLens = LensManager.getLensFromItem(goggles);
if (theLens != null && theLens == ThaumicHorizons.itemLensEarth) {
this.setBlocksEvanescent(mc.thePlayer);
if (goggles != null && goggles.getItem() instanceof IRevealer
&& goggles.stackTagCompound != null
&& goggles.stackTagCompound.getString("Lens") != null
&& !goggles.stackTagCompound.getString("Lens").equals("")) {
final ILens theLens = (ILens) LensManager.getLens(goggles.stackTagCompound.getString("Lens"));
if (theLens == ThaumicHorizons.itemLensEarth) {
this.setBlocksEvanescent(mc.thePlayer);
}
}
}
@@ -586,11 +587,15 @@ public class RenderEventHandler {
public void clearWater(final RenderBlockOverlayEvent event) {
final Minecraft mc = Minecraft.getMinecraft();
final ItemStack goggles = mc.thePlayer.inventory.armorItemInSlot(3);
final ILens theLens = LensManager.getLensFromItem(goggles);
if (theLens != null && theLens == ThaumicHorizons.itemLensWater) {
event.setCanceled(true);
if (goggles != null && goggles.getItem() instanceof IRevealer
&& goggles.stackTagCompound != null
&& goggles.stackTagCompound.getString("Lens") != null
&& !goggles.stackTagCompound.getString("Lens").equals("")) {
final ILens theLens = (ILens) LensManager.getLens(goggles.stackTagCompound.getString("Lens"));
if (theLens == ThaumicHorizons.itemLensWater) {
event.setCanceled(true);
}
}
if (event.overlayType == RenderBlockOverlayEvent.OverlayType.FIRE
&& mc.thePlayer.ridingEntity instanceof EntityBoatThaumium) {
event.setCanceled(true);
@@ -92,7 +92,7 @@ public class CommonProxy implements IGuiHandler {
return new ContainerVat(player, (TileVat) world.getTileEntity(x, y, z));
}
case 8 -> {
return new ContainerCase(player.inventory, world);
return new ContainerCase(player.inventory, world, x, y, z);
}
case 9 -> {
return new ContainerFingers(player.inventory);
@@ -3243,7 +3243,7 @@ public class ThaumicHorizons {
critterRecipes.add(
new CreatureInfusionRecipe(
"cowInfusion",
EntityList.getEntityID(new EntityMooshroom(null)),
-EntityList.getEntityID(new EntityMooshroom(null)),
2,
(new AspectList()).add(Aspect.PLANT, 8).add(Aspect.BEAST, 4),
EntityCow.class,
@@ -20,22 +20,31 @@ import thaumcraft.common.container.SlotLimitedByClass;
public class ContainerCase extends Container {
private final World worldObj;
private final int blockSlot;
private int posX;
private int posY;
private int posZ;
private int blockSlot;
public IInventory input;
ItemStack pouch;
EntityPlayer player;
public ContainerCase(final InventoryPlayer inventory, final World par2World) {
public ContainerCase(final InventoryPlayer iinventory, final World par2World, final int par3, final int par4,
final int par5) {
this.input = new InventoryCase(this);
this.pouch = null;
this.player = null;
this.worldObj = par2World;
this.player = inventory.player;
this.pouch = inventory.getCurrentItem();
this.blockSlot = inventory.currentItem + 45;
this.posX = par3;
this.posY = par4;
this.posZ = par5;
this.player = iinventory.player;
this.pouch = iinventory.getCurrentItem();
this.blockSlot = iinventory.currentItem + 45;
for (int a = 0; a < 18; ++a) {
this.addSlotToContainer(
new SlotLimitedByClass(ILens.class, this.input, a, 37 + a % 6 * 18, 51 + a / 6 * 18));
}
this.bindPlayerInventory(inventory);
this.bindPlayerInventory(iinventory);
if (!par2World.isRemote && this.pouch != null
&& this.pouch.getItem() instanceof ItemLensCase lensCase
&& this.input instanceof InventoryCase inv) {
@@ -60,7 +69,7 @@ public class ContainerCase extends Container {
return null;
}
ItemStack stack = null;
final Slot slotObject = this.inventorySlots.get(slot);
final Slot slotObject = (Slot) this.inventorySlots.get(slot);
if (slotObject != null && slotObject.getHasStack()) {
final ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
@@ -78,7 +87,6 @@ public class ContainerCase extends Container {
} else {
slotObject.onSlotChanged();
}
this.detectAndSendChanges();
}
return stack;
}
@@ -45,18 +45,13 @@ public class ItemLensAir extends Item implements ILens {
return "LensAir";
}
@Override
public int getItemStackLimit(ItemStack stack) {
return 1;
}
@SideOnly(Side.CLIENT)
public void handleRender(final Minecraft mc, final float partialTicks) {
if (mc.gameSettings.thirdPersonView > 0) {
return;
}
final EntityPlayer player = mc.thePlayer;
final List<Entity> critters = player.worldObj.getEntitiesWithinAABBExcludingEntity(
final List<Entity> critters = (List<Entity>) player.worldObj.getEntitiesWithinAABBExcludingEntity(
mc.thePlayer,
AxisAlignedBB.getBoundingBox(
player.posX - 24.0,
@@ -126,8 +121,7 @@ public class ItemLensAir extends Item implements ILens {
numRipples = 4;
}
for (int i = 0; i < numRipples; ++i) {
final double ripSize = size * (((double) (i * 16) / (numRipples + 1) + sizeOffset) % 16.0f)
/ 12.0;
final double ripSize = size * ((i * 16 / (numRipples + 1) + sizeOffset) % 16.0f) / 12.0;
t.startDrawingQuads();
t.addVertexWithUV(xCenter - ripSize, yCenter + ripSize, 1.0, 0.0, 1.0);
t.addVertexWithUV(xCenter + ripSize, yCenter + ripSize, 1.0, 1.0, 1.0);
@@ -28,11 +28,6 @@ public class ItemLensEarth extends Item implements ILens {
return "LensEarth";
}
@Override
public int getItemStackLimit(ItemStack stack) {
return 1;
}
public void handleRender(final Minecraft mc, final float partialTicks) {}
public String getUnlocalizedName(final ItemStack par1ItemStack) {
@@ -4,8 +4,6 @@
package com.kentington.thaumichorizons.common.items.lenses;
import static com.kentington.thaumichorizons.common.items.lenses.LensPotionEffects.isNightVisionGrantedByLens;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -19,7 +17,7 @@ import net.minecraft.util.IIcon;
import com.kentington.thaumichorizons.common.ThaumicHorizons;
import com.kentington.thaumichorizons.common.lib.networking.PacketHandler;
import com.kentington.thaumichorizons.common.lib.networking.PacketRemoveLensNightvision;
import com.kentington.thaumichorizons.common.lib.networking.PacketRemoveNightvision;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -36,26 +34,20 @@ public class ItemLensFire extends Item implements ILens {
return "LensFire";
}
@Override
public int getItemStackLimit(ItemStack stack) {
return 1;
}
public void handleRender(final Minecraft mc, final float partialTicks) {
final boolean inWater = mc.thePlayer.isInsideOfMaterial(Material.water);
final PotionEffect effect = mc.thePlayer.getActivePotionEffect(Potion.nightVision);
if (!inWater) {
// Apply effect.
if ((effect == null || (isNightVisionGrantedByLens(effect) && effect.getDuration() < 242))
if ((effect == null || (isEffectGrantedByLens(effect) && effect.getDuration() < 242))
&& Minecraft.getSystemTime() > LensManager.nightVisionOffTime) {
LensManager.nightVisionOffTime = Minecraft.getSystemTime();
mc.thePlayer
.addPotionEffect(new LensPotionEffects.LensNightVision(Potion.nightVision.id, 255, -1, true));
mc.thePlayer.addPotionEffect(new IlluminePotionEffect(Potion.nightVision.id, 255, -1, true));
}
} else {
// Remove effect.
if (isNightVisionGrantedByLens(effect)) {
if (isEffectGrantedByLens(effect)) {
mc.thePlayer.removePotionEffect(Potion.nightVision.id);
}
}
@@ -76,6 +68,30 @@ public class ItemLensFire extends Item implements ILens {
}
public void handleRemoval(final EntityPlayer p) {
PacketHandler.INSTANCE.sendTo(new PacketRemoveLensNightvision(), (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;
}
}
}
@@ -7,8 +7,6 @@ package com.kentington.thaumichorizons.common.items.lenses;
import java.awt.Color;
import java.text.DecimalFormat;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
@@ -65,25 +63,24 @@ public class ItemLensOrderEntropy extends Item implements ILens {
return "LensOrderEntropy";
}
@Override
public int getItemStackLimit(ItemStack stack) {
return 1;
}
@SideOnly(Side.CLIENT)
public void handleRender(final Minecraft mc, final float partialTicks) {
if (Minecraft.getMinecraft().thePlayer.worldObj.isRemote) {
double x = 0.0;
double y = 0.0;
double z = 0.0;
final EntityPlayer p = Minecraft.getMinecraft().thePlayer;
this.isNew = false;
String text = "?";
final ScanResult scan = this.doScan(new ItemStack(ConfigItems.itemThaumometer), p.worldObj, p);
final ScanResult scan = this.doScan(new ItemStack(ConfigItems.itemThaumometer), p.worldObj, p, this.count);
if (scan != null) {
AspectList aspects = null;
if (!this.isNew) {
aspects = ScanManager.getScanAspects(scan, p.worldObj);
}
ItemStack stack = null;
if (scan.id > 0) {
ItemStack stack = new ItemStack(Item.getItemById(scan.id), 1, scan.meta);
stack = new ItemStack(Item.getItemById(scan.id), 1, scan.meta);
if (stack.getItem() != null) {
try {
text = stack.getDisplayName();
@@ -96,9 +93,15 @@ public class ItemLensOrderEntropy extends Item implements ILens {
} else {
text = ((EntityItem) scan.entity).getEntityItem().getDisplayName();
}
x = scan.entity.posX;
y = scan.entity.posY;
z = scan.entity.posZ;
} else {
final MovingObjectPosition mop = EntityUtils.getMovingObjectPositionFromPlayer(p.worldObj, p, true);
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
x = mop.blockX;
y = mop.blockY;
z = mop.blockZ;
final TileEntity tile = p.worldObj.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
if (scan.type == 3 && scan.phenomena.startsWith("NODE") && tile instanceof INode) {
if (!this.isNew) {
@@ -126,7 +129,7 @@ public class ItemLensOrderEntropy extends Item implements ILens {
}
}
}
if (aspects != null || !text.isEmpty()) {
if (aspects != null || text.length() > 0) {
this.renderNameAndAspects(aspects, text);
}
}
@@ -166,21 +169,24 @@ public class ItemLensOrderEntropy extends Item implements ILens {
final int h = sr.getScaledHeight();
if (aspects != null && aspects.size() > 0) {
int num = 0;
int yOff = 0;
int thisRow = 0;
final int size = 18;
int thisRow = Math.min(aspects.size() - num, 5);
thisRow = Math.min(aspects.size() - num, 5);
for (final Aspect asp : aspects.getAspects()) {
int yOff = num / 5 * size;
yOff = num / 5 * size;
this.drawAspectTag(
asp,
aspects.getAmount(asp),
w / 2 - size * thisRow / 2 + size * (num % 5),
h / 2 + 16 + yOff);
h / 2 + 16 + yOff,
w);
if (++num % 5 == 0) {
thisRow = Math.min(aspects.size() - num, 5);
}
}
}
if (!text.isEmpty()) {
if (text.length() > 0) {
Minecraft.getMinecraft().ingameGUI.drawString(
Minecraft.getMinecraft().fontRenderer,
text,
@@ -190,21 +196,34 @@ public class ItemLensOrderEntropy extends Item implements ILens {
}
}
private ScanResult doScan(final ItemStack stack, final World world, final EntityPlayer player) {
final Entity pointedEntity = EntityUtils.getPointedEntity(player.worldObj, player, 0.5, 10.0, 0.0f, true);
private ScanResult doScan(final ItemStack stack, final World world, final EntityPlayer p, final int count) {
final Entity pointedEntity = EntityUtils.getPointedEntity(p.worldObj, p, 0.5, 10.0, 0.0f, true);
if (pointedEntity == null) {
final MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(player.worldObj, player, true);
final MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(p.worldObj, p, true);
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
final TileEntity tile = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
if (tile instanceof INode) {
final ScanResult sr = new ScanResult((byte) 3, 0, 0, null, "NODE" + ((INode) tile).getId());
return getScanResult(world, player, mop, sr);
if (ScanManager.isValidScanTarget(p, sr, "@")) {
Thaumcraft.proxy.blockRunes(
world,
mop.blockX,
mop.blockY + 0.25,
mop.blockZ,
0.3f + world.rand.nextFloat() * 0.7f,
0.0f,
0.3f + world.rand.nextFloat() * 0.7f,
15,
0.03f);
this.isNew = true;
return sr;
}
return sr;
} else {
final Block bi = world.getBlock(mop.blockX, mop.blockY, mop.blockZ);
if (bi != Blocks.air) {
final int md = bi.getDamageValue(world, mop.blockX, mop.blockY, mop.blockZ);
ItemStack is = bi
.getPickBlock(mop, player.worldObj, mop.blockX, mop.blockY, mop.blockZ, player);
ItemStack is = bi.getPickBlock(mop, p.worldObj, mop.blockX, mop.blockY, mop.blockZ);
ScanResult sr2 = null;
try {
if (is == null) {
@@ -223,12 +242,26 @@ public class ItemLensOrderEntropy extends Item implements ILens {
"");
}
} catch (Exception ignored) {}
return getScanResult(world, player, mop, sr2);
if (ScanManager.isValidScanTarget(p, sr2, "@")) {
Thaumcraft.proxy.blockRunes(
world,
mop.blockX,
mop.blockY + 0.25,
mop.blockZ,
0.3f + world.rand.nextFloat() * 0.7f,
0.0f,
0.3f + world.rand.nextFloat() * 0.7f,
15,
0.03f);
this.isNew = true;
return sr2;
}
return sr2;
}
}
}
for (final IScanEventHandler seh : ThaumcraftApi.scanEventhandlers) {
final ScanResult scan = seh.scanPhenomena(stack, world, player);
final ScanResult scan = seh.scanPhenomena(stack, world, p);
if (scan != null) {
return scan;
}
@@ -236,7 +269,7 @@ public class ItemLensOrderEntropy extends Item implements ILens {
return null;
}
final ScanResult sr3 = new ScanResult((byte) 2, 0, 0, pointedEntity, "");
if (ScanManager.isValidScanTarget(player, sr3, "@")) {
if (ScanManager.isValidScanTarget(p, sr3, "@")) {
Thaumcraft.proxy.blockRunes(
world,
pointedEntity.posX - 0.5,
@@ -253,30 +286,11 @@ public class ItemLensOrderEntropy extends Item implements ILens {
return sr3;
}
@Nullable
private ScanResult getScanResult(World world, EntityPlayer player, MovingObjectPosition mop, ScanResult sr) {
if (ScanManager.isValidScanTarget(player, sr, "@")) {
Thaumcraft.proxy.blockRunes(
world,
mop.blockX,
mop.blockY + 0.25,
mop.blockZ,
0.3f + world.rand.nextFloat() * 0.7f,
0.0f,
0.3f + world.rand.nextFloat() * 0.7f,
15,
0.03f);
this.isNew = true;
}
return sr;
}
public String getUnlocalizedName(final ItemStack par1ItemStack) {
return "item.LensOrderEntropy";
}
public void drawAspectTag(final Aspect aspect, final int amount, final int x, final int y) {
public void drawAspectTag(final Aspect aspect, final int amount, final int x, final int y, final int sw) {
GL11.glPushMatrix();
GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569f);
GL11.glEnable(GL11.GL_BLEND);
@@ -4,8 +4,6 @@
package com.kentington.thaumichorizons.common.items.lenses;
import static com.kentington.thaumichorizons.common.items.lenses.LensPotionEffects.isNightVisionGrantedByLens;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -19,7 +17,7 @@ import net.minecraft.util.IIcon;
import com.kentington.thaumichorizons.common.ThaumicHorizons;
import com.kentington.thaumichorizons.common.lib.networking.PacketHandler;
import com.kentington.thaumichorizons.common.lib.networking.PacketRemoveLensNightvision;
import com.kentington.thaumichorizons.common.lib.networking.PacketRemoveNightvision;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -36,28 +34,16 @@ public class ItemLensWater extends Item implements ILens {
return "LensWater";
}
@Override
public int getItemStackLimit(ItemStack stack) {
return 1;
}
public void handleRender(final Minecraft mc, final float partialTicks) {
final boolean inWater = mc.thePlayer.isInsideOfMaterial(Material.water);
final PotionEffect effect = mc.thePlayer.getActivePotionEffect(Potion.nightVision);
if (inWater) {
// Apply effect.
if ((effect == null || (isNightVisionGrantedByLens(effect) && effect.getDuration() < 242))
&& Minecraft.getSystemTime() > LensManager.nightVisionOffTime) {
LensManager.nightVisionOffTime = Minecraft.getSystemTime();
mc.thePlayer
.addPotionEffect(new LensPotionEffects.LensNightVision(Potion.nightVision.id, 255, -1, true));
}
} else {
// Remove effect.
if (isNightVisionGrantedByLens(effect)) {
mc.thePlayer.removePotionEffect(Potion.nightVision.id);
}
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);
}
}
@@ -76,6 +62,7 @@ public class ItemLensWater extends Item implements ILens {
}
public void handleRemoval(final EntityPlayer p) {
PacketHandler.INSTANCE.sendTo(new PacketRemoveLensNightvision(), (EntityPlayerMP) p);
p.removePotionEffect(Potion.nightVision.id);
PacketHandler.INSTANCE.sendTo(new PacketRemoveNightvision(), (EntityPlayerMP) p);
}
}
@@ -27,88 +27,89 @@ public class LensManager {
public static long nightVisionOffTime;
public static void changeLens(final ItemStack is, final World w, final EntityPlayer player, final String lens) {
final TreeMap<String, Integer> lenses = new TreeMap<>();
final HashMap<Integer, Integer> pouches = new HashMap<>();
final IRevealer goggles = (IRevealer) is.getItem();
final TreeMap lenses = new TreeMap<>();
final HashMap pouches = new HashMap<>();
int pouchcount = 0;
ItemStack item = null;
final IInventory baubles = BaublesApi.getBaubles(player);
final int baubleSlots = baubles.getSizeInventory();
for (int a = 0; a < baubleSlots; ++a) {
if (baubles.getStackInSlot(a) != null
&& baubles.getStackInSlot(a).getItem() instanceof ItemLensCase lensCase) {
for (int a = 0; a < 4; ++a) {
if (baubles.getStackInSlot(a) != null && baubles.getStackInSlot(a).getItem() instanceof ItemLensCase) {
++pouchcount;
item = baubles.getStackInSlot(a);
pouches.put(pouchcount, a - baubleSlots);
final ItemStack[] inv = lensCase.getInventory(item);
pouches.put(pouchcount, a - 4);
final ItemStack[] inv = ((ItemLensCase) item.getItem()).getInventory(item);
for (int q = 0; q < inv.length; ++q) {
item = inv[q];
if (item != null && item.getItem() instanceof ILens newLens) {
lenses.put(newLens.lensName(), q + pouchcount * 1000);
if (item != null && item.getItem() instanceof ILens) {
lenses.put(((ILens) item.getItem()).lensName(), q + pouchcount * 1000);
}
}
}
}
for (int newkey = 0; newkey < 36; ++newkey) {
item = player.inventory.mainInventory[newkey];
if (item != null && item.getItem() instanceof ILens newLens) {
lenses.put(newLens.lensName(), newkey);
if (item != null && item.getItem() instanceof ILens) {
lenses.put(((ILens) item.getItem()).lensName(), newkey);
}
if (item != null && item.getItem() instanceof ItemLensCase lensCase) {
if (item != null && item.getItem() instanceof ItemLensCase) {
++pouchcount;
pouches.put(pouchcount, newkey);
final ItemStack[] pid = lensCase.getInventory(item);
final ItemStack[] pid = ((ItemLensCase) item.getItem()).getInventory(item);
for (int pouchslot = 0; pouchslot < pid.length; ++pouchslot) {
item = pid[pouchslot];
if (item != null && item.getItem() instanceof ILens newLens) {
lenses.put(newLens.lensName(), pouchslot + pouchcount * 1000);
if (item != null && item.getItem() instanceof ILens) {
lenses.put(((ILens) item.getItem()).lensName(), pouchslot + pouchcount * 1000);
}
}
}
}
ItemStack oldLens;
if (!lens.equals("REMOVE") && !lenses.isEmpty()) {
String var13 = lens;
if (lenses.get(lens) == null) {
var13 = lenses.higherKey(lens);
}
if (var13 == null || lenses.get(var13) == null) {
var13 = lenses.firstKey();
}
if (lenses.get(var13) < 1000) {
item = player.inventory.mainInventory[lenses.get(var13)].copy();
} else {
final int var14 = lenses.get(var13) / 1000;
if (pouches.containsKey(var14)) {
final int pouchSlot = pouches.get(var14);
final int lensSlot = lenses.get(var13) - (var14 * 1000);
ItemStack tmp;
if (pouchSlot >= 0) {
tmp = player.inventory.mainInventory[pouchSlot].copy();
} else {
tmp = baubles.getStackInSlot(pouchSlot + baubleSlots).copy();
}
item = fetchLensFromPouch(player, lensSlot, tmp, pouchSlot);
ItemStack oldLens = null;
if (!lens.equals("REMOVE") && lenses.size() != 0) {
if (lenses != null && lenses.size() > 0 && lens != null) {
String var13 = lens;
if (lenses.get(lens) == null) {
var13 = (String) lenses.higherKey(lens);
}
if (var13 == null || lenses.get(var13) == null) {
var13 = (String) lenses.firstKey();
}
if ((Integer) lenses.get(var13) < 1000) {
item = player.inventory.mainInventory[(Integer) lenses.get(var13)].copy();
} else {
final int var14 = (Integer) lenses.get(var13) / 1000;
if (pouches.containsKey(var14)) {
final int pouchslot = (Integer) pouches.get(var14);
final int lensSlot = (Integer) lenses.get(var13) - (var14 * 1000);
ItemStack tmp;
if (pouchslot >= 0) {
tmp = player.inventory.mainInventory[pouchslot].copy();
} else {
tmp = baubles.getStackInSlot(pouchslot + 4).copy();
}
item = fetchLensFromPouch(player, lensSlot, tmp, pouchslot);
}
}
if (item == null) {
return;
}
if ((Integer) lenses.get(var13) < 1000) {
player.inventory.setInventorySlotContents((Integer) lenses.get(var13), null);
}
w.playSoundAtEntity(player, "thaumcraft:cameraticks", 0.3f, 1.0f);
String currentLens = "";
if (is.stackTagCompound != null) {
currentLens = is.stackTagCompound.getString("Lens");
}
oldLens = getLensItem(currentLens);
if (!currentLens.equals("") && (addLensToPouch(player, oldLens, pouches)
|| player.inventory.addItemStackToInventory(oldLens))) {
setLensItem(is, item);
} else if (currentLens.equals("")) {
setLensItem(is, item);
} else if (!addLensToPouch(player, item, pouches)) {
player.inventory.addItemStackToInventory(item);
}
}
if (item == null) {
return;
}
if (lenses.get(var13) < 1000) {
player.inventory.decrStackSize(lenses.get(var13), 1);
}
w.playSoundAtEntity(player, "thaumcraft:cameraticks", 0.3f, 1.0f);
String currentLens = "";
if (is.stackTagCompound != null) {
currentLens = is.stackTagCompound.getString("Lens");
}
oldLens = getLensItem(currentLens);
if (!currentLens.isEmpty() && (addLensToPouch(player, oldLens, pouches)
|| player.inventory.addItemStackToInventory(oldLens))) {
setLensItem(is, item);
} else if (currentLens.isEmpty()) {
setLensItem(is, item);
} else if (!addLensToPouch(player, item, pouches)) {
player.inventory.addItemStackToInventory(item);
}
} else {
String currentLens2 = "";
@@ -116,7 +117,7 @@ public class LensManager {
currentLens2 = is.stackTagCompound.getString("Lens");
}
oldLens = getLensItem(currentLens2);
if (!currentLens2.isEmpty() && (addLensToPouch(player, oldLens, pouches)
if (!currentLens2.equals("") && (addLensToPouch(player, oldLens, pouches)
|| player.inventory.addItemStackToInventory(oldLens))) {
setLensItem(is, null);
w.playSoundAtEntity(player, "thaumcraft:cameraticks", 0.3f, 0.9f);
@@ -127,25 +128,21 @@ public class LensManager {
}
}
private static ItemStack fetchLensFromPouch(final EntityPlayer player, final int lensId, final ItemStack pouch,
final int pouchSlot) {
private static ItemStack fetchLensFromPouch(final EntityPlayer player, final int lensid, final ItemStack pouch,
final int pouchslot) {
ItemStack lens = null;
final ItemStack[] inv = ((ItemLensCase) pouch.getItem()).getInventory(pouch);
final ItemStack contents = inv[lensId];
final ItemStack contents = inv[lensid];
if (contents != null && contents.getItem() instanceof ILens) {
lens = contents.copy();
if (contents.stackSize <= 1) {
inv[lensId] = null;
} else {
contents.stackSize--;
}
inv[lensid] = null;
((ItemLensCase) pouch.getItem()).setInventory(pouch, inv);
if (pouchSlot >= 0) {
player.inventory.setInventorySlotContents(pouchSlot, pouch);
if (pouchslot >= 0) {
player.inventory.setInventorySlotContents(pouchslot, pouch);
player.inventory.markDirty();
} else {
final IInventory baubles = BaublesApi.getBaubles(player);
baubles.setInventorySlotContents(pouchSlot + baubles.getSizeInventory(), pouch);
baubles.setInventorySlotContents(pouchslot + 4, pouch);
baubles.markDirty();
}
}
@@ -154,13 +151,14 @@ public class LensManager {
private static boolean addLensToPouch(final EntityPlayer player, final ItemStack lens,
final HashMap<Integer, Integer> pouches) {
for (int pouchSlot : pouches.values()) {
for (int value : pouches.values()) {
final IInventory baubles = BaublesApi.getBaubles(player);
final int pouchslot = value;
ItemStack pouch;
if (pouchSlot >= 0) {
pouch = player.inventory.mainInventory[pouchSlot];
if (pouchslot >= 0) {
pouch = player.inventory.mainInventory[pouchslot];
} else {
pouch = baubles.getStackInSlot(pouchSlot + baubles.getSizeInventory());
pouch = baubles.getStackInSlot(pouchslot + 4);
}
final ItemStack[] inv = ((ItemLensCase) pouch.getItem()).getInventory(pouch);
for (int q = 0; q < inv.length; ++q) {
@@ -168,11 +166,11 @@ public class LensManager {
if (contents == null) {
inv[q] = lens.copy();
((ItemLensCase) pouch.getItem()).setInventory(pouch, inv);
if (pouchSlot >= 0) {
player.inventory.setInventorySlotContents(pouchSlot, pouch);
if (pouchslot >= 0) {
player.inventory.setInventorySlotContents(pouchslot, pouch);
player.inventory.markDirty();
} else {
baubles.setInventorySlotContents(pouchSlot + baubles.getSizeInventory(), pouch);
baubles.setInventorySlotContents(pouchslot + 4, pouch);
baubles.markDirty();
}
player.inventory.markDirty();
@@ -190,27 +188,23 @@ public class LensManager {
return null;
}
public static ILens getLensFromItem(final ItemStack stack) {
if (stack == null || !(stack.getItem() instanceof IRevealer) || stack.stackTagCompound == null) {
return null;
}
final String lensName = stack.stackTagCompound.getString("Lens");
if (lensName.isEmpty()) {
return null;
}
final Item lensItem = getLens(lensName);
return lensItem instanceof ILens ? (ILens) lensItem : null;
}
public static Item getLens(final String lens) {
return switch (lens) {
case "LensFire" -> ThaumicHorizons.itemLensFire;
case "LensWater" -> ThaumicHorizons.itemLensWater;
case "LensEarth" -> ThaumicHorizons.itemLensEarth;
case "LensAir" -> ThaumicHorizons.itemLensAir;
case "LensOrderEntropy" -> ThaumicHorizons.itemLensOrderEntropy;
default -> null;
};
if (lens.equals("LensFire")) {
return ThaumicHorizons.itemLensFire;
}
if (lens.equals("LensWater")) {
return ThaumicHorizons.itemLensWater;
}
if (lens.equals("LensEarth")) {
return ThaumicHorizons.itemLensEarth;
}
if (lens.equals("LensAir")) {
return ThaumicHorizons.itemLensAir;
}
if (lens.equals("LensOrderEntropy")) {
return ThaumicHorizons.itemLensOrderEntropy;
}
return null;
}
public static void setLensItem(final ItemStack goggles, final ItemStack lens) {
@@ -1,27 +0,0 @@
package com.kentington.thaumichorizons.common.items.lenses;
import net.minecraft.potion.PotionEffect;
public class LensPotionEffects {
public static boolean isNightVisionGrantedByLens(PotionEffect effect) {
return effect instanceof LensNightVision lensNightvision && lensNightvision.isGrantedByLens;
}
static class LensNightVision extends PotionEffect {
public boolean isGrantedByLens;
public LensNightVision(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 LensNightVision;
}
}
}
@@ -15,7 +15,6 @@ import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.input.Keyboard;
import com.kentington.thaumichorizons.client.lib.RenderEventHandler;
import com.kentington.thaumichorizons.common.ThaumicHorizons;
import com.kentington.thaumichorizons.common.lib.networking.PacketFingersToServer;
import com.kentington.thaumichorizons.common.lib.networking.PacketHandler;
@@ -44,10 +43,9 @@ public class THKeyHandler {
private boolean keyPressedX;
public static long lastPressX;
private boolean keyPressedV;
public static long lastPressV;
public static boolean radialActive;
public static boolean radialLock;
public static boolean radialSelectionMade;
public static long lastPressV;
public THKeyHandler() {
this.keyV = new KeyBinding("Change Arcane Lens", Keyboard.KEY_NONE, "Thaumcraft");
@@ -67,147 +65,149 @@ public class THKeyHandler {
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void playerTick(final TickEvent.PlayerTickEvent event) {
if (event.side == Side.SERVER) return;
if (event.phase != TickEvent.Phase.START) return;
if (this.keyV.getIsKeyPressed()) {
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
final EntityPlayer player = event.player;
if (player != null) {
if (!this.keyPressedV) {
THKeyHandler.lastPressV = System.currentTimeMillis();
THKeyHandler.radialLock = false;
THKeyHandler.radialSelectionMade = false;
}
if (!THKeyHandler.radialLock && !THKeyHandler.radialSelectionMade
&& player.inventory.armorItemInSlot(3) != null
&& player.inventory.armorItemInSlot(3).getItem() instanceof IRevealer) {
if (player.isSneaking()) {
PacketHandler.INSTANCE.sendToServer(new PacketLensChangeToServer("REMOVE"));
} else if (RenderEventHandler.radialHudScale <= 0.0f) {
THKeyHandler.radialActive = true;
if (event.side == Side.SERVER) {
return;
}
if (event.phase == TickEvent.Phase.START) {
if (this.keyV.getIsKeyPressed()) {
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
final EntityPlayer player = event.player;
if (player != null) {
if (!this.keyPressedV) {
THKeyHandler.lastPressV = System.currentTimeMillis();
THKeyHandler.radialLock = false;
}
if (!THKeyHandler.radialLock && player.inventory.armorItemInSlot(3) != null
&& player.inventory.armorItemInSlot(3).getItem() instanceof IRevealer) {
if (player.isSneaking()) {
PacketHandler.INSTANCE.sendToServer(new PacketLensChangeToServer(player, "REMOVE"));
} else {
THKeyHandler.radialActive = true;
}
}
}
this.keyPressedV = true;
}
this.keyPressedV = true;
}
} else {
THKeyHandler.radialActive = false;
THKeyHandler.radialSelectionMade = false;
if (this.keyPressedV) {
THKeyHandler.lastPressV = System.currentTimeMillis();
}
this.keyPressedV = false;
}
if (this.keyM.getIsKeyPressed()) {
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
final EntityPlayer player = event.player;
if (player != null) {
if (!this.keyPressedM) {
THKeyHandler.lastPressM = System.currentTimeMillis();
}
if (((EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion"))
.hasPlayerInfusion(2) && !this.keyPressedM) {
player.openGui(
ThaumicHorizons.instance,
9,
player.worldObj,
(int) player.posX,
(int) player.posY,
(int) player.posZ);
PacketHandler.INSTANCE.sendToServer(new PacketFingersToServer());
}
} else {
THKeyHandler.radialActive = false;
if (this.keyPressedV) {
THKeyHandler.lastPressV = System.currentTimeMillis();
}
this.keyPressedM = true;
this.keyPressedV = false;
}
} else {
if (this.keyPressedM) {
THKeyHandler.lastPressM = System.currentTimeMillis();
}
this.keyPressedM = false;
}
if (this.keyC.getIsKeyPressed()) {
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
final EntityPlayer player = event.player;
if (player != null) {
if (!this.keyPressedC) {
THKeyHandler.lastPressC = System.currentTimeMillis();
}
if (((EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion"))
.hasPlayerInfusion(9) && !this.keyPressedC) {
((EntityInfusionProperties) player.getExtendedProperties(
"CreatureInfusion")).toggleClimb = !((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleClimb;
if (((EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion")).toggleClimb) {
player.addChatMessage(
new ChatComponentText(
EnumChatFormatting.ITALIC + ""
+ EnumChatFormatting.GRAY
+ "Spider Climb disabled."));
} else {
player.addChatMessage(
new ChatComponentText(
EnumChatFormatting.ITALIC + ""
+ EnumChatFormatting.GRAY
+ "Spider Climb enabled."));
if (this.keyM.getIsKeyPressed()) {
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
final EntityPlayer player = event.player;
if (player != null) {
if (!this.keyPressedM) {
THKeyHandler.lastPressM = System.currentTimeMillis();
}
PacketHandler.INSTANCE.sendToServer(new PacketToggleClimbToServer());
}
}
this.keyPressedC = true;
}
} else {
if (this.keyPressedC) {
THKeyHandler.lastPressC = System.currentTimeMillis();
}
this.keyPressedC = false;
}
if (this.keyX.getIsKeyPressed()) {
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
final EntityPlayer player = event.player;
if (player != null) {
if (!this.keyPressedX) {
THKeyHandler.lastPressX = System.currentTimeMillis();
}
if (((EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion"))
.hasPlayerInfusion(10) && !this.keyPressedX) {
((EntityInfusionProperties) player.getExtendedProperties(
"CreatureInfusion")).toggleInvisible = !((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleInvisible;
if (((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleInvisible) {
player.removePotionEffectClient(Potion.invisibility.id);
player.setInvisible(false);
player.addChatMessage(
new ChatComponentText(
EnumChatFormatting.ITALIC + ""
+ EnumChatFormatting.GRAY
+ "Chameleon Skin disabled."));
} else {
final PotionEffect effect = new PotionEffect(
Potion.invisibility.id,
Integer.MAX_VALUE,
0,
true);
effect.setCurativeItems(new ArrayList<>());
player.addPotionEffect(effect);
player.setInvisible(true);
player.addChatMessage(
new ChatComponentText(
EnumChatFormatting.ITALIC + ""
+ EnumChatFormatting.GRAY
+ "Chameleon Skin enabled."));
if (((EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion"))
.hasPlayerInfusion(2) && !this.keyPressedM) {
player.openGui(
ThaumicHorizons.instance,
9,
player.worldObj,
(int) player.posX,
(int) player.posY,
(int) player.posZ);
PacketHandler.INSTANCE.sendToServer(new PacketFingersToServer(player, player.dimension));
}
PacketHandler.INSTANCE.sendToServer(new PacketToggleInvisibleToServer());
}
this.keyPressedM = true;
}
this.keyPressedX = true;
} else {
if (this.keyPressedM) {
THKeyHandler.lastPressM = System.currentTimeMillis();
}
this.keyPressedM = false;
}
} else {
if (this.keyPressedX) {
THKeyHandler.lastPressX = System.currentTimeMillis();
if (this.keyC.getIsKeyPressed()) {
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
final EntityPlayer player = event.player;
if (player != null) {
if (!this.keyPressedC) {
THKeyHandler.lastPressC = System.currentTimeMillis();
}
if (((EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion"))
.hasPlayerInfusion(9) && !this.keyPressedC) {
((EntityInfusionProperties) player.getExtendedProperties(
"CreatureInfusion")).toggleClimb = !((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleClimb;
if (((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleClimb) {
player.addChatMessage(
new ChatComponentText(
EnumChatFormatting.ITALIC + ""
+ EnumChatFormatting.GRAY
+ "Spider Climb disabled."));
} else {
player.addChatMessage(
new ChatComponentText(
EnumChatFormatting.ITALIC + ""
+ EnumChatFormatting.GRAY
+ "Spider Climb enabled."));
}
PacketHandler.INSTANCE
.sendToServer(new PacketToggleClimbToServer(player, player.dimension));
}
}
this.keyPressedC = true;
}
} else {
if (this.keyPressedC) {
THKeyHandler.lastPressC = System.currentTimeMillis();
}
this.keyPressedC = false;
}
if (this.keyX.getIsKeyPressed()) {
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
final EntityPlayer player = event.player;
if (player != null) {
if (!this.keyPressedX) {
THKeyHandler.lastPressX = System.currentTimeMillis();
}
if (((EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion"))
.hasPlayerInfusion(10) && !this.keyPressedX) {
((EntityInfusionProperties) player.getExtendedProperties(
"CreatureInfusion")).toggleInvisible = !((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleInvisible;
if (((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleInvisible) {
player.removePotionEffectClient(Potion.invisibility.id);
player.setInvisible(false);
player.addChatMessage(
new ChatComponentText(
EnumChatFormatting.ITALIC + ""
+ EnumChatFormatting.GRAY
+ "Chameleon Skin disabled."));
} else {
final PotionEffect effect = new PotionEffect(
Potion.invisibility.id,
Integer.MAX_VALUE,
0,
true);
effect.setCurativeItems(new ArrayList<>());
player.addPotionEffect(effect);
player.setInvisible(true);
player.addChatMessage(
new ChatComponentText(
EnumChatFormatting.ITALIC + ""
+ EnumChatFormatting.GRAY
+ "Chameleon Skin enabled."));
}
PacketHandler.INSTANCE
.sendToServer(new PacketToggleInvisibleToServer(player, player.dimension));
}
}
this.keyPressedX = true;
}
} else {
if (this.keyPressedX) {
THKeyHandler.lastPressX = System.currentTimeMillis();
}
this.keyPressedX = false;
}
this.keyPressedX = false;
}
}
@@ -215,9 +215,8 @@ public class THKeyHandler {
THKeyHandler.lastPressM = 0L;
THKeyHandler.lastPressC = 0L;
THKeyHandler.lastPressX = 0L;
THKeyHandler.lastPressV = 0L;
THKeyHandler.radialActive = false;
THKeyHandler.radialLock = false;
THKeyHandler.radialSelectionMade = false;
THKeyHandler.lastPressV = 0L;
}
}
@@ -5,6 +5,8 @@
package com.kentington.thaumichorizons.common.lib.networking;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import com.kentington.thaumichorizons.common.ThaumicHorizons;
@@ -15,17 +17,32 @@ import io.netty.buffer.ByteBuf;
public class PacketFingersToServer implements IMessage, IMessageHandler<PacketFingersToServer, IMessage> {
private int playerid;
private int dim;
public PacketFingersToServer() {}
public void toBytes(final ByteBuf buffer) {}
public PacketFingersToServer(final EntityPlayer player, final int dim) {
this.playerid = player.getEntityId();
this.dim = dim;
}
public void fromBytes(final ByteBuf buffer) {}
public void toBytes(final ByteBuf buffer) {
buffer.writeInt(this.playerid);
buffer.writeInt(this.dim);
}
public void fromBytes(final ByteBuf buffer) {
this.playerid = buffer.readInt();
this.dim = buffer.readInt();
}
public IMessage onMessage(final PacketFingersToServer message, final MessageContext ctx) {
if (PacketHandler.selfInfusionSecurityCheck(ctx, "open workbench", 2)) {
if (!PacketHandler.selfInfusionSecurityCheck(ctx, "open workbench", message.playerid, 2)) {
return null;
}
final EntityPlayer player = ctx.getServerHandler().playerEntity;
final World world = DimensionManager.getWorld(message.dim);
final EntityPlayer player = (EntityPlayer) world.getEntityByID(message.playerid);
player.openGui(
ThaumicHorizons.instance,
9,
@@ -38,11 +38,8 @@ public class PacketHandler {
PacketHandler.INSTANCE.registerMessage(PacketNoMoreItems.class, PacketNoMoreItems.class, idx++, Side.CLIENT);
PacketHandler.INSTANCE
.registerMessage(PacketFXBlocksplosion.class, PacketFXBlocksplosion.class, idx++, Side.CLIENT);
PacketHandler.INSTANCE.registerMessage(
PacketRemoveLensNightvision.class,
PacketRemoveLensNightvision.class,
idx++,
Side.CLIENT);
PacketHandler.INSTANCE
.registerMessage(PacketRemoveNightvision.class, PacketRemoveNightvision.class, idx++, Side.CLIENT);
PacketHandler.INSTANCE
.registerMessage(PacketFingersToServer.class, PacketFingersToServer.class, idx++, Side.SERVER);
PacketHandler.INSTANCE
@@ -56,24 +53,32 @@ public class PacketHandler {
PacketToggleInvisibleToServer.class,
idx++,
Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketRainState.class, PacketRainState.class, idx, Side.CLIENT);
PacketHandler.INSTANCE.registerMessage(PacketRainState.class, PacketRainState.class, idx++, Side.CLIENT);
}
static {
INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("ThaumicHorizons".toLowerCase());
}
static boolean selfInfusionSecurityCheck(final MessageContext ctx, String action, int requiredInfusion) {
private static void securityWarn(String message, Object... args) {
ThaumicHorizons.log.warn(SECURITY_MARKER, message, args);
}
static boolean selfInfusionSecurityCheck(final MessageContext ctx, String action, int sentPlayerID,
int requiredInfusion) {
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
if (player.getEntityId() != sentPlayerID) {
PacketHandler.securityWarn("Player {} tried to {} for other people!", player.getGameProfile(), action);
return false;
}
EntityInfusionProperties ieep = (EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion");
if (!ieep.hasInfusion(requiredInfusion)) {
ThaumicHorizons.log.warn(
SECURITY_MARKER,
"Player {} tried to {} without getting the ability legitimately",
PacketHandler.securityWarn(
"Player {} tried to {} getting the ability legitimately",
player.getGameProfile(),
action);
return true;
return false;
}
return false;
return true;
}
}
@@ -4,7 +4,10 @@
package com.kentington.thaumichorizons.common.lib.networking;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import com.kentington.thaumichorizons.common.items.lenses.LensManager;
@@ -17,30 +20,44 @@ import thaumcraft.api.nodes.IRevealer;
public class PacketLensChangeToServer implements IMessage, IMessageHandler<PacketLensChangeToServer, IMessage> {
private int dim;
private int playerid;
private String lens;
public PacketLensChangeToServer() {}
public PacketLensChangeToServer(final String lens) {
public PacketLensChangeToServer(final EntityPlayer player, final String lens) {
this.dim = player.worldObj.provider.dimensionId;
this.playerid = player.getEntityId();
this.lens = lens;
}
public void toBytes(final ByteBuf buffer) {
buffer.writeInt(this.dim);
buffer.writeInt(this.playerid);
ByteBufUtils.writeUTF8String(buffer, this.lens);
}
public void fromBytes(final ByteBuf buffer) {
this.dim = buffer.readInt();
this.playerid = buffer.readInt();
this.lens = ByteBufUtils.readUTF8String(buffer);
}
public IMessage onMessage(final PacketLensChangeToServer message, final MessageContext ctx) {
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
if (player.worldObj == null) {
final World world = DimensionManager.getWorld(message.dim);
if (world == null || (ctx.getServerHandler().playerEntity != null
&& ctx.getServerHandler().playerEntity.getEntityId() != message.playerid)) {
return null;
}
if (player.inventory.armorItemInSlot(3) != null
&& player.inventory.armorItemInSlot(3).getItem() instanceof IRevealer) {
LensManager.changeLens(player.inventory.armorItemInSlot(3), player.worldObj, player, message.lens);
final Entity player = world.getEntityByID(message.playerid);
if (player instanceof EntityPlayer && ((EntityPlayer) player).inventory.armorItemInSlot(3) != null
&& ((EntityPlayer) player).inventory.armorItemInSlot(3).getItem() instanceof IRevealer) {
LensManager.changeLens(
((EntityPlayer) player).inventory.armorItemInSlot(3),
world,
(EntityPlayer) player,
message.lens);
}
return null;
}
@@ -1,34 +0,0 @@
//
// Decompiled by Procyon v0.5.30
//
package com.kentington.thaumichorizons.common.lib.networking;
import static com.kentington.thaumichorizons.common.items.lenses.LensPotionEffects.isNightVisionGrantedByLens;
import net.minecraft.client.Minecraft;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import com.kentington.thaumichorizons.common.items.lenses.LensManager;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
public class PacketRemoveLensNightvision implements IMessage, IMessageHandler<PacketRemoveLensNightvision, IMessage> {
public IMessage onMessage(final PacketRemoveLensNightvision message, final MessageContext ctx) {
final PotionEffect effect = Minecraft.getMinecraft().thePlayer.getActivePotionEffect(Potion.nightVision);
if (isNightVisionGrantedByLens(effect)) {
Minecraft.getMinecraft().thePlayer.removePotionEffect(Potion.nightVision.id);
LensManager.nightVisionOffTime = Minecraft.getSystemTime() + 100L;
}
return null;
}
public void fromBytes(final ByteBuf buf) {}
public void toBytes(final ByteBuf buf) {}
}
@@ -0,0 +1,32 @@
//
// Decompiled by Procyon v0.5.30
//
package com.kentington.thaumichorizons.common.lib.networking;
import net.minecraft.client.Minecraft;
import net.minecraft.potion.Potion;
import com.kentington.thaumichorizons.common.items.lenses.LensManager;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
public class PacketRemoveNightvision implements IMessage, IMessageHandler<PacketRemoveNightvision, IMessage> {
@SideOnly(Side.CLIENT)
public IMessage onMessage(final PacketRemoveNightvision message, final MessageContext ctx) {
Minecraft.getMinecraft().thePlayer.removePotionEffect(Potion.nightVision.id);
Minecraft.getMinecraft();
LensManager.nightVisionOffTime = Minecraft.getSystemTime() + 100L;
return null;
}
public void fromBytes(final ByteBuf buf) {}
public void toBytes(final ByteBuf buf) {}
}
@@ -5,6 +5,8 @@
package com.kentington.thaumichorizons.common.lib.networking;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import com.kentington.thaumichorizons.common.lib.EntityInfusionProperties;
@@ -15,17 +17,32 @@ import io.netty.buffer.ByteBuf;
public class PacketToggleClimbToServer implements IMessage, IMessageHandler<PacketToggleClimbToServer, IMessage> {
private int playerid;
private int dim;
public PacketToggleClimbToServer() {}
public void toBytes(final ByteBuf buffer) {}
public PacketToggleClimbToServer(final EntityPlayer player, final int dim) {
this.playerid = player.getEntityId();
this.dim = dim;
}
public void fromBytes(final ByteBuf buffer) {}
public void toBytes(final ByteBuf buffer) {
buffer.writeInt(this.playerid);
buffer.writeInt(this.dim);
}
public void fromBytes(final ByteBuf buffer) {
this.playerid = buffer.readInt();
this.dim = buffer.readInt();
}
public IMessage onMessage(final PacketToggleClimbToServer message, final MessageContext ctx) {
if (PacketHandler.selfInfusionSecurityCheck(ctx, "toggle spider climb", 9)) {
if (!PacketHandler.selfInfusionSecurityCheck(ctx, "toggle spider climb", message.playerid, 9)) {
return null;
}
final EntityPlayer player = ctx.getServerHandler().playerEntity;
final World world = DimensionManager.getWorld(message.dim);
final EntityPlayer player = (EntityPlayer) world.getEntityByID(message.playerid);
((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleClimb = !((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleClimb;
@@ -6,6 +6,7 @@ package com.kentington.thaumichorizons.common.lib.networking;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
@@ -20,14 +21,29 @@ import io.netty.buffer.ByteBuf;
public class PacketToggleInvisibleToServer
implements IMessage, IMessageHandler<PacketToggleInvisibleToServer, IMessage> {
private int playerid;
private int dim;
public PacketToggleInvisibleToServer() {}
public void toBytes(final ByteBuf buffer) {}
public PacketToggleInvisibleToServer(final EntityPlayer player, final int dim) {
this.playerid = player.getEntityId();
this.dim = dim;
}
public void fromBytes(final ByteBuf buffer) {}
public void toBytes(final ByteBuf buffer) {
buffer.writeInt(this.playerid);
buffer.writeInt(this.dim);
}
public void fromBytes(final ByteBuf buffer) {
this.playerid = buffer.readInt();
this.dim = buffer.readInt();
}
public IMessage onMessage(final PacketToggleInvisibleToServer message, final MessageContext ctx) {
if (PacketHandler.selfInfusionSecurityCheck(ctx, "toggle chamelon skin (i.e. invisible)", 10)) {
if (!PacketHandler
.selfInfusionSecurityCheck(ctx, "toggle chamelon skin (i.e. invisible)", message.playerid, 10)) {
return null;
}
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
@@ -1239,22 +1239,25 @@ public class TileVat extends TileThaumcraft implements IAspectContainer, IEssent
EntityLivingBase created = null;
if ((Integer) out < 0) {
created = (EntityLivingBase) EntityList.createEntityByID(-(Integer) out, this.worldObj);
} else {
final ModContainer mc = Loader.instance().getIndexedModList().get("ThaumicHorizons");
try {
created = (EntityLivingBase) EntityRegistry.instance().lookupModSpawn(mc, (Integer) out)
.getEntityClass().getConstructor(World.class).newInstance(this.worldObj);
} catch (InvocationTargetException e) {
e.getCause().printStackTrace();
} catch (Exception e2) {
e2.printStackTrace();
}
}
final ModContainer mc = Loader.instance().getIndexedModList().get("ThaumicHorizons");
try {
created = (EntityLivingBase) EntityRegistry.instance().lookupModSpawn(mc, (Integer) out)
.getEntityClass().getConstructor(World.class).newInstance(this.worldObj);
} catch (InvocationTargetException e) {
e.getCause().printStackTrace();
} catch (Exception e2) {
e2.printStackTrace();
if (created != null) {
created.copyLocationAndAnglesFrom(this.getEntityContained());
created.copyDataFrom(this.getEntityContained(), true);
if (created instanceof IEntityInfusedStats) {
((IEntityInfusedStats) created).resetStats();
}
this.setEntityContained(created);
}
created.copyLocationAndAnglesFrom(this.getEntityContained());
created.copyDataFrom(this.getEntityContained(), true);
if (created instanceof IEntityInfusedStats) {
((IEntityInfusedStats) created).resetStats();
}
this.setEntityContained(created);
} else if (out instanceof NBTBase) {
final NBTTagCompound tagMods = (NBTTagCompound) out;
final Multimap map = HashMultimap.create();