TechReborn/src/main/java/techreborn/multiblocks/MultiBlockCasing.java

323 lines
7.9 KiB
Java
Raw Normal View History

package techreborn.multiblocks;
2015-07-02 20:51:24 +02:00
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
2016-03-13 17:08:30 +01:00
import net.minecraft.util.math.BlockPos;
2015-07-02 20:51:24 +02:00
import net.minecraft.world.World;
2015-11-08 13:15:45 +01:00
import reborncore.common.multiblock.CoordTriplet;
import reborncore.common.multiblock.IMultiblockPart;
import reborncore.common.multiblock.MultiblockControllerBase;
import reborncore.common.multiblock.MultiblockValidationException;
import reborncore.common.multiblock.rectangular.RectangularMultiblockControllerBase;
import reborncore.common.multiblock.rectangular.RectangularMultiblockTileEntityBase;
2016-03-27 13:51:39 +02:00
import techreborn.init.ModBlocks;
2016-10-08 21:46:16 +02:00
public class MultiBlockCasing extends RectangularMultiblockControllerBase {
2016-03-25 10:47:34 +01:00
public boolean hasLava;
public boolean isStar = false;
public int height = 0;
2016-10-08 21:46:16 +02:00
public MultiBlockCasing(World world) {
2016-03-25 10:47:34 +01:00
super(world);
}
2016-10-08 21:46:16 +02:00
public String getInfo() {
2016-03-25 10:47:34 +01:00
String value = "Intact";
2016-10-08 21:46:16 +02:00
try {
2016-03-25 10:47:34 +01:00
isMachineWhole();
2016-10-08 21:46:16 +02:00
} catch (MultiblockValidationException e) {
2016-03-25 10:47:34 +01:00
e.printStackTrace();
value = e.getLocalizedMessage();
}
return value;
}
/**
* @return True if the machine is "whole" and should be assembled. False
2016-10-08 21:46:16 +02:00
* otherwise.
2016-03-25 10:47:34 +01:00
*/
@Override
2016-10-08 21:46:16 +02:00
protected void isMachineWhole() throws MultiblockValidationException {
if (connectedParts.size() < getMinimumNumberOfBlocksForAssembledMachine()) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException("Machine is too small.");
}
CoordTriplet maximumCoord = getMaximumCoord();
CoordTriplet minimumCoord = getMinimumCoord();
// Quickly check for exceeded dimensions
int deltaX = maximumCoord.x - minimumCoord.x + 1;
int deltaY = maximumCoord.y - minimumCoord.y + 1;
int deltaZ = maximumCoord.z - minimumCoord.z + 1;
int maxX = getMaximumXSize();
int maxY = getMaximumYSize();
int maxZ = getMaximumZSize();
int minX = getMinimumXSize();
int minY = getMinimumYSize();
int minZ = getMinimumZSize();
2016-10-08 21:46:16 +02:00
if (maxX > 0 && deltaX > maxX) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException(
2016-10-08 21:46:16 +02:00
String.format("Machine is too large, it may be at most %d blocks in the X dimension", maxX));
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
if (maxY > 0 && deltaY > maxY) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException(
2016-10-08 21:46:16 +02:00
String.format("Machine is too large, it may be at most %d blocks in the Y dimension", maxY));
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
if (maxZ > 0 && deltaZ > maxZ) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException(
2016-10-08 21:46:16 +02:00
String.format("Machine is too large, it may be at most %d blocks in the Z dimension", maxZ));
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
if (deltaX < minX) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException(
2016-10-08 21:46:16 +02:00
String.format("Machine is too small, it must be at least %d blocks in the X dimension", minX));
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
if (deltaY < minY) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException(
2016-10-08 21:46:16 +02:00
String.format("Machine is too small, it must be at least %d blocks in the Y dimension", minY));
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
if (deltaZ < minZ) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException(
2016-10-08 21:46:16 +02:00
String.format("Machine is too small, it must be at least %d blocks in the Z dimension", minZ));
2016-03-25 10:47:34 +01:00
}
height = deltaY;
// if(checkIfStarShape(minimumCoord.x, minimumCoord.y, minimumCoord.z)){
// isStar = true;
// return;
// } else {
// isStar = false;
// }
2016-10-08 21:46:16 +02:00
if (deltaY < minY) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException(
2016-10-08 21:46:16 +02:00
String.format("Machine is too small, it must be at least %d blocks in the Y dimension", minY));
2016-03-25 10:47:34 +01:00
}
// Now we run a simple check on each block within that volume.
// Any block deviating = NO DEAL SIR
TileEntity te;
RectangularMultiblockTileEntityBase part;
Class<? extends RectangularMultiblockControllerBase> myClass = this.getClass();
2016-10-08 21:46:16 +02:00
for (int x = minimumCoord.x; x <= maximumCoord.x; x++) {
for (int y = minimumCoord.y; y <= maximumCoord.y; y++) {
for (int z = minimumCoord.z; z <= maximumCoord.z; z++) {
2016-03-25 10:47:34 +01:00
// Okay, figure out what sort of block this should be.
te = this.worldObj.getTileEntity(new BlockPos(x, y, z));
2016-10-08 21:46:16 +02:00
if (te instanceof RectangularMultiblockTileEntityBase) {
2016-03-25 10:47:34 +01:00
part = (RectangularMultiblockTileEntityBase) te;
// Ensure this part should actually be allowed within a
// cube of this controller's type
2016-10-08 21:46:16 +02:00
if (!myClass.equals(part.getMultiblockControllerType())) {
2016-03-25 10:47:34 +01:00
throw new MultiblockValidationException(
2016-10-08 21:46:16 +02:00
String.format("Part @ %d, %d, %d is incompatible with machines of type %s", x, y, z,
myClass.getSimpleName()));
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
// This is permitted so that we can incorporate certain
// non-multiblock parts inside interiors
part = null;
}
// Validate block type against both part-level and
// material-level validators.
int extremes = 0;
2016-10-08 21:46:16 +02:00
if (x == minimumCoord.x) {
2016-03-25 10:47:34 +01:00
extremes++;
}
2016-10-08 21:46:16 +02:00
if (y == minimumCoord.y) {
2016-03-25 10:47:34 +01:00
extremes++;
}
2016-10-08 21:46:16 +02:00
if (z == minimumCoord.z) {
2016-03-25 10:47:34 +01:00
extremes++;
}
2016-10-08 21:46:16 +02:00
if (x == maximumCoord.x) {
2016-03-25 10:47:34 +01:00
extremes++;
}
2016-10-08 21:46:16 +02:00
if (y == maximumCoord.y) {
2016-03-25 10:47:34 +01:00
extremes++;
}
2016-10-08 21:46:16 +02:00
if (z == maximumCoord.z) {
2016-03-25 10:47:34 +01:00
extremes++;
}
2016-10-08 21:46:16 +02:00
if (extremes >= 2) {
if (part != null) {
2016-03-25 10:47:34 +01:00
part.isGoodForFrame();
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
isBlockGoodForFrame(this.worldObj, x, y, z);
}
2016-10-08 21:46:16 +02:00
} else if (extremes == 1) {
if (y == maximumCoord.y) {
if (part != null) {
2016-03-25 10:47:34 +01:00
part.isGoodForTop();
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
isBlockGoodForTop(this.worldObj, x, y, z);
}
2016-10-08 21:46:16 +02:00
} else if (y == minimumCoord.y) {
if (part != null) {
2016-03-25 10:47:34 +01:00
part.isGoodForBottom();
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
isBlockGoodForBottom(this.worldObj, x, y, z);
}
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
// Side
2016-10-08 21:46:16 +02:00
if (part != null) {
2016-03-25 10:47:34 +01:00
part.isGoodForSides();
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
isBlockGoodForSides(this.worldObj, x, y, z);
}
}
2016-10-08 21:46:16 +02:00
} else {
if (part != null) {
2016-03-25 10:47:34 +01:00
part.isGoodForInterior();
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
isBlockGoodForInterior(this.worldObj, x, y, z);
}
}
}
}
}
}
@Override
2016-10-08 21:46:16 +02:00
public void onAttachedPartWithMultiblockData(IMultiblockPart part, NBTTagCompound data) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected void onBlockAdded(IMultiblockPart newPart) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected void onBlockRemoved(IMultiblockPart oldPart) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected void onMachineAssembled() {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected void onMachineRestored() {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected void onMachinePaused() {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected void onMachineDisassembled() {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected int getMinimumNumberOfBlocksForAssembledMachine() {
2016-03-25 10:47:34 +01:00
return 1;
}
@Override
2016-10-08 21:46:16 +02:00
protected int getMaximumXSize() {
2016-03-25 10:47:34 +01:00
return 3;
}
@Override
2016-10-08 21:46:16 +02:00
protected int getMaximumZSize() {
2016-03-25 10:47:34 +01:00
return 3;
}
@Override
2016-10-08 21:46:16 +02:00
protected int getMaximumYSize() {
2016-03-25 10:47:34 +01:00
return 4;
}
@Override
2016-10-08 21:46:16 +02:00
protected int getMinimumXSize() {
2016-03-25 10:47:34 +01:00
return 3;
}
@Override
2016-10-08 21:46:16 +02:00
protected int getMinimumYSize() {
2016-03-25 10:47:34 +01:00
return 3;
}
@Override
2016-10-08 21:46:16 +02:00
protected int getMinimumZSize() {
2016-03-25 10:47:34 +01:00
return 3;
}
@Override
2016-10-08 21:46:16 +02:00
protected void onAssimilate(MultiblockControllerBase assimilated) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected void onAssimilated(MultiblockControllerBase assimilator) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected boolean updateServer() {
2016-03-25 10:47:34 +01:00
return true;
}
@Override
2016-10-08 21:46:16 +02:00
protected void updateClient() {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public void writeToNBT(NBTTagCompound data) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public void readFromNBT(NBTTagCompound data) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public void formatDescriptionPacket(NBTTagCompound data) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public void decodeDescriptionPacket(NBTTagCompound data) {
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
protected void isBlockGoodForInterior(World world, int x, int y, int z) throws MultiblockValidationException {
2016-03-25 10:47:34 +01:00
Block block = world.getBlockState(new BlockPos(x, y, z)).getBlock();
2016-03-27 13:51:39 +02:00
System.out.println(block);
2016-10-08 21:46:16 +02:00
if (block.isAir(world.getBlockState(new BlockPos(x, y, z)), world, new BlockPos(x, y, z))) {
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
} else if (block.getUnlocalizedName().equals("tile.lava")) {
2016-03-25 10:47:34 +01:00
hasLava = true;
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
super.isBlockGoodForInterior(world, x, y, z);
}
}
2016-03-27 13:51:39 +02:00
@Override
2016-10-08 21:46:16 +02:00
protected void isBlockGoodForFrame(World world, int x, int y, int z) throws MultiblockValidationException {
2016-03-27 13:51:39 +02:00
Block block = world.getBlockState(new BlockPos(x, y, z)).getBlock();
2016-10-08 21:46:16 +02:00
if (block == ModBlocks.MachineCasing) {
2016-03-27 13:51:39 +02:00
2016-10-08 21:46:16 +02:00
} else {
2016-03-27 13:51:39 +02:00
super.isBlockGoodForFrame(world, x, y, z);
}
}
}