TechReborn/src/main/java/techreborn/tiles/multiblock/MultiblockChecker.java

100 lines
2.9 KiB
Java
Raw Normal View History

2016-07-23 20:10:37 +02:00
package techreborn.tiles.multiblock;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import techreborn.blocks.BlockMachineCasing;
import techreborn.init.ModBlocks;
public class MultiblockChecker {
2016-10-08 21:46:16 +02:00
public static final BlockPos ZERO_OFFSET = BlockPos.ORIGIN;
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public static final int CASING_NORMAL = 0;
public static final int CASING_REINFORCED = 1;
public static final int CASING_ADVANCED = 2;
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
private final World world;
private final BlockPos downCenter;
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public MultiblockChecker(World world, BlockPos downCenter) {
this.world = world;
this.downCenter = downCenter;
}
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public boolean checkCasing(int offX, int offY, int offZ, int type) {
IBlockState block = getBlock(offX, offY, offZ);
2016-12-05 10:40:55 +01:00
if (block.getBlock() == ModBlocks.machineCasing) {
2016-10-08 21:46:16 +02:00
if (block.getValue(BlockMachineCasing.METADATA) == type)
return true;
}
return false;
}
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public boolean checkAir(int offX, int offY, int offZ) {
BlockPos pos = downCenter.add(offX, offY, offZ);
return world.isAirBlock(pos);
}
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public IBlockState getBlock(int offX, int offY, int offZ) {
BlockPos pos = downCenter.add(offX, offY, offZ);
return world.getBlockState(pos);
}
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public boolean checkRectY(int sizeX, int sizeZ, int casingType, BlockPos offset) {
for (int x = -sizeX; x <= sizeX; x++) {
for (int z = -sizeZ; z <= sizeZ; z++) {
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
return false;
}
}
return true;
}
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public boolean checkRectZ(int sizeX, int sizeY, int casingType, BlockPos offset) {
for (int x = -sizeX; x <= sizeX; x++) {
for (int y = -sizeY; y <= sizeY; y++) {
if (!checkCasing(x + offset.getX(), y + offset.getY(), offset.getZ(), casingType))
return false;
}
}
return true;
}
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public boolean checkRectX(int sizeZ, int sizeY, int casingType, BlockPos offset) {
for (int z = -sizeZ; z <= sizeZ; z++) {
for (int y = -sizeY; y <= sizeY; y++) {
if (!checkCasing(offset.getX(), y + offset.getY(), z + offset.getZ(), casingType))
return false;
}
}
return true;
}
2016-07-23 20:10:37 +02:00
2016-10-08 21:46:16 +02:00
public boolean checkRingY(int sizeX, int sizeZ, int casingType, BlockPos offset) {
for (int x = -sizeX; x <= sizeX; x++) {
for (int z = -sizeZ; z <= sizeZ; z++) {
if ((x == sizeX || x == -sizeX) || (z == sizeZ || z == -sizeZ)) {
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
return false;
}
}
}
return true;
}
2016-10-08 21:46:16 +02:00
public boolean checkRingYHollow(int sizeX, int sizeZ, int casingType, BlockPos offset) {
for (int x = -sizeX; x <= sizeX; x++) {
for (int z = -sizeZ; z <= sizeZ; z++) {
if ((x == sizeX || x == -sizeX) || (z == sizeZ || z == -sizeZ)) {
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
return false;
} else if (!checkAir(x + offset.getX(), offset.getY(), z + offset.getZ()))
return false;
}
}
return true;
}
2016-07-23 20:10:37 +02:00
}