use of mods.railcraft.common.blocks.structures.StructurePattern in project Railcraft by Railcraft.
the class StructureLogic method readFromNBT.
@Override
@OverridingMethodsMustInvokeSuper
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
functionalLogic.readFromNBT(data);
isMaster = data.getBoolean("master");
if (data.hasKey("marker"))
marker = data.getString("marker").charAt(0);
StructurePattern pat = null;
try {
byte index = data.getByte("pattern");
pat = index < 0 ? null : patterns.get(index);
} catch (Exception ex) {
// NOOP
}
BlockPos pos = NBTPlugin.readBlockPos(data, "posInPattern");
setPatternState(pat, pos);
}
use of mods.railcraft.common.blocks.structures.StructurePattern in project Railcraft by Railcraft.
the class StructureLogic method readPacketData.
@Override
@OverridingMethodsMustInvokeSuper
public void readPacketData(RailcraftInputStream data) throws IOException {
requestPacket = false;
state = data.readEnum(StructureState.VALUES);
marker = data.readChar();
if (state == StructureState.VALID) {
int patternIndex = data.readByte();
patternIndex = MathHelper.clamp(patternIndex, 0, patterns.size() - 1);
StructurePattern pat = patterns.get(patternIndex);
BlockPos posInPattern = data.readBlockPos();
changePattern(pat, posInPattern);
isMaster = pat.isMasterPosition(posInPattern);
// TODO is this still necessary?
if (!getMasterLogic().isPresent())
requestPacket = true;
} else {
isMaster = false;
changePattern(null, null);
}
super.readPacketData(data);
functionalLogic.readPacketData(data);
}
use of mods.railcraft.common.blocks.structures.StructurePattern in project Railcraft by Railcraft.
the class StructureLogic method testIfMasterBlock.
protected void testIfMasterBlock() {
// System.out.println("testing structure");
testPatterns();
List<TileRailcraft> old = new ArrayList<>(components);
components.clear();
components.add(tile);
if (patternStates.containsKey(StructurePattern.State.VALID)) {
state = StructureState.VALID;
isMaster = true;
// System.out.println("structure complete");
StructurePattern pattern = patternStates.get(StructurePattern.State.VALID).get(0);
int xWidth = pattern.getPatternWidthX();
int zWidth = pattern.getPatternWidthZ();
int height = pattern.getPatternHeight();
BlockPos offset = getPos().subtract(pattern.getMasterOffset());
Map<BlockPos, StructureLogic> newComponents = new HashMap<>();
for (int px = 0; px < xWidth; px++) {
for (int py = 0; py < height; py++) {
for (int pz = 0; pz < zWidth; pz++) {
char marker = pattern.getPatternMarker(px, py, pz);
if (isMapPositionOtherBlock(marker))
continue;
BlockPos patternPos = new BlockPos(px, py, pz);
BlockPos pos = patternPos.add(offset);
WorldPlugin.getTileEntity(theWorldAsserted(), pos).flatMap(tileToLogic()).ifPresent(l -> {
components.add(l.tile);
newComponents.put(patternPos, l);
});
}
}
}
newComponents.forEach((pos, logic) -> logic.changePattern(pattern, pos));
MinecraftForge.EVENT_BUS.post(new MultiBlockEvent.Form(tile));
} else if (patternStates.containsKey(StructurePattern.State.NOT_LOADED)) {
state = StructureState.UNKNOWN;
} else {
state = StructureState.INVALID;
functionalLogic.getLogic(IDropsInv.class).ifPresent(i -> i.spewInventory(theWorldAsserted(), getPos()));
if (isMaster) {
isMaster = false;
onMasterReset();
sendUpdateToClient();
}
}
old.removeAll(components);
old.stream().filter(t -> !t.isInvalid()).map(tileToLogic()).flatMap(Streams.unwrap()).forEach(t -> t.changePattern(null, null));
}
Aggregations