mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
CTM fixes!
This commit is contained in:
1 parent
738c5c8ba6
commit
c44c23b5e9
3 files changed
+121
-57
No files matched your search
@@ -19,6 +19,7 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -120,8 +121,10 @@ public class CTM {
|
||||
protected EnumMap<Dir, Boolean> connectionMap = Maps.newEnumMap(Dir.class);
|
||||
protected int[] submapCache;
|
||||
|
||||
protected CTM() {
|
||||
for (Dir dir : Dir.VALUES) {
|
||||
protected CTM()
|
||||
{
|
||||
for (Dir dir : Dir.VALUES)
|
||||
{
|
||||
connectionMap.put(dir, false);
|
||||
}
|
||||
|
||||
@@ -293,28 +296,13 @@ public class CTM {
|
||||
|
||||
boolean disableObscured = disableObscuredFaceCheck.or(disableObscuredFaceCheckConfig);
|
||||
|
||||
IBlockState con = getBlockOrFacade(world, connection, dir);
|
||||
IBlockState obscuring = disableObscured ? null : getBlockOrFacade(world, pos2, dir);
|
||||
|
||||
CTMData data = ((ICTMBlock)state.getBlock()).getCTMData(state);
|
||||
IBlockState obscuring = disableObscured ? null : getConnectedState(world, pos2, dir);
|
||||
|
||||
// no block or a bad API user
|
||||
if (con == null || data == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean ret = false;
|
||||
|
||||
if(con.getBlock() instanceof ICTMBlock && ((ICTMBlock)con.getBlock()).getCTMData(con) != null)
|
||||
{
|
||||
String state2 = ((IStringSerializable)con.getValue(((ICTMBlock)con.getBlock()).getTypeProperty())).getName();
|
||||
|
||||
ret = data.acceptableBlockStates.contains(state2);
|
||||
}
|
||||
boolean ret = canConnect(world, current, connection);
|
||||
|
||||
// no block obscuring this face
|
||||
if (obscuring == null) {
|
||||
if(obscuring == null)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -323,8 +311,34 @@ public class CTM {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static boolean canConnect(IBlockAccess world, BlockPos pos, BlockPos connection)
|
||||
{
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
IBlockState con = world.getBlockState(connection);
|
||||
|
||||
CTMData data = ((ICTMBlock)state.getBlock()).getCTMData(state);
|
||||
|
||||
public static IBlockState getBlockOrFacade(IBlockAccess world, BlockPos pos, EnumFacing side) {
|
||||
// no block or a bad API user
|
||||
if(con == null || data == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean ret = false;
|
||||
|
||||
if(con.getBlock() instanceof ICTMBlock && ((ICTMBlock)con.getBlock()).getCTMData(con) != null)
|
||||
{
|
||||
String state2 = ((IStringSerializable)con.getValue(((ICTMBlock)con.getBlock()).getTypeProperty())).getName();
|
||||
|
||||
ret = data.acceptableBlockStates.contains(state2);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static IBlockState getConnectedState(IBlockAccess world, BlockPos pos, EnumFacing side)
|
||||
{
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -53,9 +53,7 @@ public enum CTMConnections
|
||||
NORTH_NORTH(EnumFacing.NORTH, null, true),
|
||||
SOUTH_SOUTH(EnumFacing.SOUTH, null, true),
|
||||
EAST_EAST(EnumFacing.EAST, null, true),
|
||||
WEST_WEST(EnumFacing.WEST, null, true),
|
||||
|
||||
;
|
||||
WEST_WEST(EnumFacing.WEST, null, true);
|
||||
|
||||
public static final CTMConnections[] VALUES = values();
|
||||
|
||||
@@ -66,56 +64,75 @@ public enum CTMConnections
|
||||
private Dir dir;
|
||||
private boolean offset;
|
||||
|
||||
private CTMConnections(Dir dir) {
|
||||
private CTMConnections(Dir dir)
|
||||
{
|
||||
this(EnumFacing.SOUTH, dir);
|
||||
}
|
||||
|
||||
private CTMConnections(Dir dir, boolean offset) {
|
||||
private CTMConnections(Dir dir, boolean offset)
|
||||
{
|
||||
this(EnumFacing.SOUTH, dir, offset);
|
||||
}
|
||||
|
||||
private CTMConnections(EnumFacing normal, Dir dir){
|
||||
private CTMConnections(EnumFacing normal, Dir dir)
|
||||
{
|
||||
this(normal, dir, false);
|
||||
}
|
||||
|
||||
private CTMConnections(EnumFacing normal, Dir dir, boolean offset) {
|
||||
private CTMConnections(EnumFacing normal, Dir dir, boolean offset)
|
||||
{
|
||||
this.normal = normal;
|
||||
this.dir = dir;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public Dir getDirForSide(EnumFacing facing){
|
||||
public Dir getDirForSide(EnumFacing facing)
|
||||
{
|
||||
return dir == null ? null : dir;//TODO .relativize()
|
||||
}
|
||||
|
||||
public EnumFacing clipOrDestroy(EnumFacing direction) {
|
||||
public EnumFacing clipOrDestroy(EnumFacing direction)
|
||||
{
|
||||
EnumFacing[] dirs = dir == null ? new EnumFacing[] {normal, normal} : dir.getNormalizedDirs(direction);
|
||||
if (dirs[0] == direction) {
|
||||
|
||||
if(dirs[0] == direction)
|
||||
{
|
||||
return dirs.length > 1 ? dirs[1] : null;
|
||||
} else if (dirs.length > 1 && dirs[1] == direction) {
|
||||
}
|
||||
else if(dirs.length > 1 && dirs[1] == direction)
|
||||
{
|
||||
return dirs[0];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public BlockPos transform(BlockPos pos) {
|
||||
if (dir != null) {
|
||||
for (EnumFacing facing : dir.getNormalizedDirs(normal)) {
|
||||
public BlockPos transform(BlockPos pos)
|
||||
{
|
||||
if(dir != null)
|
||||
{
|
||||
for(EnumFacing facing : dir.getNormalizedDirs(normal))
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
pos = pos.offset(normal);
|
||||
}
|
||||
|
||||
if (offset) {
|
||||
if(offset)
|
||||
{
|
||||
pos = pos.offset(normal);
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
public static CTMConnections fromFacing(EnumFacing facing){
|
||||
switch (facing){
|
||||
public static CTMConnections fromFacing(EnumFacing facing)
|
||||
{
|
||||
switch(facing)
|
||||
{
|
||||
case NORTH: return NORTH;
|
||||
case SOUTH: return SOUTH;
|
||||
case EAST: return EAST;
|
||||
@@ -126,8 +143,10 @@ public enum CTMConnections
|
||||
}
|
||||
}
|
||||
|
||||
public static EnumFacing toFacing(CTMConnections loc){
|
||||
switch (loc){
|
||||
public static EnumFacing toFacing(CTMConnections loc)
|
||||
{
|
||||
switch(loc)
|
||||
{
|
||||
case NORTH: return EnumFacing.NORTH;
|
||||
case SOUTH: return EnumFacing.SOUTH;
|
||||
case EAST: return EnumFacing.EAST;
|
||||
@@ -138,45 +157,68 @@ public enum CTMConnections
|
||||
}
|
||||
}
|
||||
|
||||
public static List<CTMConnections> decode(long data) {
|
||||
public static List<CTMConnections> decode(long data)
|
||||
{
|
||||
List<CTMConnections> list = new ArrayList<>();
|
||||
for (CTMConnections loc : values()) {
|
||||
if ((1 & (data >> loc.ordinal())) != 0) {
|
||||
|
||||
for(CTMConnections loc : values())
|
||||
{
|
||||
if((1 & (data >> loc.ordinal())) != 0)
|
||||
{
|
||||
list.add(loc);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public long getMask(){
|
||||
public long getMask()
|
||||
{
|
||||
return 1 << ordinal();
|
||||
}
|
||||
|
||||
public static List<CTMConnections> getConnections(IBlockAccess world, BlockPos pos, CTMConnections[] values){
|
||||
public static List<CTMConnections> getConnections(IBlockAccess world, BlockPos pos, CTMConnections[] values)
|
||||
{
|
||||
List<CTMConnections> locs = new ArrayList<>();
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
for (CTMConnections loc : values) {
|
||||
|
||||
for(CTMConnections loc : values)
|
||||
{
|
||||
BlockPos second = loc.transform(pos);
|
||||
if (state.equals(CTM.getBlockOrFacade(world, second, null))){
|
||||
|
||||
if(CTM.canConnect(world, pos, second))
|
||||
{
|
||||
locs.add(loc);
|
||||
}
|
||||
}
|
||||
|
||||
return locs;
|
||||
}
|
||||
|
||||
public static long getData(IBlockAccess world, BlockPos pos, CTMConnections[] values){
|
||||
public static long getData(IBlockAccess world, BlockPos pos, CTMConnections[] values)
|
||||
{
|
||||
List<CTMConnections> locs = getConnections(world, pos, values);
|
||||
|
||||
long data = 0;
|
||||
for (CTMConnections loc : locs){
|
||||
|
||||
for(CTMConnections loc : locs)
|
||||
{
|
||||
data = data | loc.getMask();
|
||||
}
|
||||
if (MekanismAPI.debug) {
|
||||
|
||||
if(MekanismAPI.debug)
|
||||
{
|
||||
String s = Long.toBinaryString(data);
|
||||
while (s.length() < 32) {
|
||||
|
||||
while(s.length() < 32)
|
||||
{
|
||||
s = "0" + s;
|
||||
}
|
||||
|
||||
System.out.println(pos + ": " + s);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
@@ -119,9 +120,9 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock
|
||||
{
|
||||
case GENERATOR_BLOCK_1:
|
||||
ctmData[9] = new CTMData(GeneratorType.ELECTROMAGNETIC_COIL);
|
||||
ctmData[10] = new CTMData(GeneratorType.TURBINE_CASING);
|
||||
ctmData[11] = new CTMData(GeneratorType.TURBINE_VALVE);
|
||||
ctmData[12] = new CTMData(GeneratorType.TURBINE_VENT);
|
||||
ctmData[10] = new CTMData(GeneratorType.TURBINE_CASING, GeneratorType.TURBINE_VALVE, GeneratorType.TURBINE_VENT);
|
||||
ctmData[11] = new CTMData(GeneratorType.TURBINE_VALVE, GeneratorType.TURBINE_CASING, GeneratorType.TURBINE_VENT);
|
||||
ctmData[12] = new CTMData(GeneratorType.TURBINE_VENT, GeneratorType.TURBINE_CASING, GeneratorType.TURBINE_VALVE);
|
||||
ctmData[13] = new CTMData(GeneratorType.SATURATING_CONDENSER);
|
||||
|
||||
break;
|
||||
@@ -572,6 +573,13 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public BlockRenderLayer getBlockLayer()
|
||||
{
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
/*This method is not used, metadata manipulation is required to create a Tile Entity.*/
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta)
|
||||
|
||||
Reference in new issue
Block a user