2021-07-19 00:05:12 +02:00
|
|
|
package com.jozufozu.flywheel.vanilla;
|
|
|
|
|
2021-09-30 22:42:17 +02:00
|
|
|
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
2021-07-19 00:05:12 +02:00
|
|
|
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
2021-07-24 08:46:30 +02:00
|
|
|
import com.jozufozu.flywheel.backend.material.MaterialManager;
|
2021-07-19 00:05:12 +02:00
|
|
|
import com.jozufozu.flywheel.core.Materials;
|
2021-09-12 23:49:00 +02:00
|
|
|
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
2021-07-19 00:05:12 +02:00
|
|
|
import com.jozufozu.flywheel.core.model.ModelPart;
|
|
|
|
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
|
|
|
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
|
2021-11-18 23:59:39 +01:00
|
|
|
import com.mojang.math.Quaternion;
|
|
|
|
import com.mojang.math.Vector3f;
|
2021-07-19 00:05:12 +02:00
|
|
|
|
2021-12-06 10:47:52 +01:00
|
|
|
import net.minecraft.client.renderer.RenderType;
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.client.renderer.Sheets;
|
2021-07-19 00:05:12 +02:00
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
2021-11-18 23:59:39 +01:00
|
|
|
import net.minecraft.core.Direction;
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.world.item.DyeColor;
|
2021-11-18 23:59:39 +01:00
|
|
|
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
|
2021-07-19 00:05:12 +02:00
|
|
|
|
2021-09-30 22:42:17 +02:00
|
|
|
public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity> implements IDynamicInstance {
|
2021-07-19 00:05:12 +02:00
|
|
|
|
|
|
|
private final TextureAtlasSprite texture;
|
|
|
|
|
|
|
|
private final ModelData base;
|
|
|
|
private final ModelData lid;
|
2021-11-24 00:07:31 +01:00
|
|
|
private final MatrixTransformStack stack = new MatrixTransformStack();
|
2021-07-19 00:05:12 +02:00
|
|
|
|
|
|
|
private float lastProgress = Float.NaN;
|
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
public ShulkerBoxInstance(MaterialManager materialManager, ShulkerBoxBlockEntity tile) {
|
2021-07-19 00:05:12 +02:00
|
|
|
super(materialManager, tile);
|
|
|
|
|
|
|
|
DyeColor color = tile.getColor();
|
|
|
|
if (color == null) {
|
2021-09-15 08:45:29 +02:00
|
|
|
texture = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION.sprite();
|
2021-07-19 00:05:12 +02:00
|
|
|
} else {
|
2021-09-15 08:45:29 +02:00
|
|
|
texture = Sheets.SHULKER_TEXTURE_LOCATION.get(color.getId()).sprite();
|
2021-07-19 00:05:12 +02:00
|
|
|
}
|
|
|
|
Quaternion rotation = getDirection().getRotation();
|
|
|
|
|
|
|
|
stack.translate(getInstancePosition())
|
|
|
|
.scale(0.9995f)
|
|
|
|
.translateAll(0.00025)
|
|
|
|
.centre()
|
|
|
|
.multiply(rotation)
|
|
|
|
.unCentre();
|
|
|
|
|
|
|
|
base = makeBaseInstance().setTransform(stack.unwrap());
|
|
|
|
|
|
|
|
stack.translateY(0.25);
|
|
|
|
|
|
|
|
lid = makeLidInstance().setTransform(stack.unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beginFrame() {
|
|
|
|
float progress = tile.getProgress(AnimationTickHolder.getPartialTicks());
|
|
|
|
|
|
|
|
if (progress == lastProgress) return;
|
|
|
|
lastProgress = progress;
|
|
|
|
|
|
|
|
Quaternion spin = Vector3f.YP.rotationDegrees(270.0F * progress);
|
|
|
|
|
2021-11-24 00:07:31 +01:00
|
|
|
stack.pushPose()
|
2021-07-19 00:05:12 +02:00
|
|
|
.centre()
|
|
|
|
.multiply(spin)
|
|
|
|
.unCentre()
|
|
|
|
.translateY(progress * 0.5f);
|
|
|
|
|
|
|
|
lid.setTransform(stack.unwrap());
|
|
|
|
|
2021-11-24 00:07:31 +01:00
|
|
|
stack.popPose();
|
2021-07-19 00:05:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove() {
|
|
|
|
base.delete();
|
|
|
|
lid.delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateLight() {
|
|
|
|
relight(pos, base, lid);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ModelData makeBaseInstance() {
|
2021-12-06 10:47:52 +01:00
|
|
|
return materialManager.cutout(RenderType.entityCutout(Sheets.SHULKER_SHEET))
|
2021-07-22 05:28:20 +02:00
|
|
|
.material(Materials.TRANSFORMED)
|
|
|
|
.model("base_" + texture.getName(), this::makeBaseModel)
|
2021-07-19 00:05:12 +02:00
|
|
|
.createInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
private ModelData makeLidInstance() {
|
2021-12-06 10:47:52 +01:00
|
|
|
return materialManager.cutout(RenderType.entityCutout(Sheets.SHULKER_SHEET))
|
2021-07-22 05:28:20 +02:00
|
|
|
.material(Materials.TRANSFORMED)
|
|
|
|
.model("lid_" + texture.getName(), this::makeLidModel)
|
2021-07-19 00:05:12 +02:00
|
|
|
.createInstance();
|
|
|
|
}
|
|
|
|
|
2021-07-23 21:26:32 +02:00
|
|
|
private ModelPart makeBaseModel() {
|
2021-11-09 05:48:02 +01:00
|
|
|
return ModelPart.builder("shulker_base", 64, 64)
|
2021-07-19 00:05:12 +02:00
|
|
|
.sprite(texture)
|
|
|
|
.cuboid()
|
|
|
|
.textureOffset(0, 28)
|
|
|
|
.size(16, 8, 16)
|
|
|
|
.invertYZ()
|
|
|
|
.endCuboid()
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
2021-07-23 21:26:32 +02:00
|
|
|
private ModelPart makeLidModel() {
|
2021-11-09 05:48:02 +01:00
|
|
|
return ModelPart.builder("shulker_lid", 64, 64)
|
2021-07-19 00:05:12 +02:00
|
|
|
.sprite(texture)
|
|
|
|
.cuboid()
|
|
|
|
.size(16, 12, 16)
|
|
|
|
.invertYZ()
|
|
|
|
.endCuboid()
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Direction getDirection() {
|
|
|
|
if (blockState.getBlock() instanceof ShulkerBoxBlock) {
|
|
|
|
return blockState.getValue(ShulkerBoxBlock.FACING);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Direction.UP;
|
|
|
|
}
|
|
|
|
}
|