diff options
author | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2019-01-13 06:12:39 +0100 |
---|---|---|
committer | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2019-01-13 06:12:39 +0100 |
commit | 2c1f93533419864702f3b79fd5a9add19cf2da3d (patch) | |
tree | ffb67da1545509b0773b35661e5172fb25208366 /src | |
parent | 7bd4d6d96453229b436cbdfb78b877563a1e12df (diff) | |
download | GT5-Unofficial-2c1f93533419864702f3b79fd5a9add19cf2da3d.tar.gz GT5-Unofficial-2c1f93533419864702f3b79fd5a9add19cf2da3d.tar.bz2 GT5-Unofficial-2c1f93533419864702f3b79fd5a9add19cf2da3d.zip |
fixes
+fixes circuit programmer consuming circuit when closed on servers
+fixes BioLab gui not loading
+reformat code
+version increase
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java | 2 | ||||
-rw-r--r-- | src/main/java/com/github/bartimaeusnek/bartworks/common/net/CircuitProgrammerPacket.java | 91 | ||||
-rw-r--r-- | src/main/java/com/github/bartimaeusnek/bartworks/server/container/GT_Container_CircuitProgrammer.java | 30 | ||||
-rw-r--r-- | src/main/java/com/github/bartimaeusnek/bartworks/util/Coords.java | 32 | ||||
-rw-r--r-- | src/main/java/com/github/bartimaeusnek/bartworks/util/MurmurHash3.java | 556 | ||||
-rw-r--r-- | src/main/resources/assets/gregtech/textures/gui/basicmachines/BW.GUI.BioLab.png (renamed from src/main/resources/assets/gregtech/textures/GUI/basicmachines/BW.GUI.BioLab.png) | bin | 3151 -> 3151 bytes |
6 files changed, 428 insertions, 283 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java index af2a08d3e8..9629eec1c9 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java @@ -59,7 +59,7 @@ public class BW_Network extends MessageToMessageCodec<FMLProxyPacket, GT_Packet> public BW_Network() { this.mChannel = NetworkRegistry.INSTANCE.newChannel("BartWorks", new ChannelHandler[]{this, new HandlerShared()}); - this.mSubChannels = new GT_Packet[]{new RendererPacket()}; + this.mSubChannels = new GT_Packet[]{new RendererPacket(), new CircuitProgrammerPacket()}; } protected void encode(ChannelHandlerContext aContext, GT_Packet aPacket, List<Object> aOutput) throws Exception { diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/CircuitProgrammerPacket.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/CircuitProgrammerPacket.java new file mode 100644 index 0000000000..23cf7a263f --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/CircuitProgrammerPacket.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019 bartimaeusnek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.bartimaeusnek.bartworks.common.net; + +import com.github.bartimaeusnek.bartworks.common.items.Circuit_Programmer; +import com.google.common.io.ByteArrayDataInput; +import gregtech.api.net.GT_Packet; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; + +import java.nio.ByteBuffer; + +public class CircuitProgrammerPacket extends GT_Packet { + + private int dimID, playerID; + private byte chipCfg; + private boolean hasChip; + + public CircuitProgrammerPacket() { + super(true); + } + + public CircuitProgrammerPacket(int dimID, int playerID, boolean hasChip, byte chipCfg) { + super(false); + this.dimID = dimID; + this.playerID = playerID; + this.hasChip = hasChip; + this.chipCfg = chipCfg; + } + + @Override + public byte getPacketID() { + return 1; + } + + @Override + public byte[] encode() { + return ByteBuffer.allocate(9).putInt(0, dimID).putInt(4, playerID).put(8, (hasChip ? chipCfg : -1)).array(); + } + + @Override + public GT_Packet decode(ByteArrayDataInput byteArrayDataInput) { + byte[] ret = new byte[9]; + byteArrayDataInput.readFully(ret); + return new CircuitProgrammerPacket(ByteBuffer.wrap(ret).getInt(0), ByteBuffer.wrap(ret).getInt(4), ByteBuffer.wrap(ret).get(8) > -1, ByteBuffer.wrap(ret).get(8)); + } + + @Override + public void process(IBlockAccess iBlockAccess) { + World w = DimensionManager.getWorld(dimID); + if (w != null && w.getEntityByID(playerID) instanceof EntityPlayer) { + ItemStack stack = ((EntityPlayer) w.getEntityByID(playerID)).getHeldItem(); + if ((stack != null) && (stack.stackSize > 0)) { + Item item = stack.getItem(); + if (item instanceof Circuit_Programmer) { + NBTTagCompound nbt = stack.getTagCompound(); + nbt.setBoolean("HasChip", hasChip); + if (hasChip) + nbt.setByte("ChipConfig", chipCfg); + stack.setTagCompound(nbt); + ((EntityPlayer) w.getEntityByID(playerID)).inventory.setInventorySlotContents(((EntityPlayer) w.getEntityByID(playerID)).inventory.currentItem, stack); + } + } + } + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/server/container/GT_Container_CircuitProgrammer.java b/src/main/java/com/github/bartimaeusnek/bartworks/server/container/GT_Container_CircuitProgrammer.java index f52d3e8b63..53c009e973 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/server/container/GT_Container_CircuitProgrammer.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/server/container/GT_Container_CircuitProgrammer.java @@ -22,6 +22,8 @@ package com.github.bartimaeusnek.bartworks.server.container; +import com.github.bartimaeusnek.bartworks.MainMod; +import com.github.bartimaeusnek.bartworks.common.net.CircuitProgrammerPacket; import com.github.bartimaeusnek.bartworks.util.BW_Util; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; @@ -39,9 +41,13 @@ import net.minecraftforge.common.ForgeHooks; public class GT_Container_CircuitProgrammer extends Container { + EntityPlayer player; + public GT_Container_CircuitProgrammer(InventoryPlayer inventory) { - IInventory inv = new pinv(inventory.player); + player = inventory.player; + + IInventory inv = new pinv(player); addSlotToContainer(new Slot(inv, 0, 44, 61));//-45, 84)); @@ -66,10 +72,11 @@ public class GT_Container_CircuitProgrammer extends Container { @Override public ItemStack slotClick(int slot, int button, int aShifthold, EntityPlayer entityPlayer) { if (slot > 0 && slot < 25 && ((Slot) this.inventorySlots.get(0)).getStack() != null) { - ((Slot) this.inventorySlots.get(0)).getStack().setItemDamage(slot); + ((Slot) this.inventorySlots.get(0)).putStack(GT_Utility.getIntegratedCircuit(slot)); detectAndSendChanges(); return ((Slot) this.inventorySlots.get(0)).getStack(); } + detectAndSendChanges(); return super.slotClick(slot, button, aShifthold, entityPlayer);//( (Slot) this.inventorySlots.get(slot)).getStack(); } @@ -83,7 +90,7 @@ public class GT_Container_CircuitProgrammer extends Container { Slot chipslot = (Slot) this.inventorySlots.get(0); if (SlotNR > 24) { Slot slot = (Slot) this.inventorySlots.get(SlotNR); - if (slot != null && slot.getStack() != null && slot.getStack().getItem().equals(GT_Utility.getIntegratedCircuit(0).getItem())) { + if (slot != null && slot.getStack() != null && slot.getStack().getItem().equals(GT_Utility.getIntegratedCircuit(0).getItem())) { if (chipslot.getStack() == null) { chipslot.putStack(slot.getStack()); slot.decrStackSize(1); @@ -99,6 +106,7 @@ public class GT_Container_CircuitProgrammer extends Container { } } } + detectAndSendChanges(); return null; } @@ -114,8 +122,9 @@ public class GT_Container_CircuitProgrammer extends Container { this.Player = Player; this.toBind = Player.inventory.getCurrentItem(); tag = this.toBind.getTagCompound(); - if (tag.getBoolean("HasChip")) + if (tag.getBoolean("HasChip")) { Slot = GT_Utility.getIntegratedCircuit(tag.getByte("ChipConfig")); + } } @Override @@ -154,19 +163,29 @@ public class GT_Container_CircuitProgrammer extends Container { tag.setByte("ChipConfig", (byte) itemStack.getItemDamage()); toBind.setTagCompound(tag); Player.inventory.setInventorySlotContents(Player.inventory.currentItem, toBind); + if (!Player.isClientWorld()) + MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(Player.worldObj.provider.dimensionId, Player.getEntityId(), true, (byte) itemStack.getItemDamage())); + } else if (BW_Util.checkStackAndPrefix(itemStack) && GT_OreDictUnificator.getAssociation(itemStack).mPrefix.equals(OrePrefixes.circuit) && GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial.equals(Materials.Basic)) { Slot = GT_Utility.getIntegratedCircuit(0); itemStack.stackSize--; tag = toBind.getTagCompound(); tag.setBoolean("HasChip", true); - tag.setByte("ChipConfig", (byte) itemStack.getItemDamage()); + tag.setByte("ChipConfig", (byte) 0); toBind.setTagCompound(tag); Player.inventory.setInventorySlotContents(Player.inventory.currentItem, toBind); + if (!Player.isClientWorld()) + MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(Player.worldObj.provider.dimensionId, Player.getEntityId(), true, (byte) 0)); + } else { ForgeHooks.onPlayerTossEvent(Player, itemStack, false); tag = toBind.getTagCompound(); tag.setBoolean("HasChip", false); toBind.setTagCompound(tag); + Player.inventory.setInventorySlotContents(Player.inventory.currentItem, toBind); + if (!Player.isClientWorld()) + MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(Player.worldObj.provider.dimensionId, Player.getEntityId(), false, (byte) 0)); + } } @@ -203,6 +222,7 @@ public class GT_Container_CircuitProgrammer extends Container { @Override public void closeInventory() { + } @Override diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/Coords.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/Coords.java index 756f6ed7dc..f285b7b6e2 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/util/Coords.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/Coords.java @@ -22,8 +22,6 @@ package com.github.bartimaeusnek.bartworks.util; -import java.util.Objects; - public class Coords { public int x, z, wID; @@ -57,21 +55,21 @@ public class Coords { @Override public int hashCode() { byte[] data = new byte[14]; - data[0]= (byte) (this.x & 0b1111); - data[1]= (byte) (this.x >> 4 & 0b1111); - data[2]= (byte) (this.x >> 8 & 0b1111); - data[3]= (byte) (this.x >> 12 & 0b1111); - data[4]= (byte) (this.y & 0b1111); - data[5]= (byte) (this.y >> 4 & 0b1111); - data[6]= (byte) (this.z & 0b1111); - data[7]= (byte) (this.z >> 4 & 0b1111); - data[8]= (byte) (this.z >> 8 & 0b1111); - data[9]= (byte) (this.z >> 12 & 0b1111); - data[10]= (byte) (this.wID & 0b1111); - data[11]= (byte) (this.wID >> 4 & 0b1111); - data[12]= (byte) (this.wID >> 8 & 0b1111); - data[13]= (byte) (this.wID >> 12 & 0b1111); - return MurmurHash3.murmurhash3_x86_32(data,0,14,31); + data[0] = (byte) (this.x & 0b1111); + data[1] = (byte) (this.x >> 4 & 0b1111); + data[2] = (byte) (this.x >> 8 & 0b1111); + data[3] = (byte) (this.x >> 12 & 0b1111); + data[4] = (byte) (this.y & 0b1111); + data[5] = (byte) (this.y >> 4 & 0b1111); + data[6] = (byte) (this.z & 0b1111); + data[7] = (byte) (this.z >> 4 & 0b1111); + data[8] = (byte) (this.z >> 8 & 0b1111); + data[9] = (byte) (this.z >> 12 & 0b1111); + data[10] = (byte) (this.wID & 0b1111); + data[11] = (byte) (this.wID >> 4 & 0b1111); + data[12] = (byte) (this.wID >> 8 & 0b1111); + data[13] = (byte) (this.wID >> 12 & 0b1111); + return MurmurHash3.murmurhash3_x86_32(data, 0, 14, 31); } @Override diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/MurmurHash3.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/MurmurHash3.java index d0433145c7..cbb10fa312 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/util/MurmurHash3.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/MurmurHash3.java @@ -23,281 +23,317 @@ package com.github.bartimaeusnek.bartworks.util; public final class MurmurHash3 { - /** 128 bits of state */ - public static final class LongPair { - public long val1; - public long val2; - } - - public static final int fmix32(int h) { - h ^= h >>> 16; - h *= 0x85ebca6b; - h ^= h >>> 13; - h *= 0xc2b2ae35; - h ^= h >>> 16; - return h; - } - - public static final long fmix64(long k) { - k ^= k >>> 33; - k *= 0xff51afd7ed558ccdL; - k ^= k >>> 33; - k *= 0xc4ceb9fe1a85ec53L; - k ^= k >>> 33; - return k; - } - - /** Gets a long from a byte buffer in little endian byte order. */ - public static final long getLongLittleEndian(byte[] buf, int offset) { - return ((long)buf[offset+7] << 56) // no mask needed - | ((buf[offset+6] & 0xffL) << 48) - | ((buf[offset+5] & 0xffL) << 40) - | ((buf[offset+4] & 0xffL) << 32) - | ((buf[offset+3] & 0xffL) << 24) - | ((buf[offset+2] & 0xffL) << 16) - | ((buf[offset+1] & 0xffL) << 8) - | ((buf[offset ] & 0xffL)); // no shift needed - } - - - /** Returns the MurmurHash3_x86_32 hash. */ - public static int murmurhash3_x86_32(byte[] data, int offset, int len, int seed) { - - final int c1 = 0xcc9e2d51; - final int c2 = 0x1b873593; - - int h1 = seed; - int roundedEnd = offset + (len & 0xfffffffc); // round down to 4 byte block - - for (int i=offset; i<roundedEnd; i+=4) { - // little endian load order - int k1 = (data[i] & 0xff) | ((data[i+1] & 0xff) << 8) | ((data[i+2] & 0xff) << 16) | (data[i+3] << 24); - k1 *= c1; - k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); - k1 *= c2; - - h1 ^= k1; - h1 = (h1 << 13) | (h1 >>> 19); // ROTL32(h1,13); - h1 = h1*5+0xe6546b64; + public static final int fmix32(int h) { + h ^= h >>> 16; + h *= 0x85ebca6b; + h ^= h >>> 13; + h *= 0xc2b2ae35; + h ^= h >>> 16; + return h; } - // tail - int k1 = 0; - - switch(len & 0x03) { - case 3: - k1 = (data[roundedEnd + 2] & 0xff) << 16; - // fallthrough - case 2: - k1 |= (data[roundedEnd + 1] & 0xff) << 8; - // fallthrough - case 1: - k1 |= (data[roundedEnd] & 0xff); - k1 *= c1; - k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); - k1 *= c2; - h1 ^= k1; + public static final long fmix64(long k) { + k ^= k >>> 33; + k *= 0xff51afd7ed558ccdL; + k ^= k >>> 33; + k *= 0xc4ceb9fe1a85ec53L; + k ^= k >>> 33; + return k; } - // finalization - h1 ^= len; - - // fmix(h1); - h1 ^= h1 >>> 16; - h1 *= 0x85ebca6b; - h1 ^= h1 >>> 13; - h1 *= 0xc2b2ae35; - h1 ^= h1 >>> 16; - - return h1; - } - - - /** Returns the MurmurHash3_x86_32 hash of the UTF-8 bytes of the String without actually encoding - * the string to a temporary buffer. This is more than 2x faster than hashing the result - * of String.getBytes(). - */ - public static int murmurhash3_x86_32(CharSequence data, int offset, int len, int seed) { - - final int c1 = 0xcc9e2d51; - final int c2 = 0x1b873593; - - int h1 = seed; - - int pos = offset; - int end = offset + len; - int k1 = 0; - int k2 = 0; - int shift = 0; - int bits = 0; - int nBytes = 0; // length in UTF8 bytes - - - while (pos < end) { - int code = data.charAt(pos++); - if (code < 0x80) { - k2 = code; - bits = 8; - - /*** - // optimized ascii implementation (currently slower!!! code size?) - if (shift == 24) { - k1 = k1 | (code << 24); - - k1 *= c1; - k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); - k1 *= c2; - - h1 ^= k1; - h1 = (h1 << 13) | (h1 >>> 19); // ROTL32(h1,13); - h1 = h1*5+0xe6546b64; - - shift = 0; - nBytes += 4; - k1 = 0; - } else { - k1 |= code << shift; - shift += 8; + /** + * Gets a long from a byte buffer in little endian byte order. + */ + public static final long getLongLittleEndian(byte[] buf, int offset) { + return ((long) buf[offset + 7] << 56) // no mask needed + | ((buf[offset + 6] & 0xffL) << 48) + | ((buf[offset + 5] & 0xffL) << 40) + | ((buf[offset + 4] & 0xffL) << 32) + | ((buf[offset + 3] & 0xffL) << 24) + | ((buf[offset + 2] & 0xffL) << 16) + | ((buf[offset + 1] & 0xffL) << 8) + | ((buf[offset] & 0xffL)); // no shift needed + } + + /** + * Returns the MurmurHash3_x86_32 hash. + */ + public static int murmurhash3_x86_32(byte[] data, int offset, int len, int seed) { + + final int c1 = 0xcc9e2d51; + final int c2 = 0x1b873593; + + int h1 = seed; + int roundedEnd = offset + (len & 0xfffffffc); // round down to 4 byte block + + for (int i = offset; i < roundedEnd; i += 4) { + // little endian load order + int k1 = (data[i] & 0xff) | ((data[i + 1] & 0xff) << 8) | ((data[i + 2] & 0xff) << 16) | (data[i + 3] << 24); + k1 *= c1; + k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); + k1 *= c2; + + h1 ^= k1; + h1 = (h1 << 13) | (h1 >>> 19); // ROTL32(h1,13); + h1 = h1 * 5 + 0xe6546b64; } - continue; - ***/ - - } - else if (code < 0x800) { - k2 = (0xC0 | (code >> 6)) - | ((0x80 | (code & 0x3F)) << 8); - bits = 16; - } - else if (code < 0xD800 || code > 0xDFFF || pos>=end) { - // we check for pos>=end to encode an unpaired surrogate as 3 bytes. - k2 = (0xE0 | (code >> 12)) - | ((0x80 | ((code >> 6) & 0x3F)) << 8) - | ((0x80 | (code & 0x3F)) << 16); - bits = 24; - } else { - // surrogate pair - // int utf32 = pos < end ? (int) data.charAt(pos++) : 0; - int utf32 = (int) data.charAt(pos++); - utf32 = ((code - 0xD7C0) << 10) + (utf32 & 0x3FF); - k2 = (0xff & (0xF0 | (utf32 >> 18))) - | ((0x80 | ((utf32 >> 12) & 0x3F))) << 8 - | ((0x80 | ((utf32 >> 6) & 0x3F))) << 16 - | (0x80 | (utf32 & 0x3F)) << 24; - bits = 32; - } - - - k1 |= k2 << shift; - - // int used_bits = 32 - shift; // how many bits of k2 were used in k1. - // int unused_bits = bits - used_bits; // (bits-(32-shift)) == bits+shift-32 == bits-newshift - - shift += bits; - if (shift >= 32) { - // mix after we have a complete word - - k1 *= c1; - k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); - k1 *= c2; - - h1 ^= k1; - h1 = (h1 << 13) | (h1 >>> 19); // ROTL32(h1,13); - h1 = h1*5+0xe6546b64; - - shift -= 32; - // unfortunately, java won't let you shift 32 bits off, so we need to check for 0 - if (shift != 0) { - k1 = k2 >>> (bits-shift); // bits used == bits - newshift - } else { - k1 = 0; + + // tail + int k1 = 0; + + switch (len & 0x03) { + case 3: + k1 = (data[roundedEnd + 2] & 0xff) << 16; + // fallthrough + case 2: + k1 |= (data[roundedEnd + 1] & 0xff) << 8; + // fallthrough + case 1: + k1 |= (data[roundedEnd] & 0xff); + k1 *= c1; + k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); + k1 *= c2; + h1 ^= k1; } - nBytes += 4; - } - - } // inner - - // handle tail - if (shift > 0) { - nBytes += shift >> 3; - k1 *= c1; - k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); - k1 *= c2; - h1 ^= k1; - } - // finalization - h1 ^= nBytes; - - // fmix(h1); - h1 ^= h1 >>> 16; - h1 *= 0x85ebca6b; - h1 ^= h1 >>> 13; - h1 *= 0xc2b2ae35; - h1 ^= h1 >>> 16; - - return h1; - } - - - /** Returns the MurmurHash3_x64_128 hash, placing the result in "out". */ - public static void murmurhash3_x64_128(byte[] key, int offset, int len, int seed, LongPair out) { - // The original algorithm does have a 32 bit unsigned seed. - // We have to mask to match the behavior of the unsigned types and prevent sign extension. - long h1 = seed & 0x00000000FFFFFFFFL; - long h2 = seed & 0x00000000FFFFFFFFL; - - final long c1 = 0x87c37b91114253d5L; - final long c2 = 0x4cf5ad432745937fL; - - int roundedEnd = offset + (len & 0xFFFFFFF0); // round down to 16 byte block - for (int i=offset; i<roundedEnd; i+=16) { - long k1 = getLongLittleEndian(key, i); - long k2 = getLongLittleEndian(key, i+8); - k1 *= c1; k1 = Long.rotateLeft(k1,31); k1 *= c2; h1 ^= k1; - h1 = Long.rotateLeft(h1,27); h1 += h2; h1 = h1*5+0x52dce729; - k2 *= c2; k2 = Long.rotateLeft(k2,33); k2 *= c1; h2 ^= k2; - h2 = Long.rotateLeft(h2,31); h2 += h1; h2 = h2*5+0x38495ab5; + // finalization + h1 ^= len; + + // fmix(h1); + h1 ^= h1 >>> 16; + h1 *= 0x85ebca6b; + h1 ^= h1 >>> 13; + h1 *= 0xc2b2ae35; + h1 ^= h1 >>> 16; + + return h1; } - long k1 = 0; - long k2 = 0; - - switch (len & 15) { - case 15: k2 = (key[roundedEnd+14] & 0xffL) << 48; - case 14: k2 |= (key[roundedEnd+13] & 0xffL) << 40; - case 13: k2 |= (key[roundedEnd+12] & 0xffL) << 32; - case 12: k2 |= (key[roundedEnd+11] & 0xffL) << 24; - case 11: k2 |= (key[roundedEnd+10] & 0xffL) << 16; - case 10: k2 |= (key[roundedEnd+ 9] & 0xffL) << 8; - case 9: k2 |= (key[roundedEnd+ 8] & 0xffL); - k2 *= c2; k2 = Long.rotateLeft(k2, 33); k2 *= c1; h2 ^= k2; - case 8: k1 = ((long)key[roundedEnd+7]) << 56; - case 7: k1 |= (key[roundedEnd+6] & 0xffL) << 48; - case 6: k1 |= (key[roundedEnd+5] & 0xffL) << 40; - case 5: k1 |= (key[roundedEnd+4] & 0xffL) << 32; - case 4: k1 |= (key[roundedEnd+3] & 0xffL) << 24; - case 3: k1 |= (key[roundedEnd+2] & 0xffL) << 16; - case 2: k1 |= (key[roundedEnd+1] & 0xffL) << 8; - case 1: k1 |= (key[roundedEnd ] & 0xffL); - k1 *= c1; k1 = Long.rotateLeft(k1,31); k1 *= c2; h1 ^= k1; + /** + * Returns the MurmurHash3_x86_32 hash of the UTF-8 bytes of the String without actually encoding + * the string to a temporary buffer. This is more than 2x faster than hashing the result + * of String.getBytes(). + */ + public static int murmurhash3_x86_32(CharSequence data, int offset, int len, int seed) { + + final int c1 = 0xcc9e2d51; + final int c2 = 0x1b873593; + + int h1 = seed; + + int pos = offset; + int end = offset + len; + int k1 = 0; + int k2 = 0; + int shift = 0; + int bits = 0; + int nBytes = 0; // length in UTF8 bytes + + + while (pos < end) { + int code = data.charAt(pos++); + if (code < 0x80) { + k2 = code; + bits = 8; + + /*** + // optimized ascii implementation (currently slower!!! code size?) + if (shift == 24) { + k1 = k1 | (code << 24); + + k1 *= c1; + k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); + k1 *= c2; + + h1 ^= k1; + h1 = (h1 << 13) | (h1 >>> 19); // ROTL32(h1,13); + h1 = h1*5+0xe6546b64; + + shift = 0; + nBytes += 4; + k1 = 0; + } else { + k1 |= code << shift; + shift += 8; + } + continue; + ***/ + + } else if (code < 0x800) { + k2 = (0xC0 | (code >> 6)) + | ((0x80 | (code & 0x3F)) << 8); + bits = 16; + } else if (code < 0xD800 || code > 0xDFFF || pos >= end) { + // we check for pos>=end to encode an unpaired surrogate as 3 bytes. + k2 = (0xE0 | (code >> 12)) + | ((0x80 | ((code >> 6) & 0x3F)) << 8) + | ((0x80 | (code & 0x3F)) << 16); + bits = 24; + } else { + // surrogate pair + // int utf32 = pos < end ? (int) data.charAt(pos++) : 0; + int utf32 = (int) data.charAt(pos++); + utf32 = ((code - 0xD7C0) << 10) + (utf32 & 0x3FF); + k2 = (0xff & (0xF0 | (utf32 >> 18))) + | ((0x80 | ((utf32 >> 12) & 0x3F))) << 8 + | ((0x80 | ((utf32 >> 6) & 0x3F))) << 16 + | (0x80 | (utf32 & 0x3F)) << 24; + bits = 32; + } + + + k1 |= k2 << shift; + + // int used_bits = 32 - shift; // how many bits of k2 were used in k1. + // int unused_bits = bits - used_bits; // (bits-(32-shift)) == bits+shift-32 == bits-newshift + + shift += bits; + if (shift >= 32) { + // mix after we have a complete word + + k1 *= c1; + k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); + k1 *= c2; + + h1 ^= k1; + h1 = (h1 << 13) | (h1 >>> 19); // ROTL32(h1,13); + h1 = h1 * 5 + 0xe6546b64; + + shift -= 32; + // unfortunately, java won't let you shift 32 bits off, so we need to check for 0 + if (shift != 0) { + k1 = k2 >>> (bits - shift); // bits used == bits - newshift + } else { + k1 = 0; + } + nBytes += 4; + } + + } // inner + + // handle tail + if (shift > 0) { + nBytes += shift >> 3; + k1 *= c1; + k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); + k1 *= c2; + h1 ^= k1; + } + + // finalization + h1 ^= nBytes; + + // fmix(h1); + h1 ^= h1 >>> 16; + h1 *= 0x85ebca6b; + h1 ^= h1 >>> 13; + h1 *= 0xc2b2ae35; + h1 ^= h1 >>> 16; + + return h1; } - //---------- - // finalization + /** + * Returns the MurmurHash3_x64_128 hash, placing the result in "out". + */ + public static void murmurhash3_x64_128(byte[] key, int offset, int len, int seed, LongPair out) { + // The original algorithm does have a 32 bit unsigned seed. + // We have to mask to match the behavior of the unsigned types and prevent sign extension. + long h1 = seed & 0x00000000FFFFFFFFL; + long h2 = seed & 0x00000000FFFFFFFFL; + + final long c1 = 0x87c37b91114253d5L; + final long c2 = 0x4cf5ad432745937fL; + + int roundedEnd = offset + (len & 0xFFFFFFF0); // round down to 16 byte block + for (int i = offset; i < roundedEnd; i += 16) { + long k1 = getLongLittleEndian(key, i); + long k2 = getLongLittleEndian(key, i + 8); + k1 *= c1; + k1 = Long.rotateLeft(k1, 31); + k1 *= c2; + h1 ^= k1; + h1 = Long.rotateLeft(h1, 27); + h1 += h2; + h1 = h1 * 5 + 0x52dce729; + k2 *= c2; + k2 = Long.rotateLeft(k2, 33); + k2 *= c1; + h2 ^= k2; + h2 = Long.rotateLeft(h2, 31); + h2 += h1; + h2 = h2 * 5 + 0x38495ab5; + } + + long k1 = 0; + long k2 = 0; + + switch (len & 15) { + case 15: + k2 = (key[roundedEnd + 14] & 0xffL) << 48; + case 14: + k2 |= (key[roundedEnd + 13] & 0xffL) << 40; + case 13: + k2 |= (key[roundedEnd + 12] & 0xffL) << 32; + case 12: + k2 |= (key[roundedEnd + 11] & 0xffL) << 24; + case 11: + k2 |= (key[roundedEnd + 10] & 0xffL) << 16; + case 10: + k2 |= (key[roundedEnd + 9] & 0xffL) << 8; + case 9: + k2 |= (key[roundedEnd + 8] & 0xffL); + k2 *= c2; + k2 = Long.rotateLeft(k2, 33); + k2 *= c1; + h2 ^= k2; + case 8: + k1 = ((long) key[roundedEnd + 7]) << 56; + case 7: + k1 |= (key[roundedEnd + 6] & 0xffL) << 48; + case 6: + k1 |= (key[roundedEnd + 5] & 0xffL) << 40; + case 5: + k1 |= (key[roundedEnd + 4] & 0xffL) << 32; + case 4: + k1 |= (key[roundedEnd + 3] & 0xffL) << 24; + case 3: + k1 |= (key[roundedEnd + 2] & 0xffL) << 16; + case 2: + k1 |= (key[roundedEnd + 1] & 0xffL) << 8; + case 1: + k1 |= (key[roundedEnd] & 0xffL); + k1 *= c1; + k1 = Long.rotateLeft(k1, 31); + k1 *= c2; + h1 ^= k1; + } + + //---------- + // finalization - h1 ^= len; h2 ^= len; + h1 ^= len; + h2 ^= len; - h1 += h2; - h2 += h1; + h1 += h2; + h2 += h1; - h1 = fmix64(h1); - h2 = fmix64(h2); + h1 = fmix64(h1); + h2 = fmix64(h2); - h1 += h2; - h2 += h1; + h1 += h2; + h2 += h1; - out.val1 = h1; - out.val2 = h2; - } + out.val1 = h1; + out.val2 = h2; + } + + /** + * 128 bits of state + */ + public static final class LongPair { + public long val1; + public long val2; + } } diff --git a/src/main/resources/assets/gregtech/textures/GUI/basicmachines/BW.GUI.BioLab.png b/src/main/resources/assets/gregtech/textures/gui/basicmachines/BW.GUI.BioLab.png Binary files differindex fb9c0e113c..fb9c0e113c 100644 --- a/src/main/resources/assets/gregtech/textures/GUI/basicmachines/BW.GUI.BioLab.png +++ b/src/main/resources/assets/gregtech/textures/gui/basicmachines/BW.GUI.BioLab.png |