2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2017-06-14 17:56:09 +02:00
|
|
|
public static final String STANDARD_CASING = "standard";
|
|
|
|
public static final String REINFORCED_CASING = "reinforced";
|
|
|
|
public static final String ADVANCED_CASING = "advanced";
|
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
|
|
|
|
2017-06-14 17:56:09 +02:00
|
|
|
public boolean checkCasing(int offX, int offY, int offZ, String type) {
|
2016-10-08 21:46:16 +02:00
|
|
|
IBlockState block = getBlock(offX, offY, offZ);
|
2017-01-01 08:29:32 +01:00
|
|
|
if (block.getBlock() == ModBlocks.MACHINE_CASINGS) {
|
2017-06-14 17:56:09 +02:00
|
|
|
if (block.getValue(BlockMachineCasing.TYPE).equals(type))
|
2016-10-08 21:46:16 +02:00
|
|
|
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
|
|
|
|
2017-06-14 17:56:09 +02:00
|
|
|
public boolean checkRectY(int sizeX, int sizeZ, String casingType, BlockPos offset) {
|
2016-10-08 21:46:16 +02:00
|
|
|
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
|
|
|
|
2017-06-14 17:56:09 +02:00
|
|
|
public boolean checkRectZ(int sizeX, int sizeY, String casingType, BlockPos offset) {
|
2016-10-08 21:46:16 +02:00
|
|
|
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
|
|
|
|
2017-06-14 17:56:09 +02:00
|
|
|
public boolean checkRectX(int sizeZ, int sizeY, String casingType, BlockPos offset) {
|
2016-10-08 21:46:16 +02:00
|
|
|
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
|
|
|
|
2017-06-14 17:56:09 +02:00
|
|
|
public boolean checkRingY(int sizeX, int sizeZ, String casingType, BlockPos offset) {
|
2016-10-08 21:46:16 +02:00
|
|
|
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-07-24 21:26:15 +02:00
|
|
|
|
2017-06-14 17:56:09 +02:00
|
|
|
public boolean checkRingYHollow(int sizeX, int sizeZ, String casingType, BlockPos offset) {
|
2016-10-08 21:46:16 +02:00
|
|
|
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-24 21:26:15 +02:00
|
|
|
|
2016-07-23 20:10:37 +02:00
|
|
|
}
|