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;
if (canInstance(obj)) {
AbstractInstance instance = getInstance(obj, false);
AbstractInstance instance = getInstance(obj);
if (instance != null) {
@ -192,7 +192,7 @@ public abstract class InstanceManager<T> 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<T> implements MaterialManagerImpl.OriginSh
}
@Nullable
protected <I extends T> AbstractInstance getInstance(I obj, boolean create) {
protected <I extends T> 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<T> 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) {

View file

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

View file

@ -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;

View file

@ -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<T extends AbstractMinecart> 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());