cleanup, fix #3102

This commit is contained in:
asiekierka 2015-11-07 11:31:07 +01:00
parent aef5e7a628
commit eebd393fc2
8 changed files with 49 additions and 75 deletions

View file

@ -50,41 +50,53 @@ public final class BCRegistry {
return false; return false;
} }
private boolean isInvalidRecipeElement(Object o) {
if (o == null) {
return true;
}
if (o instanceof Block && !Utils.isRegistered((Block) o)) {
return true;
}
if (o instanceof Item && !Utils.isRegistered((Item) o)) {
return true;
}
if (o instanceof ItemStack && !Utils.isRegistered((ItemStack) o)) {
return true;
}
return false;
}
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public void registerTileEntity(Class clas, String ident) { public void registerTileEntity(Class clas, String ident) {
GameRegistry.registerTileEntity(CompatHooks.INSTANCE.getTile(clas), ident); GameRegistry.registerTileEntity(CompatHooks.INSTANCE.getTile(clas), ident);
} }
public void addCraftingRecipe(ItemStack result, Object... recipe) { public void addCraftingRecipe(ItemStack result, Object... recipe) {
if (isInvalidRecipeElement(result)) {
return;
}
for (Object o : recipe) { for (Object o : recipe) {
if (o == null) { if (isInvalidRecipeElement(o)) {
return;
}
if (o instanceof Block && !Utils.isRegistered((Block) o)) {
return;
}
if (o instanceof Item && !Utils.isRegistered((Item) o)) {
return;
}
if (o instanceof ItemStack && !Utils.isRegistered((ItemStack) o)) {
return; return;
} }
} }
GameRegistry.addRecipe(new ShapedOreRecipe(result, recipe)); GameRegistry.addRecipe(new ShapedOreRecipe(result, recipe));
} }
public void addShapelessRecipe(ItemStack result, Object... recipe) { public void addShapelessRecipe(ItemStack result, Object... recipe) {
if (isInvalidRecipeElement(result)) {
return;
}
for (Object o : recipe) { for (Object o : recipe) {
if (o instanceof Block && Block.getIdFromBlock((Block) o) < 0) { if (isInvalidRecipeElement(o)) {
return;
}
if (o instanceof Item && Item.getIdFromItem((Item) o) < 0) {
return;
}
if (o instanceof ItemStack && ((ItemStack) o).getItem() == null) {
return; return;
} }
} }
GameRegistry.addRecipe(new ShapelessOreRecipe(result, recipe)); GameRegistry.addRecipe(new ShapelessOreRecipe(result, recipe));
} }

View file

