diff --git a/src/main/java/com/hbm/extprop/HbmPlayerProps.java b/src/main/java/com/hbm/extprop/HbmPlayerProps.java index 9439b5572..e1b64d8e9 100644 --- a/src/main/java/com/hbm/extprop/HbmPlayerProps.java +++ b/src/main/java/com/hbm/extprop/HbmPlayerProps.java @@ -26,6 +26,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties { public boolean enableHUD = true; public boolean enableBackpack = true; + public boolean enableMagnet = true; private boolean[] keysPressed = new boolean[EnumKeybind.values().length]; @@ -71,6 +72,10 @@ public class HbmPlayerProps implements IExtendedEntityProperties { return this.enableBackpack && getKeyPressed(EnumKeybind.JETPACK); } + public boolean isMagnetActive(){ + return this.enableMagnet; + } + public void setKeyPressed(EnumKeybind key, boolean pressed) { if(!getKeyPressed(key) && pressed) { @@ -86,6 +91,16 @@ public class HbmPlayerProps implements IExtendedEntityProperties { MainRegistry.proxy.displayTooltip(EnumChatFormatting.RED + "Jetpack OFF", MainRegistry.proxy.ID_JETPACK); } } + if (key == EnumKeybind.TOGGLE_MAGNET){ + if (!player.worldObj.isRemote){ + this.enableMagnet = !this.enableMagnet; + + if(this.enableMagnet) + MainRegistry.proxy.displayTooltip(EnumChatFormatting.GREEN + "Magnet ON", MainRegistry.proxy.ID_MAGNET); + else + MainRegistry.proxy.displayTooltip(EnumChatFormatting.RED + "Magnet OFF", MainRegistry.proxy.ID_MAGNET); + } + } if(key == EnumKeybind.TOGGLE_HEAD) { if(!player.worldObj.isRemote) { @@ -174,6 +189,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties { buf.writeBoolean(this.enableHUD); buf.writeInt(this.reputation); buf.writeBoolean(this.isOnLadder); + buf.writeBoolean(this.enableMagnet); } public void deserialize(ByteBuf buf) { @@ -185,6 +201,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties { this.enableHUD = buf.readBoolean(); this.reputation = buf.readInt(); this.isOnLadder = buf.readBoolean(); + this.enableMagnet = buf.readBoolean(); } } @@ -198,6 +215,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties { props.setFloat("shield", shield); props.setFloat("maxShield", maxShield); props.setBoolean("enableBackpack", enableBackpack); + props.setBoolean("enableMagnet", enableMagnet); props.setBoolean("enableHUD", enableHUD); props.setInteger("reputation", reputation); props.setBoolean("isOnLadder", isOnLadder); @@ -216,6 +234,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties { this.shield = props.getFloat("shield"); this.maxShield = props.getFloat("maxShield"); this.enableBackpack = props.getBoolean("enableBackpack"); + this.enableMagnet = props.getBoolean("enableMagnet"); this.enableHUD = props.getBoolean("enableHUD"); this.reputation = props.getInteger("reputation"); this.isOnLadder = props.getBoolean("isOnLadder"); diff --git a/src/main/java/com/hbm/handler/HbmKeybinds.java b/src/main/java/com/hbm/handler/HbmKeybinds.java index 30ed60a37..890ef4474 100644 --- a/src/main/java/com/hbm/handler/HbmKeybinds.java +++ b/src/main/java/com/hbm/handler/HbmKeybinds.java @@ -22,6 +22,7 @@ public class HbmKeybinds { public static KeyBinding calculatorKey = new KeyBinding(category + ".calculator", Keyboard.KEY_N, category); public static KeyBinding jetpackKey = new KeyBinding(category + ".toggleBack", Keyboard.KEY_C, category); + public static KeyBinding magnetKey = new KeyBinding(category + ".toggleMagnet", Keyboard.KEY_Z, category); public static KeyBinding hudKey = new KeyBinding(category + ".toggleHUD", Keyboard.KEY_V, category); public static KeyBinding dashKey = new KeyBinding(category + ".dash", Keyboard.KEY_LSHIFT, category); public static KeyBinding trainKey = new KeyBinding(category + ".trainInv", Keyboard.KEY_R, category); @@ -43,6 +44,7 @@ public class HbmKeybinds { public static void register() { ClientRegistry.registerKeyBinding(calculatorKey); ClientRegistry.registerKeyBinding(jetpackKey); + ClientRegistry.registerKeyBinding(magnetKey); ClientRegistry.registerKeyBinding(hudKey); ClientRegistry.registerKeyBinding(dashKey); ClientRegistry.registerKeyBinding(trainKey); @@ -98,6 +100,7 @@ public class HbmKeybinds { public static enum EnumKeybind { JETPACK, TOGGLE_JETPACK, + TOGGLE_MAGNET, TOGGLE_HEAD, DASH, TRAIN, diff --git a/src/main/java/com/hbm/items/armor/ItemModLodestone.java b/src/main/java/com/hbm/items/armor/ItemModLodestone.java index 9939244b7..f89e6c508 100644 --- a/src/main/java/com/hbm/items/armor/ItemModLodestone.java +++ b/src/main/java/com/hbm/items/armor/ItemModLodestone.java @@ -2,6 +2,7 @@ package com.hbm.items.armor; import java.util.List; +import com.hbm.extprop.HbmPlayerProps; import com.hbm.handler.ArmorModHandler; import net.minecraft.entity.EntityLivingBase; @@ -36,7 +37,10 @@ public class ItemModLodestone extends ItemArmorMod { @Override public void modUpdate(EntityLivingBase entity, ItemStack armor) { - + + // No magnet if keybind toggled + if (entity instanceof EntityPlayer && !HbmPlayerProps.getData((EntityPlayer) entity).isMagnetActive()) return; + List items = entity.worldObj.getEntitiesWithinAABB(EntityItem.class, entity.boundingBox.expand(range, range, range)); for(EntityItem item : items) { diff --git a/src/main/java/com/hbm/main/ClientProxy.java b/src/main/java/com/hbm/main/ClientProxy.java index 3a4db1cdd..6928ba30b 100644 --- a/src/main/java/com/hbm/main/ClientProxy.java +++ b/src/main/java/com/hbm/main/ClientProxy.java @@ -2038,6 +2038,7 @@ public class ClientProxy extends ServerProxy { switch(key){ case JETPACK: return Minecraft.getMinecraft().gameSettings.keyBindJump.getIsKeyPressed(); case TOGGLE_JETPACK: return HbmKeybinds.jetpackKey.getIsKeyPressed(); + case TOGGLE_MAGNET: return HbmKeybinds.magnetKey.getIsKeyPressed(); case TOGGLE_HEAD: return HbmKeybinds.hudKey.getIsKeyPressed(); case RELOAD: return HbmKeybinds.reloadKey.getIsKeyPressed(); case DASH: return HbmKeybinds.dashKey.getIsKeyPressed(); diff --git a/src/main/java/com/hbm/main/ServerProxy.java b/src/main/java/com/hbm/main/ServerProxy.java index 19b9723ce..98f09fbb7 100644 --- a/src/main/java/com/hbm/main/ServerProxy.java +++ b/src/main/java/com/hbm/main/ServerProxy.java @@ -21,12 +21,13 @@ public class ServerProxy { public static final int ID_CABLE = 3; public static final int ID_DRONE = 4; public static final int ID_JETPACK = 5; - public static final int ID_HUD = 6; - public static final int ID_DETONATOR = 7; - public static final int ID_FLUID_ID = 8; - public static final int ID_TOOLABILITY = 9; - public static final int ID_GUN_MODE = 10; - public static final int ID_GAS_HAZARD = 11; + public static final int ID_MAGNET = 6; + public static final int ID_HUD = 7; + public static final int ID_DETONATOR = 8; + public static final int ID_FLUID_ID = 9; + public static final int ID_TOOLABILITY = 10; + public static final int ID_GUN_MODE = 11; + public static final int ID_GAS_HAZARD = 12; public void registerPreRenderInfo() { } public void registerRenderInfo() { } diff --git a/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java b/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java index 4db727ba5..ecb027e11 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java +++ b/src/main/java/com/hbm/render/tileentity/RenderPylonBase.java @@ -14,7 +14,7 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; public abstract class RenderPylonBase extends TileEntitySpecialRenderer { - + /** * The closest we have to a does-all solution. It will figure out if it needs to draw multiple lines, * iterate through all the mounting points, try to find the matching mounting points and then draw the lines. @@ -24,27 +24,25 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { * @param z */ public void renderLinesGeneric(TileEntityPylonBase pyl, double x, double y, double z) { - - this.bindTexture(pyl.color == 0 ? ResourceManager.wire_tex : ResourceManager.wire_greyscale_tex); - - for(int i = 0; i < pyl.connected.size(); i++) { - int[] wire = pyl.connected.get(i); + this.bindTexture(pyl.color == 0 ? ResourceManager.wire_tex : ResourceManager.wire_greyscale_tex); + + pyl.getConnected().forEach(wire -> { TileEntity tile = pyl.getWorldObj().getTileEntity(wire[0], wire[1], wire[2]); - + if(tile instanceof TileEntityPylonBase) { TileEntityPylonBase pylon = (TileEntityPylonBase) tile; - + Vec3[] m1 = pyl.getMountPos(); Vec3[] m2 = pylon.getMountPos(); - + int lineCount = Math.min(m1.length, m2.length); - + for(int line = 0; line < lineCount; line++) { Vec3 first = m1[line % m1.length]; int secondIndex = line % m2.length; - + /* * hacky hacky hack * this will shift the mount point order by 2 to prevent wires from crossing @@ -55,17 +53,17 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { if(lineCount == 4 && ( (pyl.getBlockMetadata() - 10 == 5 && pylon.getBlockMetadata() - 10 == 2) || (pyl.getBlockMetadata() - 10 == 2 && pylon.getBlockMetadata() - 10 == 5))) { - + secondIndex += 2; secondIndex %= m2.length; } - + Vec3 second = m2[secondIndex]; - + double sX = second.xCoord + pylon.xCoord - pyl.xCoord; double sY = second.yCoord + pylon.yCoord - pyl.yCoord; double sZ = second.zCoord + pylon.zCoord - pyl.zCoord; - + renderLine(pyl.getWorldObj(), pyl, x, y, z, first.xCoord, first.yCoord, @@ -75,9 +73,9 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { first.zCoord + (sZ - first.zCoord) * 0.5); } } - } + }); } - + /** * Renders half a line * First coords: the relative render position @@ -101,12 +99,12 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { GL11.glTranslated(x, y, z); float count = 10; Tessellator tess = Tessellator.instance; - + GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_CULL_FACE); tess.startDrawingQuads(); Vec3 delta = Vec3.createVectorHelper(x0 - x1, y0 - y1, z0 - z1); - + double girth = 0.03125D; double hyp = Math.sqrt(delta.xCoord * delta.xCoord + delta.zCoord * delta.zCoord); double yaw = Math.atan2(delta.xCoord, delta.zCoord); @@ -124,31 +122,31 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { tess.setColorOpaque_I(pyl.color == 0 ? 0xffffff : pyl.color); drawLineSegment(tess, x0, y0, z0, x1, y1, z1, iX, iY, iZ, jX, jZ); } else { - + double hang = Math.min(delta.lengthVector() / 15D, 2.5D); - + for(float j = 0; j < count; j++) { - + float k = j + 1; - + double sagJ = Math.sin(j / count * Math.PI * 0.5) * hang; double sagK = Math.sin(k / count * Math.PI * 0.5) * hang; double sagMean = (sagJ + sagK) / 2D; - + double deltaX = x1 - x0; double deltaY = y1 - y0; double deltaZ = z1 - z0; - + double ja = j + 0.5D; double ix = pyl.xCoord + x0 + deltaX / (double)(count) * ja; double iy = pyl.yCoord + y0 + deltaY / (double)(count) * ja - sagMean; double iz = pyl.zCoord + z0 + deltaZ / (double)(count) * ja; - + int brightness = world.getLightBrightnessForSkyBlocks(MathHelper.floor_double(ix), MathHelper.floor_double(iy), MathHelper.floor_double(iz), 0); tess.setBrightness(brightness); - + tess.setColorOpaque_I(pyl.color == 0 ? 0xffffff : pyl.color); - + drawLineSegment(tess, x0 + (deltaX * j / count), y0 + (deltaY * j / count) - sagJ, @@ -162,10 +160,10 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { tess.draw(); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_CULL_FACE); - + GL11.glPopMatrix(); } - + /** * Draws a single segment from the first to the second 3D coordinate. * Not fantastic but it looks good enough. @@ -178,19 +176,19 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { * @param c */ public void drawLineSegment(Tessellator tessellator, double x, double y, double z, double a, double b, double c, double iX, double iY, double iZ, double jX, double jZ) { - + double deltaX = a - x; double deltaY = b - y; double deltaZ = c - z; double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); int wrap = (int) Math.ceil(length * 8); - + if(deltaX + deltaZ < 0) { wrap *= -1; jZ *= -1; jX *= -1; } - + tessellator.addVertexWithUV(x + iX, y + iY, z + iZ, 0, 0); tessellator.addVertexWithUV(x - iX, y - iY, z - iZ, 0, 1); tessellator.addVertexWithUV(a - iX, b - iY, c - iZ, wrap, 1); @@ -200,6 +198,6 @@ public abstract class RenderPylonBase extends TileEntitySpecialRenderer { tessellator.addVertexWithUV(a - jX, b, c - jZ, wrap, 1); tessellator.addVertexWithUV(a + jX, b, c + jZ, wrap, 0); } - + public static final int LINE_COLOR = 0xBB3311; } diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java b/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java index 7581ddaed..f3041922b 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityPylonBase.java @@ -23,45 +23,45 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.ForgeDirection; public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { - - public List connected = new ArrayList(); + + protected List connected = new ArrayList<>(); public int color; - + public static int canConnect(TileEntityPylonBase first, TileEntityPylonBase second) { - + if(first.getConnectionType() != second.getConnectionType()) return 1; - + if(first == second) return 2; - + double len = Math.min(first.getMaxWireLength(), second.getMaxWireLength()); - + Vec3 firstPos = first.getConnectionPoint(); Vec3 secondPos = second.getConnectionPoint(); - + Vec3 delta = Vec3.createVectorHelper( (secondPos.xCoord) - (firstPos.xCoord), (secondPos.yCoord) - (firstPos.yCoord), (secondPos.zCoord) - (firstPos.zCoord) ); - + return len >= delta.lengthVector() ? 0 : 3; } - + public boolean setColor(ItemStack stack) { if(stack == null) return false; int color = ColorUtil.getColorFromDye(stack); if(color == 0 || color == this.color) return false; stack.stackSize--; this.color = color; - + this.markDirty(); if(worldObj instanceof WorldServer) { WorldServer world = (WorldServer) worldObj; world.getPlayerManager().markBlockForUpdate(xCoord, yCoord, zCoord); } - + return true; } @@ -72,91 +72,95 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { for(int[] pos : this.connected) node.addConnection(new DirPos(pos[0], pos[1], pos[2], ForgeDirection.UNKNOWN)); return node; } - + public void addConnection(int x, int y, int z) { - + connected.add(new int[] {x, y, z}); - + PowerNode node = Nodespace.getNode(worldObj, xCoord, yCoord, zCoord); node.recentlyChanged = true; node.addConnection(new DirPos(x, y, z, ForgeDirection.UNKNOWN)); - + this.markDirty(); - + if(worldObj instanceof WorldServer) { WorldServer world = (WorldServer) worldObj; world.getPlayerManager().markBlockForUpdate(xCoord, yCoord, zCoord); } } - + public void disconnectAll() { - + for(int[] pos : connected) { - + TileEntity te = worldObj.getTileEntity(pos[0], pos[1], pos[2]); - + if(te == this) continue; - + if(te instanceof TileEntityPylonBase) { TileEntityPylonBase pylon = (TileEntityPylonBase) te; Nodespace.destroyNode(worldObj, pos[0], pos[1], pos[2]); - + for(int i = 0; i < pylon.connected.size(); i++) { int[] conPos = pylon.connected.get(i); - + if(conPos[0] == xCoord && conPos[1] == yCoord && conPos[2] == zCoord) { pylon.connected.remove(i); i--; } } - + pylon.markDirty(); - + if(worldObj instanceof WorldServer) { WorldServer world = (WorldServer) worldObj; world.getPlayerManager().markBlockForUpdate(pylon.xCoord, pylon.yCoord, pylon.zCoord); } } } - + Nodespace.destroyNode(worldObj, xCoord, yCoord, zCoord); } - + public abstract ConnectionType getConnectionType(); public abstract Vec3[] getMountPos(); public abstract double getMaxWireLength(); - + public Vec3 getConnectionPoint() { Vec3[] mounts = this.getMountPos(); - + if(mounts == null || mounts.length == 0) return Vec3.createVectorHelper(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - + return mounts[0].addVector(xCoord, yCoord, zCoord); } - + + public List getConnected() { + return connected; + } + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setInteger("conCount", connected.size()); nbt.setInteger("color", color); - + for(int i = 0; i < connected.size(); i++) { nbt.setIntArray("con" + i, connected.get(i)); } } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - + int count = nbt.getInteger("conCount"); this.color = nbt.getInteger("color"); - + this.connected.clear(); - + for(int i = 0; i < count; i++) { connected.add(nbt.getIntArray("con" + i)); } @@ -164,24 +168,24 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT { @Override public Packet getDescriptionPacket() { - + NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt); } - + @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); } - public static enum ConnectionType { + public enum ConnectionType { SINGLE, TRIPLE, QUAD //more to follow } - + @Override public AxisAlignedBB getRenderBoundingBox() { return TileEntity.INFINITE_EXTENT_AABB;