mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-24 20:07:54 +01:00
A little encapsulation goes a long way
- Encapsulate instancerProvider and renderOrigin in AbstractVisual - Saves 8 bytes per visual
This commit is contained in:
parent
b24e87262b
commit
5299571540
7 changed files with 18 additions and 11 deletions
|
@ -52,7 +52,7 @@ public abstract class AbstractBlockEntityVisual<T extends BlockEntity> extends A
|
|||
this.blockEntity = blockEntity;
|
||||
this.pos = blockEntity.getBlockPos();
|
||||
this.blockState = blockEntity.getBlockState();
|
||||
this.visualPos = pos.subtract(renderOrigin);
|
||||
this.visualPos = pos.subtract(ctx.renderOrigin());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -67,6 +67,7 @@ public abstract class AbstractEntityVisual<T extends Entity> extends AbstractVis
|
|||
*/
|
||||
public Vector3f getVisualPosition() {
|
||||
Vec3 pos = entity.position();
|
||||
var renderOrigin = renderOrigin();
|
||||
return new Vector3f((float) (pos.x - renderOrigin.getX()),
|
||||
(float) (pos.y - renderOrigin.getY()),
|
||||
(float) (pos.z - renderOrigin.getZ()));
|
||||
|
@ -81,6 +82,7 @@ public abstract class AbstractEntityVisual<T extends Entity> extends AbstractVis
|
|||
*/
|
||||
public Vector3f getVisualPosition(float partialTick) {
|
||||
Vec3 pos = entity.position();
|
||||
var renderOrigin = renderOrigin();
|
||||
return new Vector3f((float) (Mth.lerp(partialTick, entity.xOld, pos.x) - renderOrigin.getX()),
|
||||
(float) (Mth.lerp(partialTick, entity.yOld, pos.y) - renderOrigin.getY()),
|
||||
(float) (Mth.lerp(partialTick, entity.zOld, pos.z) - renderOrigin.getZ()));
|
||||
|
|
|
@ -13,16 +13,12 @@ public abstract class AbstractVisual implements Visual {
|
|||
* Useful for passing to child visuals.
|
||||
*/
|
||||
protected final VisualizationContext visualizationContext;
|
||||
protected final InstancerProvider instancerProvider;
|
||||
protected final Vec3i renderOrigin;
|
||||
protected final Level level;
|
||||
|
||||
protected boolean deleted = false;
|
||||
|
||||
public AbstractVisual(VisualizationContext ctx, Level level, float partialTick) {
|
||||
this.visualizationContext = ctx;
|
||||
this.instancerProvider = ctx.instancerProvider();
|
||||
this.renderOrigin = ctx.renderOrigin();
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
|
@ -32,6 +28,14 @@ public abstract class AbstractVisual implements Visual {
|
|||
|
||||
protected abstract void _delete();
|
||||
|
||||
protected InstancerProvider instancerProvider() {
|
||||
return visualizationContext.instancerProvider();
|
||||
}
|
||||
|
||||
protected Vec3i renderOrigin() {
|
||||
return visualizationContext.renderOrigin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void delete() {
|
||||
if (deleted) {
|
||||
|
|
|
@ -46,7 +46,7 @@ public class BellVisual extends AbstractBlockEntityVisual<BellBlockEntity> imple
|
|||
}
|
||||
|
||||
private OrientedInstance createBellInstance() {
|
||||
return instancerProvider.instancer(InstanceTypes.ORIENTED, BELL_MODEL.get())
|
||||
return instancerProvider().instancer(InstanceTypes.ORIENTED, BELL_MODEL.get())
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
|||
ChestType chestType = blockState.hasProperty(ChestBlock.TYPE) ? blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
|
||||
TextureAtlasSprite sprite = Sheets.chooseMaterial(blockEntity, chestType, isChristmas()).sprite();
|
||||
|
||||
instances = InstanceTree.create(instancerProvider, LAYER_LOCATIONS.get(chestType), (path, mesh) -> {
|
||||
instances = InstanceTree.create(instancerProvider(), LAYER_LOCATIONS.get(chestType), (path, mesh) -> {
|
||||
return new Model.ConfiguredMesh(MATERIAL, new RetexturedMesh(mesh, sprite));
|
||||
});
|
||||
lid = instances.childOrThrow("lid");
|
||||
|
|
|
@ -82,7 +82,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends ComponentEntityV
|
|||
}
|
||||
|
||||
private TransformedInstance createBodyInstance() {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, bodyModel.get())
|
||||
return instancerProvider().instancer(InstanceTypes.TRANSFORMED, bodyModel.get())
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends ComponentEntityV
|
|||
return null;
|
||||
}
|
||||
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.block(blockState))
|
||||
return instancerProvider().instancer(InstanceTypes.TRANSFORMED, Models.block(blockState))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
@ -141,6 +141,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends ComponentEntityV
|
|||
double posY = Mth.lerp(partialTick, entity.yOld, entity.getY());
|
||||
double posZ = Mth.lerp(partialTick, entity.zOld, entity.getZ());
|
||||
|
||||
var renderOrigin = renderOrigin();
|
||||
stack.translate(posX - renderOrigin.getX(), posY - renderOrigin.getY(), posZ - renderOrigin.getZ());
|
||||
float yaw = Mth.lerp(partialTick, entity.yRotO, entity.getYRot());
|
||||
|
||||
|
|
|
@ -78,12 +78,12 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
|||
}
|
||||
|
||||
private TransformedInstance createBaseInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, BASE_MODELS.get(texture))
|
||||
return instancerProvider().instancer(InstanceTypes.TRANSFORMED, BASE_MODELS.get(texture))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
private TransformedInstance createLidInstance(Material texture) {
|
||||
return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(texture))
|
||||
return instancerProvider().instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(texture))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue