From db2b8dd197124d0f56810b47e3412613eaa08b54 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Wed, 14 Oct 2020 21:15:19 +0200 Subject: [PATCH] ForgeCraft Playtesting, Part II - Fixed server dist crash in entity belt movement - Fixed client crash when saving a schematic without giving it a name --- .../belt/transport/BeltMovementHandler.java | 50 +++++++++++++------ .../client/SchematicAndQuillHandler.java | 2 +- .../create/foundation/gui/widgets/Label.java | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java index cfb74196c..fbe36c36f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java @@ -51,7 +51,7 @@ public class BeltMovementHandler { ticksSinceLastCollision++; return this; } - + public int getTicksSinceLastCollision() { return ticksSinceLastCollision; } @@ -72,8 +72,8 @@ public class BeltMovementHandler { TileEntity tileEntityBelowPassenger = world.getTileEntity(entityIn.getBlockPos()); BlockState blockState = info.lastCollidedState; Direction movementFacing = - Direction.getFacingFromAxisDirection(blockState.get(BlockStateProperties.HORIZONTAL_FACING).getAxis(), - beltTe.getSpeed() < 0 ? POSITIVE : NEGATIVE); + Direction.getFacingFromAxisDirection(blockState.get(BlockStateProperties.HORIZONTAL_FACING) + .getAxis(), beltTe.getSpeed() < 0 ? POSITIVE : NEGATIVE); boolean collidedWithBelt = te instanceof BeltTileEntity; boolean betweenBelts = tileEntityBelowPassenger instanceof BeltTileEntity && tileEntityBelowPassenger != te; @@ -84,7 +84,8 @@ public class BeltMovementHandler { } // Too slow - boolean notHorizontal = beltTe.getBlockState().get(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL; + boolean notHorizontal = beltTe.getBlockState() + .get(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL; if (Math.abs(beltTe.getSpeed()) < 1) return; @@ -104,19 +105,23 @@ public class BeltMovementHandler { float movementSpeed = beltTe.getBeltMovementSpeed(); final Direction movementDirection = Direction.getFacingFromAxis(axis == Axis.X ? NEGATIVE : POSITIVE, axis); - Vector3i centeringDirection = - Direction.getFacingFromAxis(POSITIVE, beltFacing.rotateY().getAxis()).getDirectionVec(); - Vector3d movement = Vector3d.of(movementDirection.getDirectionVec()).scale(movementSpeed); + Vector3i centeringDirection = Direction.getFacingFromAxis(POSITIVE, beltFacing.rotateY() + .getAxis()) + .getDirectionVec(); + Vector3d movement = Vector3d.of(movementDirection.getDirectionVec()) + .scale(movementSpeed); - double diffCenter = axis == Axis.Z ? (pos.getX() + .5f - entityIn.getX()) : (pos.getZ() + .5f - entityIn.getZ()); + double diffCenter = + axis == Axis.Z ? (pos.getX() + .5f - entityIn.getX()) : (pos.getZ() + .5f - entityIn.getZ()); if (Math.abs(diffCenter) > 48 / 64f) return; BeltPart part = blockState.get(BeltBlock.PART); float top = 13 / 16f; boolean onSlope = notHorizontal && (part == BeltPart.MIDDLE || part == BeltPart.PULLEY - || part == (slope == BeltSlope.UPWARD ? BeltPart.END : BeltPart.START) && entityIn.getY() - pos.getY() < top - || part == (slope == BeltSlope.UPWARD ? BeltPart.START : BeltPart.END) && entityIn.getY() - pos.getY() > top); + || part == (slope == BeltSlope.UPWARD ? BeltPart.END : BeltPart.START) && entityIn.getY() - pos.getY() < top + || part == (slope == BeltSlope.UPWARD ? BeltPart.START : BeltPart.END) + && entityIn.getY() - pos.getY() > top); boolean movingDown = onSlope && slope == (movementFacing == beltFacing ? BeltSlope.DOWNWARD : BeltSlope.UPWARD); boolean movingUp = onSlope && slope == (movementFacing == beltFacing ? BeltSlope.UPWARD : BeltSlope.DOWNWARD); @@ -132,7 +137,8 @@ public class BeltMovementHandler { if (movingDown) movement = movement.add(0, -Math.abs(axis.getCoordinate(movement.x, movement.y, movement.z)), 0); - Vector3d centering = Vector3d.of(centeringDirection).scale(diffCenter * Math.min(Math.abs(movementSpeed), .1f) * 4); + Vector3d centering = Vector3d.of(centeringDirection) + .scale(diffCenter * Math.min(Math.abs(movementSpeed), .1f) * 4); movement = movement.add(centering); float step = entityIn.stepHeight; @@ -141,11 +147,12 @@ public class BeltMovementHandler { // Entity Collisions if (Math.abs(movementSpeed) < .5f) { - Vector3d checkDistance = movement.normalize().scale(0.5); + Vector3d checkDistance = movement.normalize() + .scale(0.5); AxisAlignedBB bb = entityIn.getBoundingBox(); AxisAlignedBB checkBB = new AxisAlignedBB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ); - checkBB = checkBB.offset(checkDistance).grow(-Math.abs(checkDistance.x), -Math.abs(checkDistance.y), - -Math.abs(checkDistance.z)); + checkBB = checkBB.offset(checkDistance) + .grow(-Math.abs(checkDistance.x), -Math.abs(checkDistance.y), -Math.abs(checkDistance.z)); List list = world.getEntitiesWithinAABBExcludingEntity(entityIn, checkBB); list.removeIf(e -> shouldIgnoreBlocking(entityIn, e)); if (!list.isEmpty()) { @@ -173,7 +180,8 @@ public class BeltMovementHandler { entityIn.stepHeight = step; boolean movedPastEndingSlope = onSlope && (AllBlocks.BELT.has(world.getBlockState(entityIn.getBlockPos())) - || AllBlocks.BELT.has(world.getBlockState(entityIn.getBlockPos().down()))); + || AllBlocks.BELT.has(world.getBlockState(entityIn.getBlockPos() + .down()))); if (movedPastEndingSlope && !movingDown && Math.abs(movementSpeed) > 0) entityIn.setPosition(entityIn.getX(), entityIn.getY() + movement.y, entityIn.getZ()); @@ -188,7 +196,17 @@ public class BeltMovementHandler { return true; if (other instanceof HangingEntity) return true; - return me.isRidingOrBeingRiddenBy(other); + return isRidingOrBeingRiddenBy(me, other); + } + + public static boolean isRidingOrBeingRiddenBy(Entity me, Entity other) { + for (Entity entity : me.getPassengers()) { + if (entity.equals(other)) + return true; + if (isRidingOrBeingRiddenBy(entity, other)) + return true; + } + return false; } } diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicAndQuillHandler.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicAndQuillHandler.java index ce1de168f..c94618e6f 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicAndQuillHandler.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicAndQuillHandler.java @@ -213,7 +213,7 @@ public class SchematicAndQuillHandler { t.takeBlocksFromWorld(Minecraft.getInstance().world, origin, bounds, true, Blocks.AIR); if (string.isEmpty()) - string = Lang.translate("schematicAndQuill.fallbackName").getUnformattedComponentText(); + string = Lang.translate("schematicAndQuill.fallbackName").getString(); String folderPath = "schematics"; FilesHelper.createFolderIfMissing(folderPath); diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java b/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java index 9784fecef..266f1d387 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java @@ -71,7 +71,7 @@ public class Label extends AbstractSimiWidget { public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { if (!visible) return; - if (text == null || text.toString().isEmpty()) + if (text == null || text.getString().isEmpty()) return; RenderSystem.color4f(1, 1, 1, 1);