Changed the Lava Factory Completeness Detection to be less stupid and better to use

This commit is contained in:
Ellpeck 2015-07-25 05:28:31 +02:00
parent 7304619c32
commit ac9574ffeb
3 changed files with 30 additions and 20 deletions

View file

@ -73,7 +73,6 @@
-Ring of Growth: Lets Plants grow, more Reach with Tier 2 -Ring of Growth: Lets Plants grow, more Reach with Tier 2
-Ring of Thorns: Hurts Attackers when they hit you with a Projectile -Ring of Thorns: Hurts Attackers when they hit you with a Projectile
-Ring of Water Walking -Ring of Water Walking
-Ring of Flight
-Ring of Aquadive: Fast underwater movement -Ring of Aquadive: Fast underwater movement
-Ring of Suction: Sucks up Items in the area -Ring of Suction: Sucks up Items in the area
-Ring of Water Absorption: Removes Water around -Ring of Water Absorption: Removes Water around

View file

@ -5,7 +5,7 @@ import cofh.api.energy.IEnergyReceiver;
import ellpeck.actuallyadditions.blocks.InitBlocks; import ellpeck.actuallyadditions.blocks.InitBlocks;
import ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks; import ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks;
import ellpeck.actuallyadditions.config.values.ConfigIntValues; import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import net.minecraft.block.Block; import ellpeck.actuallyadditions.util.WorldUtil;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -19,6 +19,9 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I
private final int maxWorkTime = ConfigIntValues.LAVA_FACTORY_TIME.getValue(); private final int maxWorkTime = ConfigIntValues.LAVA_FACTORY_TIME.getValue();
private int currentWorkTime; private int currentWorkTime;
//The Positions the Case Blocks should be in for the Factory to work
private static final int[][] CASE_POSITIONS = {{-1, 1, 0}, {1, 1, 0}, {0, 1, -1}, {0, 1, 1}};
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void updateEntity(){ public void updateEntity(){
@ -36,18 +39,7 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I
} }
public int isMultiblock(){ public int isMultiblock(){
Block blockNorth = worldObj.getBlock(xCoord+ForgeDirection.NORTH.offsetX, yCoord+1, zCoord+ForgeDirection.NORTH.offsetZ); if(WorldUtil.hasBlocksInPlacesGiven(CASE_POSITIONS, InitBlocks.blockMisc, TheMiscBlocks.LAVA_FACTORY_CASE.ordinal(), worldObj, xCoord, yCoord, zCoord)){
Block blockEast = worldObj.getBlock(xCoord+ForgeDirection.EAST.offsetX, yCoord+1, zCoord+ForgeDirection.EAST.offsetZ);
Block blockSouth = worldObj.getBlock(xCoord+ForgeDirection.SOUTH.offsetX, yCoord+1, zCoord+ForgeDirection.SOUTH.offsetZ);
Block blockWest = worldObj.getBlock(xCoord+ForgeDirection.WEST.offsetX, yCoord+1, zCoord+ForgeDirection.WEST.offsetZ);
int metaNorth = worldObj.getBlockMetadata(xCoord+ForgeDirection.NORTH.offsetX, yCoord+1, zCoord+ForgeDirection.NORTH.offsetZ);
int metaEast = worldObj.getBlockMetadata(xCoord+ForgeDirection.EAST.offsetX, yCoord+1, zCoord+ForgeDirection.EAST.offsetZ);
int metaSouth = worldObj.getBlockMetadata(xCoord+ForgeDirection.SOUTH.offsetX, yCoord+1, zCoord+ForgeDirection.SOUTH.offsetZ);
int metaWest = worldObj.getBlockMetadata(xCoord+ForgeDirection.WEST.offsetX, yCoord+1, zCoord+ForgeDirection.WEST.offsetZ);
int metaNeeded = TheMiscBlocks.LAVA_FACTORY_CASE.ordinal();
if(blockNorth == InitBlocks.blockMisc && blockEast == InitBlocks.blockMisc && blockSouth == InitBlocks.blockMisc && blockWest == InitBlocks.blockMisc){
if(metaNorth == metaNeeded && metaEast == metaNeeded && metaSouth == metaNeeded && metaWest == metaNeeded){
if(worldObj.getBlock(xCoord, yCoord+1, zCoord) == Blocks.lava || worldObj.getBlock(xCoord, yCoord+1, zCoord) == Blocks.flowing_lava){ if(worldObj.getBlock(xCoord, yCoord+1, zCoord) == Blocks.lava || worldObj.getBlock(xCoord, yCoord+1, zCoord) == Blocks.flowing_lava){
return HAS_LAVA; return HAS_LAVA;
} }
@ -55,7 +47,6 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I
return HAS_AIR; return HAS_AIR;
} }
} }
}
return NOT_MULTI; return NOT_MULTI;
} }

View file

@ -50,6 +50,26 @@ public class WorldUtil{
} }
} }
/**
* Checks if a given Block with a given Meta is present in given Positions
* @param positions The Positions, an array of {xCoord, yCoord, zCoord} arrays containing RELATIVE Positions
* @param block The Block
* @param meta The Meta
* @param world The World
* @param x The Start X Coord
* @param y The Start Y Coord
* @param z The Start Z Coord
* @return Is every block present?
*/
public static boolean hasBlocksInPlacesGiven(int[][] positions, Block block, int meta, World world, int x, int y, int z){
for(int[] xYZ : positions){
if(!(world.getBlock(x+xYZ[0], y+xYZ[1], z+xYZ[2]) == block && world.getBlockMetadata(x+xYZ[0], y+xYZ[1], z+xYZ[2]) == meta)){
return false;
}
}
return true;
}
public static void updateTileAndTilesAround(TileEntity tile){ public static void updateTileAndTilesAround(TileEntity tile){
tile.getWorldObj().markBlockForUpdate(tile.xCoord+1, tile.yCoord, tile.zCoord); tile.getWorldObj().markBlockForUpdate(tile.xCoord+1, tile.yCoord, tile.zCoord);
tile.getWorldObj().markBlockForUpdate(tile.xCoord-1, tile.yCoord, tile.zCoord); tile.getWorldObj().markBlockForUpdate(tile.xCoord-1, tile.yCoord, tile.zCoord);