Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Set;
import java.util.function.Consumer;

import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;

import com.simibubi.create.api.contraption.transformable.TransformableBlockEntity;
import com.simibubi.create.content.contraptions.StructureTransform;
Expand Down Expand Up @@ -88,7 +88,30 @@ public ChainConveyorBlockEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockSt

@Override
protected AABB createRenderBoundingBox() {
return new AABB(worldPosition).inflate(connections.isEmpty() ? 3 : 64);
if (connections.isEmpty()) {
return new AABB(worldPosition).inflate(3);
} else {
Vec3 mid = Vec3.atLowerCornerOf(worldPosition);
double minX = mid.x;
double minY = mid.y;
double minZ = mid.z;
double maxX = mid.x;
double maxY = mid.y;
double maxZ = mid.z;

for (BlockPos connection : connections) {
ConnectionStats stats = connectionStats.get(connection);
if (stats == null)
continue;
minX = Math.min(minX, Math.min(stats.start.x, stats.end.x));
minY = Math.min(minY, Math.min(stats.start.y, stats.end.y));
minZ = Math.min(minZ, Math.min(stats.start.z, stats.end.z));
maxX = Math.max(maxX, Math.max(stats.start.x, stats.end.x));
maxY = Math.max(maxY, Math.max(stats.start.y, stats.end.y));
maxZ = Math.max(maxZ, Math.max(stats.start.z, stats.end.z));
}
return new AABB(minX, minY, minZ, maxX, maxY, maxZ).inflate(3);
}
}

@Override
Expand Down Expand Up @@ -486,8 +509,7 @@ private void tickBoxVisuals(ChainConveyorPackage box) {
physicsData.yaw = AngleHelper.angleLerp(.25, physicsData.yaw, box.yaw);
}

private void calculateConnectionStats(BlockPos connection) {
boolean reversed = getSpeed() < 0;
public static ConnectionStats calculateConnectionStats(BlockPos connection, BlockPos worldPosition, boolean reversed) {
float offBranchDistance = 35f;
float direction = Mth.RAD_TO_DEG * (float) Mth.atan2(connection.getX(), connection.getZ());
float angle = wrapAngle(direction - offBranchDistance * (reversed ? -1 : 1));
Expand All @@ -502,7 +524,12 @@ private void calculateConnectionStats(BlockPos connection) {
.add(0, 6 / 16f, 0);

float length = (float) start.distanceTo(end);
connectionStats.put(connection, new ConnectionStats(angle, length, start, end));
return new ConnectionStats(angle, length, start, end);
}

private void calculateConnectionStats(BlockPos connection) {
boolean reversed = getSpeed() < 0;
connectionStats.put(connection, calculateConnectionStats(connection, worldPosition, reversed));
}

public boolean addConnectionTo(BlockPos target) {
Expand Down Expand Up @@ -668,7 +695,7 @@ public float propagateRotationTo(KineticBlockEntity target, BlockState stateFrom
@Override
public void writeSafe(CompoundTag tag, HolderLookup.Provider registries) {
super.writeSafe(tag, registries);
tag.put("Connections", CatnipCodecUtils.encode(CatnipCodecs.set(BlockPos.CODEC), registries, connections).orElseThrow());
tag.put("Connections", CatnipCodecUtils.encode(CatnipCodecs.set(BlockPos.CODEC), connections).orElseThrow());
}

@Override
Expand All @@ -679,7 +706,7 @@ protected void write(CompoundTag compound, HolderLookup.Provider registries, boo
chainDestroyedEffectToSend = null;
}

compound.put("Connections", CatnipCodecUtils.encode(CatnipCodecs.set(BlockPos.CODEC), registries, connections).orElseThrow());
compound.put("Connections", CatnipCodecUtils.encode(CatnipCodecs.set(BlockPos.CODEC), connections).orElseThrow());
compound.put("TravellingPackages", NBTHelper.writeCompoundList(travellingPackages.entrySet(), entry -> {
CompoundTag compoundTag = new CompoundTag();
compoundTag.put("Target", NbtUtils.writeBlockPos(entry.getKey()));
Expand All @@ -699,7 +726,7 @@ protected void read(CompoundTag compound, HolderLookup.Provider registries, bool

int sizeBefore = connections.size();
connections.clear();
CatnipCodecUtils.decode(CatnipCodecs.set(BlockPos.CODEC), registries, compound.get("Connections")).ifPresent(connections::addAll);
CatnipCodecUtils.decode(CatnipCodecs.set(BlockPos.CODEC), compound.get("Connections")).ifPresent(connections::addAll);
travellingPackages.clear();
NBTHelper.iterateCompoundList(compound.getList("TravellingPackages", Tag.TAG_COMPOUND),
c -> travellingPackages.put(NBTHelper.readBlockPos(c, "Target"),
Expand All @@ -714,7 +741,7 @@ protected void read(CompoundTag compound, HolderLookup.Provider registries, bool
invalidateRenderBoundingBox();
}

public float wrapAngle(float angle) {
public static float wrapAngle(float angle) {
angle %= 360;
if (angle < 0)
angle += 360;
Expand Down
Loading