Small things

- Fix minecarts rendering really far away
 - InstanceManager#getInstance now has one job
 - Instance creation moved to InstanceManager#addInternal
 - TransformStack#translateBack for Vec3i
This commit is contained in:
Jozufozu 2021-09-17 15:59:20 -07:00
parent 5044308c68
commit 5c5f48ba4a
4 changed files with 22 additions and 21 deletions

View file

@ -170,7 +170,7 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
.canUseInstancing()) return; .canUseInstancing()) return;
if (canInstance(obj)) { if (canInstance(obj)) {
AbstractInstance instance = getInstance(obj, false); AbstractInstance instance = getInstance(obj);
if (instance != null) { if (instance != null) {
@ -192,7 +192,7 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
.canUseInstancing()) return; .canUseInstancing()) return;
if (canInstance(obj)) { if (canInstance(obj)) {
AbstractInstance instance = getInstance(obj, false); AbstractInstance instance = getInstance(obj);
if (instance != null) removeInternal(obj, instance); if (instance != null) removeInternal(obj, instance);
} }
} }
@ -205,19 +205,11 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
} }
@Nullable @Nullable
protected <I extends T> AbstractInstance getInstance(I obj, boolean create) { protected <I extends T> AbstractInstance getInstance(I obj) {
if (!Backend.getInstance() if (!Backend.getInstance()
.canUseInstancing()) return null; .canUseInstancing()) return null;
AbstractInstance instance = instances.get(obj); return instances.get(obj);
if (instance != null) {
return instance;
} else if (create && canCreateInstance(obj)) {
return createInternal(obj);
} else {
return null;
}
} }
protected void processQueuedAdditions() { protected void processQueuedAdditions() {
@ -269,8 +261,15 @@ public abstract class InstanceManager<T> implements MaterialManagerImpl.OriginSh
return divisorSequence[Mth.clamp(i, 0, divisorSequence.length - 1)]; return divisorSequence[Mth.clamp(i, 0, divisorSequence.length - 1)];
} }
protected void addInternal(T tile) { protected void addInternal(T obj) {
getInstance(tile, true); if (!Backend.getInstance()
.canUseInstancing()) return;
AbstractInstance instance = instances.get(obj);
if (instance == null && canCreateInstance(obj)) {
createInternal(obj);
}
} }
protected void removeInternal(T obj, AbstractInstance instance) { protected void removeInternal(T obj, AbstractInstance instance) {

View file

@ -34,8 +34,6 @@ public class EntityInstanceManager extends InstanceManager<Entity> {
Level world = entity.level; Level world = entity.level;
if (world == null) return false;
if (Backend.isFlywheelWorld(world)) { if (Backend.isFlywheelWorld(world)) {
BlockPos pos = entity.blockPosition(); BlockPos pos = entity.blockPosition();

View file

@ -100,6 +100,10 @@ public interface TransformStack {
return translate(-vec.x, -vec.y, -vec.z); 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) { default TransformStack nudge(int id) {
long randomBits = (long) id * 31L * 493286711L; long randomBits = (long) id * 31L * 493286711L;
randomBits = randomBits * randomBits * 4392167121L + randomBits * 98761L; randomBits = randomBits * randomBits * 4392167121L + randomBits * 98761L;

View file

@ -12,6 +12,7 @@ import com.jozufozu.flywheel.core.model.ModelPart;
import com.jozufozu.flywheel.util.AnimationTickHolder; import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack; 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.RenderShape;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.entity.vehicle.AbstractMinecart;
@ -55,12 +56,11 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
stack.setIdentity(); stack.setIdentity();
float pt = AnimationTickHolder.getPartialTicks(); float pt = AnimationTickHolder.getPartialTicks();
Vec3i originCoordinate = materialManager.getOriginCoordinate();
stack.translate( stack.translate(
Mth.lerp(pt, entity.xOld, entity.getX()), Mth.lerp(pt, entity.xOld, entity.getX()) - originCoordinate.getX(),
Mth.lerp(pt, entity.yOld, entity.getY()), Mth.lerp(pt, entity.yOld, entity.getY()) - originCoordinate.getY(),
Mth.lerp(pt, entity.zOld, entity.getZ()) Mth.lerp(pt, entity.zOld, entity.getZ()) - originCoordinate.getZ());
);
float yaw = Mth.lerp(pt, entity.yRotO, entity.getYRot()); float yaw = Mth.lerp(pt, entity.yRotO, entity.getYRot());