diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java index 864706ca9..573d3fac2 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -170,7 +170,7 @@ public abstract class InstanceManager implements MaterialManagerImpl.OriginSh .canUseInstancing()) return; if (canInstance(obj)) { - AbstractInstance instance = getInstance(obj, false); + AbstractInstance instance = getInstance(obj); if (instance != null) { @@ -192,7 +192,7 @@ public abstract class InstanceManager implements MaterialManagerImpl.OriginSh .canUseInstancing()) return; if (canInstance(obj)) { - AbstractInstance instance = getInstance(obj, false); + AbstractInstance instance = getInstance(obj); if (instance != null) removeInternal(obj, instance); } } @@ -205,19 +205,11 @@ public abstract class InstanceManager implements MaterialManagerImpl.OriginSh } @Nullable - protected AbstractInstance getInstance(I obj, boolean create) { + protected AbstractInstance getInstance(I obj) { if (!Backend.getInstance() .canUseInstancing()) return null; - AbstractInstance instance = instances.get(obj); - - if (instance != null) { - return instance; - } else if (create && canCreateInstance(obj)) { - return createInternal(obj); - } else { - return null; - } + return instances.get(obj); } protected void processQueuedAdditions() { @@ -269,8 +261,15 @@ public abstract class InstanceManager implements MaterialManagerImpl.OriginSh return divisorSequence[Mth.clamp(i, 0, divisorSequence.length - 1)]; } - protected void addInternal(T tile) { - getInstance(tile, true); + protected void addInternal(T obj) { + if (!Backend.getInstance() + .canUseInstancing()) return; + + AbstractInstance instance = instances.get(obj); + + if (instance == null && canCreateInstance(obj)) { + createInternal(obj); + } } protected void removeInternal(T obj, AbstractInstance instance) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java index b98ea2d88..2cbca481e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java @@ -34,8 +34,6 @@ public class EntityInstanceManager extends InstanceManager { Level world = entity.level; - if (world == null) return false; - if (Backend.isFlywheelWorld(world)) { BlockPos pos = entity.blockPosition(); diff --git a/src/main/java/com/jozufozu/flywheel/util/transform/TransformStack.java b/src/main/java/com/jozufozu/flywheel/util/transform/TransformStack.java index 8bbe0c03d..0a704f90d 100644 --- a/src/main/java/com/jozufozu/flywheel/util/transform/TransformStack.java +++ b/src/main/java/com/jozufozu/flywheel/util/transform/TransformStack.java @@ -100,6 +100,10 @@ public interface TransformStack { return translate(-vec.x, -vec.y, -vec.z); } + default TransformStack translateBack(Vec3i vec) { + return translate(-vec.getX(), -vec.getY(), -vec.getZ()); + } + default TransformStack nudge(int id) { long randomBits = (long) id * 31L * 493286711L; randomBits = randomBits * randomBits * 4392167121L + randomBits * 98761L; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java index b5b19b293..820b4d364 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java @@ -12,6 +12,7 @@ import com.jozufozu.flywheel.core.model.ModelPart; import com.jozufozu.flywheel.util.AnimationTickHolder; import com.jozufozu.flywheel.util.transform.MatrixTransformStack; +import net.minecraft.core.Vec3i; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.entity.vehicle.AbstractMinecart; @@ -55,12 +56,11 @@ public class MinecartInstance extends EntityInstance stack.setIdentity(); float pt = AnimationTickHolder.getPartialTicks(); + Vec3i originCoordinate = materialManager.getOriginCoordinate(); stack.translate( - Mth.lerp(pt, entity.xOld, entity.getX()), - Mth.lerp(pt, entity.yOld, entity.getY()), - Mth.lerp(pt, entity.zOld, entity.getZ()) - ); - + Mth.lerp(pt, entity.xOld, entity.getX()) - originCoordinate.getX(), + Mth.lerp(pt, entity.yOld, entity.getY()) - originCoordinate.getY(), + Mth.lerp(pt, entity.zOld, entity.getZ()) - originCoordinate.getZ()); float yaw = Mth.lerp(pt, entity.yRotO, entity.getYRot());