use of buildcraft.builders.snapshot.SnapshotBuilder in project BuildCraft by BuildCraft.
the class TileBuilder method onSlotChange.
@Override
protected void onSlotChange(IItemHandlerModifiable handler, int slot, @Nonnull ItemStack before, @Nonnull ItemStack after) {
if (!world.isRemote) {
if (handler == invSnapshot) {
currentBasePosIndex = 0;
snapshot = null;
if (after.getItem() instanceof ItemSnapshot) {
Snapshot.Header header = BCBuildersItems.snapshot.getHeader(after);
if (header != null) {
Snapshot newSnapshot = GlobalSavedDataSnapshots.get(world).getSnapshot(header.key);
if (newSnapshot != null) {
snapshot = newSnapshot;
}
}
}
updateSnapshot(true);
sendNetworkUpdate(NET_SNAPSHOT_TYPE);
}
if (handler == invResources) {
Optional.ofNullable(getBuilder()).ifPresent(SnapshotBuilder::resourcesChanged);
}
}
super.onSlotChange(handler, slot, before, after);
}
use of buildcraft.builders.snapshot.SnapshotBuilder in project BuildCraft by BuildCraft.
the class TileBuilder method updateSnapshot.
private void updateSnapshot(boolean canGetFacing) {
Optional.ofNullable(getBuilder()).ifPresent(SnapshotBuilder::cancel);
if (snapshot != null && getCurrentBasePos() != null) {
snapshotType = snapshot.getType();
if (canGetFacing) {
rotation = Arrays.stream(Rotation.values()).filter(r -> r.rotate(snapshot.facing) == world.getBlockState(pos).getValue(BlockBCBase_Neptune.PROP_FACING)).findFirst().orElse(null);
}
if (snapshot.getType() == EnumSnapshotType.TEMPLATE) {
templateBuildingInfo = ((Template) snapshot).new BuildingInfo(getCurrentBasePos(), rotation);
}
if (snapshot.getType() == EnumSnapshotType.BLUEPRINT) {
blueprintBuildingInfo = ((Blueprint) snapshot).new BuildingInfo(getCurrentBasePos(), rotation);
}
currentBox = Optional.ofNullable(getBuildingInfo()).map(buildingInfo -> buildingInfo.box).orElse(null);
Optional.ofNullable(getBuilder()).ifPresent(SnapshotBuilder::updateSnapshot);
} else {
snapshotType = null;
rotation = null;
templateBuildingInfo = null;
blueprintBuildingInfo = null;
currentBox = null;
}
if (currentBox == null) {
currentBox = new Box();
}
}
use of buildcraft.builders.snapshot.SnapshotBuilder in project BuildCraft by BuildCraft.
the class RenderSnapshotBuilder method render.
public static <T extends ITileForSnapshotBuilder> void render(SnapshotBuilder<T> snapshotBuilder, World world, BlockPos tilePos, double x, double y, double z, float partialTicks, BufferBuilder bb) {
for (SnapshotBuilder<T>.PlaceTask placeTask : snapshotBuilder.clientPlaceTasks) {
Vec3d prevPos = snapshotBuilder.prevClientPlaceTasks.stream().filter(renderTaskLocal -> renderTaskLocal.pos.equals(placeTask.pos)).map(snapshotBuilder::getPlaceTaskItemPos).findFirst().orElse(snapshotBuilder.getPlaceTaskItemPos(snapshotBuilder.new PlaceTask(tilePos, Collections.emptyList(), 0L)));
Vec3d pos = prevPos.add(snapshotBuilder.getPlaceTaskItemPos(placeTask).subtract(prevPos).scale(partialTicks));
for (ItemStack item : placeTask.items) {
ItemRenderUtil.renderItemStack(x - tilePos.getX() + pos.x, y - tilePos.getY() + pos.y, z - tilePos.getZ() + pos.z, item, world.getCombinedLight(new BlockPos(pos), 0), EnumFacing.SOUTH, bb);
}
ItemRenderUtil.endItemBatch();
}
Vec3d robotPos = snapshotBuilder.robotPos;
if (robotPos != null) {
if (snapshotBuilder.prevRobotPos != null) {
robotPos = snapshotBuilder.prevRobotPos.add(robotPos.subtract(snapshotBuilder.prevRobotPos).scale(partialTicks));
}
bb.setTranslation(x - tilePos.getX(), y - tilePos.getY(), z - tilePos.getZ());
int i = 0;
for (EnumFacing face : EnumFacing.VALUES) {
ModelUtil.createFace(face, new Point3f((float) robotPos.x, (float) robotPos.y, (float) robotPos.z), new Point3f(4 / 16F, 4 / 16F, 4 / 16F), new ModelUtil.UvFaceData(BCBuildersSprites.ROBOT.getInterpU((i * 8) / 64D), BCBuildersSprites.ROBOT.getInterpV(0 / 64D), BCBuildersSprites.ROBOT.getInterpU(((i + 1) * 8) / 64D), BCBuildersSprites.ROBOT.getInterpV(8 / 64D))).lighti(world.getCombinedLight(new BlockPos(robotPos), 0)).render(bb);
i++;
}
for (SnapshotBuilder.BreakTask breakTask : snapshotBuilder.clientBreakTasks) {
LaserRenderer_BC8.renderLaserDynamic(new LaserData_BC8(BuildCraftLaserManager.POWERS[(int) Math.round(MathUtil.clamp(breakTask.power * 1D / breakTask.getTarget(), 0D, 1D) * (BuildCraftLaserManager.POWERS.length - 1))], robotPos.subtract(new Vec3d(0, 0.27, 0)), new Vec3d(breakTask.pos).add(VecUtil.VEC_HALF), 1 / 16D), bb);
}
}
bb.setTranslation(0, 0, 0);
}
Aggregations