mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 07:49:29 +00:00
90 lines
4.9 KiB
Diff
90 lines
4.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Fri, 9 Aug 2024 20:43:53 +0100
|
|
Subject: [PATCH] Configurable left shooting and adjusting limits
|
|
|
|
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 8548a41641534fabf44658f014d86df6d27046a0..6cd8e8bae0c62799fde7533f994eb71bf133fe35 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -598,6 +598,46 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return Math.max(x, z) >= this.travelDistanceLimit;
|
|
}
|
|
// Sakura end - entity travel distance limits
|
|
+ // Sakura start - configurable left shooting and adjusting limits
|
|
+ protected final void limitLeftShooting() {
|
|
+ Vec3 movement = this.getDeltaMovement();
|
|
+ int threshold = this.level.sakuraConfig().cannons.restrictions.leftShootingThreshold.or(-1);
|
|
+ if (threshold > 0 && (movement.x != 0.0 || movement.z != 0.0) && this.origin != null) {
|
|
+ double travelledX = Math.abs(this.getX() - this.origin.x());
|
|
+ double travelledZ = Math.abs(this.getZ() - this.origin.z());
|
|
+ boolean xSmaller = travelledX < travelledZ; // intended
|
|
+
|
|
+ // Once entities have travelled past the threshold changing direction is restricted.
|
|
+ if (xSmaller && travelledX > threshold) {
|
|
+ this.setDeltaMovement(movement.multiply(1.0, 1.0, 0.0)); // limit z
|
|
+ } else if (!xSmaller && travelledZ > threshold) {
|
|
+ this.setDeltaMovement(movement.multiply(0.0, 1.0, 1.0)); // limit x
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void limitAdjustMovement(AABB currBoundingBox, double dir, boolean xAdjust, List<VoxelShape> shapes) {
|
|
+ int adjustDistance = this.level.sakuraConfig().cannons.restrictions.maxAdjustDistance.or(-1);
|
|
+ if (adjustDistance > 0 && Math.abs(dir) > adjustDistance) {
|
|
+ double minX = Double.NEGATIVE_INFINITY;
|
|
+ double minZ = Double.NEGATIVE_INFINITY;
|
|
+ double maxX = Double.POSITIVE_INFINITY;
|
|
+ double maxZ = Double.POSITIVE_INFINITY;
|
|
+ if (xAdjust) { // limit x adjust
|
|
+ minX = Math.floor(currBoundingBox.minX) - adjustDistance;
|
|
+ maxX = Math.floor(currBoundingBox.maxX) + adjustDistance + 1;
|
|
+ } else { // limit z adjust
|
|
+ minZ = Math.floor(currBoundingBox.minZ) - adjustDistance;
|
|
+ maxZ = Math.floor(currBoundingBox.maxZ) + adjustDistance + 1;
|
|
+ }
|
|
+ VoxelShape safeSpace = Shapes.box(
|
|
+ minX, Double.NEGATIVE_INFINITY, minZ,
|
|
+ maxX, Double.POSITIVE_INFINITY, maxZ
|
|
+ );
|
|
+ shapes.add(Shapes.join(Shapes.INFINITY, safeSpace, BooleanOp.ONLY_FIRST));
|
|
+ }
|
|
+ }
|
|
+ // Sakura end - configurable left shooting and adjusting limits
|
|
|
|
public Entity(EntityType<?> entityType, Level level) {
|
|
this.type = entityType;
|
|
@@ -1606,6 +1646,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
|
|
if (xSmaller && z != 0.0) {
|
|
+ this.limitAdjustMovement(currBoundingBox, z, false, voxelList); // Sakura - configurable left shooting and adjusting limits
|
|
z = this.scanZ(currBoundingBox, z, voxelList, bbList);
|
|
if (z != 0.0) {
|
|
currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetZ(currBoundingBox, z);
|
|
@@ -1613,6 +1654,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
|
|
if (x != 0.0) {
|
|
+ // Sakura start - configurable left shooting and adjusting limits
|
|
+ if (!xSmaller) {
|
|
+ this.limitAdjustMovement(currBoundingBox, x, true, voxelList);
|
|
+ }
|
|
+ // Sakura end - configurable left shooting and adjusting limits
|
|
x = this.scanX(currBoundingBox, x, voxelList, bbList);
|
|
if (x != 0.0) {
|
|
currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetX(currBoundingBox, x);
|
|
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
index 3b83c101fd5583f45fdd6fa20e92bc17318fad6b..60e1c2acb267eb277ba06903002a8d687fb309d0 100644
|
|
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -285,6 +285,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
|
|
// Sakura end - configure cannon physics
|
|
this.time++;
|
|
this.applyGravity();
|
|
+ this.limitLeftShooting(); // Sakura - configurable left shooting and adjusting limits
|
|
this.move(MoverType.SELF, this.getDeltaMovement());
|
|
this.applyEffectsFromBlocks();
|
|
// Paper start - Configurable falling blocks height nerf
|