diff options
author | basdxz <tudurap.com@gmail.com> | 2020-06-23 16:23:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 16:23:50 +0100 |
commit | ca0d8f6c57f22620934d049566218d0e71f3100f (patch) | |
tree | 617bdadac1ab6da04d8d96c64356ddc64758a3cc | |
parent | 2c0bbbb109aa0cc00193ad294e0aa794137bf9e1 (diff) | |
parent | 0afcd6ff4c62200307c409dd62b768c3015ead1d (diff) | |
download | GT5-Unofficial-ca0d8f6c57f22620934d049566218d0e71f3100f.tar.gz GT5-Unofficial-ca0d8f6c57f22620934d049566218d0e71f3100f.tar.bz2 GT5-Unofficial-ca0d8f6c57f22620934d049566218d0e71f3100f.zip |
Merge pull request #35 from bartimaeusnek/metablock
Added Support for MetaBlocks
3 files changed, 66 insertions, 27 deletions
diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/ICustomMetaBlock.java b/src/main/java/com/github/technus/tectech/mechanics/structure/ICustomMetaBlock.java new file mode 100644 index 0000000000..2c783ef268 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/ICustomMetaBlock.java @@ -0,0 +1,10 @@ +package com.github.technus.tectech.mechanics.structure; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +public interface ICustomMetaBlock { + default void setBlock(World world, int x, int y, int z, int meta){ + world.setBlock(x, y, z, (Block)this, meta, 2); + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java b/src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java index e7769b3e04..9e680b877e 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/Structure.java @@ -103,32 +103,34 @@ public class Structure { } break; default://check for block (countable) + Block worldblock = world.getBlock(xyz[0], xyz[1], xyz[2]); + int dmg = worldblock.getDamageValue(world, xyz[0], xyz[1], xyz[2]); if ((pointer = block - '0') >= 0) { //countable air -> net.minecraft.block.BlockAir - if (world.getBlock(xyz[0], xyz[1], xyz[2]) != blockType[pointer]) { + if (worldblock != blockType[pointer]) { if (DEBUG_MODE) { - TecTech.LOGGER.info("Struct-block-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + world.getBlock(xyz[0], xyz[1], xyz[2]).getUnlocalizedName() + ' ' + blockType[pointer].getUnlocalizedName()); + TecTech.LOGGER.info("Struct-block-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + worldblock.getUnlocalizedName() + ' ' + blockType[pointer].getUnlocalizedName()); } return false; } - if (world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) != blockMeta[pointer]) { + if (dmg != blockMeta[pointer]) { if (DEBUG_MODE) { - TecTech.LOGGER.info("Struct-meta-id-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) + ' ' + blockMeta[pointer]); + TecTech.LOGGER.info("Struct-meta-id-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + dmg + ' ' + blockMeta[pointer]); } return false; } } else if ((pointer = block - ' ') >= 0) { igt = aBaseMetaTileEntity.getIGregTechTileEntity(xyz[0], xyz[1], xyz[2]); if (igt == null || !addingMethods[pointer].apply(metaTile,igt, casingTextures[pointer])) { - if (world.getBlock(xyz[0], xyz[1], xyz[2]) != blockTypeFallback[pointer]) { + if (worldblock != blockTypeFallback[pointer]) { if (DEBUG_MODE) { - TecTech.LOGGER.info("Fallback-struct-block-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + world.getBlock(xyz[0], xyz[1], xyz[2]).getUnlocalizedName() + ' ' + (blockTypeFallback[pointer] == null ? "null" : blockTypeFallback[pointer].getUnlocalizedName())); + TecTech.LOGGER.info("Fallback-struct-block-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + worldblock.getUnlocalizedName() + ' ' + (blockTypeFallback[pointer] == null ? "null" : blockTypeFallback[pointer].getUnlocalizedName())); } return false; } - if (world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) != blockMetaFallback[pointer]) { + if (dmg != blockMetaFallback[pointer]) { if (DEBUG_MODE) { - TecTech.LOGGER.info("Fallback-Struct-meta-id-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) + ' ' + blockMetaFallback[pointer]); + TecTech.LOGGER.info("Fallback-Struct-meta-id-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + dmg + ' ' + blockMetaFallback[pointer]); } return false; } @@ -212,7 +214,7 @@ public class Structure { break; default: //check for block if ((pointer = block - '0') >= 0) { - if (world.getBlock(xyz[0], xyz[1], xyz[2]) != blockType[pointer] || world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) != blockMeta[pointer]) { + if (world.getBlock(xyz[0], xyz[1], xyz[2]) != blockType[pointer] || blockType[pointer].getDamageValue(world,xyz[0], xyz[1], xyz[2]) != blockMeta[pointer]) { TecTech.proxy.hint_particle(world, xyz[0], xyz[1], xyz[2], blockType[pointer], blockMeta[pointer]); } } else if ((pointer = block - ' ') >= 0) { @@ -235,7 +237,10 @@ public class Structure { break; default: //check for block if ((pointer = block - '0') >= 0) { - world.setBlock(xyz[0], xyz[1], xyz[2], blockType[pointer], blockMeta[pointer], 2); + if (blockType[pointer] instanceof ICustomMetaBlock) + ((ICustomMetaBlock)blockType[pointer]).setBlock(world,xyz[0], xyz[1], xyz[2], blockMeta[pointer]); + else + world.setBlock(xyz[0], xyz[1], xyz[2], blockType[pointer], blockMeta[pointer], 2); } } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java index 1c2fd18326..10779659dc 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java @@ -196,7 +196,8 @@ public class StructureUtility { return new IStructureElementNoPlacement<T>() { @Override public boolean check(T t, World world, int x, int y, int z) { - return blocsMap.getOrDefault(world.getBlock(x, y, z), -1) == world.getBlockMetadata(x, y, z); + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, -1) == worldBlock.getDamageValue(world, x, y, z); } @Override @@ -222,7 +223,8 @@ public class StructureUtility { return new IStructureElementNoPlacement<T>() { @Override public boolean check(T t, World world, int x, int y, int z) { - return blocsMap.getOrDefault(world.getBlock(x, y, z), Collections.emptySet()).contains(world.getBlockMetadata(x, y, z)); + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, Collections.emptySet()).contains(worldBlock.getDamageValue(world, x, y, z)); } @Override @@ -240,7 +242,8 @@ public class StructureUtility { return new IStructureElementNoPlacement<T>() { @Override public boolean check(T t, World world, int x, int y, int z) { - return block == world.getBlock(x, y, z) && meta == world.getBlockMetadata(x, y, z); + Block worldBlock = world.getBlock(x, y, z); + return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z); } @Override @@ -262,7 +265,8 @@ public class StructureUtility { return new IStructureElementNoPlacement<T>() { @Override public boolean check(T t, World world, int x, int y, int z) { - return iBlockAdder.apply(t, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + Block worldBlock = world.getBlock(x, y, z); + return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world,x,y,z)); } @Override @@ -283,12 +287,16 @@ public class StructureUtility { return new IStructureElement<T>() { @Override public boolean check(T t, World world, int x, int y, int z) { - return blocsMap.getOrDefault(world.getBlock(x, y, z), -1) == world.getBlockMetadata(x, y, z); + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, -1) == worldBlock.getDamageValue(world,x,y,z); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); + if (defaultBlock instanceof ICustomMetaBlock) + ((ICustomMetaBlock)defaultBlock).setBlock(world, x, y, z, defaultMeta); + else + world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); return true; } @@ -315,12 +323,16 @@ public class StructureUtility { return new IStructureElement<T>() { @Override public boolean check(T t, World world, int x, int y, int z) { - return blocsMap.getOrDefault(world.getBlock(x, y, z), Collections.emptySet()).contains(world.getBlockMetadata(x, y, z)); + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, Collections.emptySet()).contains(worldBlock.getDamageValue(world, x, y, z)); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); + if (defaultBlock instanceof ICustomMetaBlock) + ((ICustomMetaBlock)defaultBlock).setBlock(world, x, y, z, defaultMeta); + else + world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); return true; } @@ -339,12 +351,16 @@ public class StructureUtility { return new IStructureElement<T>() { @Override public boolean check(T t, World world, int x, int y, int z) { - return block == world.getBlock(x, y, z) && meta == world.getBlockMetadata(x, y, z); + Block worldBlock = world.getBlock(x, y, z); + return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); + if (defaultBlock instanceof ICustomMetaBlock) + ((ICustomMetaBlock)defaultBlock).setBlock(world, x, y, z, defaultMeta); + else + world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); return true; } @@ -371,12 +387,16 @@ public class StructureUtility { return new IStructureElement<T>() { @Override public boolean check(T t, World world, int x, int y, int z) { - return iBlockAdder.apply(t, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + Block worldBlock = world.getBlock(x, y, z); + return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, x, y, z)); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); + if (defaultBlock instanceof ICustomMetaBlock) + ((ICustomMetaBlock)defaultBlock).setBlock(world, x, y, z, defaultMeta); + else + world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); return true; } @@ -446,9 +466,10 @@ public class StructureUtility { @Override public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); + Block worldBlock = world.getBlock(x, y, z); return (tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex)) || - (world.getBlock(x, y, z) == placeCasing && world.getBlockMetadata(x, y, z) == placeCasingMeta); + (worldBlock == placeCasing && worldBlock.getDamageValue(world, x, y, z) == placeCasingMeta); } @Override @@ -459,7 +480,10 @@ public class StructureUtility { @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, placeCasing, placeCasingMeta, 2); + if (placeCasing instanceof ICustomMetaBlock) + ((ICustomMetaBlock)placeCasing).setBlock(world, x, y, z, placeCasingMeta); + else + world.setBlock(x, y, z, placeCasing, placeCasingMeta, 2); return true; } }; @@ -989,7 +1013,7 @@ public class StructureUtility { if (set == null) { set = new TreeSet<>(); } - set.add(world.getBlockMetadata(x, y, z)); + set.add(block.getDamageValue(world, x, y, z)); return set; }); } @@ -1060,7 +1084,7 @@ public class StructureUtility { if (tileEntity == null) { Block block = w.getBlock(x, y, z); if (block != null && block != Blocks.air) { - builder.append(map.get(block.getUnlocalizedName() + '\0' + world.getBlockMetadata(x, y, z))); + builder.append(map.get(block.getUnlocalizedName() + '\0' + block.getDamageValue(world, x, y, z))); } else { builder.append(' '); } @@ -1095,7 +1119,7 @@ public class StructureUtility { if (tileEntity == null) { Block block = w.getBlock(x, y, z); if (block != null && block != Blocks.air) { - builder.append(map.get(block.getUnlocalizedName() + '\0' + world.getBlockMetadata(x, y, z))); + builder.append(map.get(block.getUnlocalizedName() + '\0' + block.getDamageValue(world,x, y, z))); } else { builder.append(' '); } |