@ -120,9 +120,6 @@ public class EntityRobot extends EntityRobotBase implements
public float itemActiveStage = 0; public float itemActiveStage = 0;
public long lastUpdateTime = 0; public long lastUpdateTime = 0;
private SafeTimeTracker expensiveVerificationsTracker = new SafeTimeTracker(10);
private boolean isMovingOutOfStuck;
private DockingStation currentDockingStation; private DockingStation currentDockingStation;
private List<ItemStack> wearables = new ArrayList<ItemStack>(); private List<ItemStack> wearables = new ArrayList<ItemStack>();
@ -360,44 +357,6 @@ public class EntityRobot extends EntityRobotBase implements
getRegistry().killRobot(this); getRegistry().killRobot(this);
} }
// The commented out part is the part which unstucks robots.
// It has been known to cause a lot of issues in 7.1.11.
// If you want to try and fix it, go ahead.
// Right now it will simply stop them from moving.
/*
if (expensiveVerificationsTracker.markTimeIfDelay(worldObj)) {
int collisions = 0;
int bx = (int) Math.floor(posX);
int by = (int) Math.floor(posY);
int bz = (int) Math.floor(posZ);
if (by >= 0 && by < worldObj.getActualHeight() && !BuildCraftAPI.isSoftBlock(worldObj, bx, by, bz)) {
List clist = new ArrayList();
Block block = worldObj.getBlock(bx, by, bz);
block.addCollisionBoxesToList(worldObj, bx, by, bz, getBoundingBox(), clist, this);
collisions = clist.size();
}
if (collisions > 0) {
isMovingOutOfStuck = true;
motionX = 0.0F;
motionY = 0.05F;
motionZ = 0.0F;
} else if (isMovingOutOfStuck) {
isMovingOutOfStuck = false;
board.abortDelegateAI();
motionY = 0.0F;
}
}
if (!isMovingOutOfStuck) {
*/
if (linkedDockingStation == null || linkedDockingStation.isInitialized()) { if (linkedDockingStation == null || linkedDockingStation.isInitialized()) {
this.worldObj.theProfiler.startSection("bcRobotAI"); this.worldObj.theProfiler.startSection("bcRobotAI");
mainAI.cycle(); mainAI.cycle();

View file

@ -173,8 +173,8 @@ public class FacadePluggable extends PipePluggable implements IFacadePluggable {
int flags = data.readUnsignedByte(); int flags = data.readUnsignedByte();
meta = flags & 0x0F; meta = flags & 0x0F;
transparent = (flags & 0x80) > 0; transparent = (flags & 0x80) != 0;
renderAsHollow = (flags & 0x40) > 0; renderAsHollow = (flags & 0x40) != 0;
} }
private void prepareStates() { private void prepareStates() {

View file

@ -23,15 +23,18 @@ public class PipePluggableState implements ISerializable {
public void setPluggables(PipePluggable[] pluggables) { public void setPluggables(PipePluggable[] pluggables) {
this.pluggables = pluggables; this.pluggables = pluggables;
this.pluggableMatrix.clean();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
this.pluggableMatrix.setConnected(dir, pluggables[dir.ordinal()] != null);
}
} }
@Override @Override
public void writeData(ByteBuf data) { public void writeData(ByteBuf data) {
this.pluggableMatrix.clean();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
this.pluggableMatrix.setConnected(dir, pluggables[dir.ordinal()] != null);
}
this.pluggableMatrix.writeData(data); this.pluggableMatrix.writeData(data);
for (PipePluggable p : pluggables) { for (PipePluggable p : pluggables) {
if (p != null) { if (p != null) {
data.writeShort(PipeManager.pipePluggables.indexOf(p.getClass())); data.writeShort(PipeManager.pipePluggables.indexOf(p.getClass()));
@ -43,6 +46,7 @@ public class PipePluggableState implements ISerializable {
@Override @Override
public void readData(ByteBuf data) { public void readData(ByteBuf data) {
this.pluggableMatrix.readData(data); this.pluggableMatrix.readData(data);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (this.pluggableMatrix.isConnected(dir)) { if (this.pluggableMatrix.isConnected(dir)) {
try { try {

View file

@ -169,7 +169,7 @@ public class LensPluggable extends PipePluggable {
@Override @Override
public void readData(ByteBuf data) { public void readData(ByteBuf data) {
int flags = data.readUnsignedByte(); int flags = data.readUnsignedByte();
color = (flags & 31) - 1; color = (flags & 0x1F) - 1;
isFilter = (flags & 0x20) > 0; isFilter = (flags & 0x20) > 0;
} }

View file

@ -14,19 +14,20 @@ public class BitSetCodec {
public byte encode(BitSet set) { public byte encode(BitSet set) {
byte result = 0; byte result = 0;
for (byte i = 0; i < 8; i++) { for (byte i = 0; i < 8; i++) {
result <<= 1; result |= set.get(i) ? (1 << i) : 0;
result |= set.get(i) ? 1 : 0;
} }
return result; return result;
} }
public void decode(byte data, BitSet target) { public void decode(byte data, BitSet target) {
byte localData = data; byte localData = data;
int t = 1;
target.clear(); target.clear();
for (byte i = 0; i < 8; i++) { for (byte i = 0; i < 8; i++) {
target.set(7 - i, (localData & 1) != 0); target.set(i, (localData & t) != 0);
localData >>= 1; t <<= 1;
} }
} }
} }

View file

@ -37,14 +37,14 @@ public class TextureMatrix {
} }
public void writeData(ByteBuf data) { public void writeData(ByteBuf data) {
for (int iconIndexe : iconIndexes) { for (int iconIndex : iconIndexes) {
data.writeByte(iconIndexe); data.writeByte(iconIndex);
} }
} }
public void readData(ByteBuf data) { public void readData(ByteBuf data) {
for (int i = 0; i < iconIndexes.length; i++) { for (int i = 0; i < iconIndexes.length; i++) {
int icon = data.readByte(); int icon = data.readUnsignedByte();
if (iconIndexes[i] != icon) { if (iconIndexes[i] != icon) {
iconIndexes[i] = icon; iconIndexes[i] = icon;
dirty = true; dirty = true;

View file

@ -17,8 +17,6 @@ import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.transport.PipeWire; import buildcraft.api.transport.PipeWire;
public class WireMatrix { public class WireMatrix {
//private final boolean[] _hasWire = new boolean[IPipe.WireColor.values().length];
private final BitSet hasWire = new BitSet(PipeWire.values().length); private final BitSet hasWire = new BitSet(PipeWire.values().length);
private final BitSetCodec bitSetCodec = new BitSetCodec(); private final BitSetCodec bitSetCodec = new BitSetCodec();
@ -94,7 +92,7 @@ public class WireMatrix {
bitSetCodec.decode(data.readByte(), hasWire); bitSetCodec.decode(data.readByte(), hasWire);
for (int i = 0; i < PipeWire.values().length; i++) { for (int i = 0; i < PipeWire.values().length; i++) {
wires[i].readData(data); wires[i].readData(data);
wireIconIndex[i] = data.readByte(); wireIconIndex[i] = data.readUnsignedByte();
} }
} }
} }