2021-07-19 00:05:12 +02:00
|
|
|
package com.jozufozu.flywheel.vanilla;
|
|
|
|
|
2022-04-11 02:02:28 +02:00
|
|
|
import java.util.function.Function;
|
|
|
|
|
2021-12-15 07:00:44 +01:00
|
|
|
import com.jozufozu.flywheel.api.MaterialManager;
|
2022-01-04 06:41:08 +01:00
|
|
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
2022-05-01 04:42:57 +02:00
|
|
|
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
2021-12-22 09:22:41 +01:00
|
|
|
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
2022-05-15 10:58:33 +02:00
|
|
|
import com.jozufozu.flywheel.core.materials.Materials;
|
2022-01-04 06:41:08 +01:00
|
|
|
import com.jozufozu.flywheel.core.materials.model.ModelData;
|
2021-07-19 00:05:12 +02:00
|
|
|
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
2022-02-09 04:26:36 +01:00
|
|
|
import com.jozufozu.flywheel.util.transform.TransformStack;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
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
|
|
|
|
2022-04-11 02:02:28 +02:00
|
|
|
import net.minecraft.Util;
|
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
|
|
|
|
2022-01-04 06:41:08 +01:00
|
|
|
public class ShulkerBoxInstance extends BlockEntityInstance<ShulkerBoxBlockEntity> implements DynamicInstance {
|
2021-07-19 00:05:12 +02:00
|
|
|
|
2022-05-01 04:42:57 +02:00
|
|
|
private static final Function<TextureAtlasSprite, BasicModelSupplier> BASE = Util.memoize(it -> new BasicModelSupplier(() -> makeBaseModel(it), RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET)));
|
|
|
|
private static final Function<TextureAtlasSprite, BasicModelSupplier> LID = Util.memoize(it -> new BasicModelSupplier(() -> makeLidModel(it), RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET)));
|
2022-04-11 02:02:28 +02:00
|
|
|
|
2021-07-19 00:05:12 +02:00
|
|
|
private final TextureAtlasSprite texture;
|
|
|
|
|
|
|
|
private final ModelData base;
|
|
|
|
private final ModelData lid;
|
2022-02-09 04:26:36 +01:00
|
|
|
private final PoseStack stack = new PoseStack();
|
2021-07-19 00:05:12 +02:00
|
|
|
|
|
|
|
private float lastProgress = Float.NaN;
|
|
|
|
|
2022-01-04 06:41:08 +01:00
|
|
|
public ShulkerBoxInstance(MaterialManager materialManager, ShulkerBoxBlockEntity blockEntity) {
|
|
|
|
super(materialManager, blockEntity);
|
2021-07-19 00:05:12 +02:00
|
|
|
|
2022-01-04 06:41:08 +01:00
|
|
|
DyeColor color = blockEntity.getColor();
|
2021-07-19 00:05:12 +02:00
|
|
|
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();
|
|
|
|
|
2022-02-09 04:26:36 +01:00
|
|
|
TransformStack tstack = TransformStack.cast(stack);
|
|
|
|
|
|
|
|
tstack.translate(getInstancePosition())
|
2021-07-19 00:05:12 +02:00
|
|
|
.scale(0.9995f)
|
|
|
|
.translateAll(0.00025)
|
|
|
|
.centre()
|
|
|
|
.multiply(rotation)
|
|
|
|
.unCentre();
|
|
|
|
|
2022-02-09 04:26:36 +01:00
|
|
|
base = makeBaseInstance().setTransform(stack);
|
2021-07-19 00:05:12 +02:00
|
|
|
|
2022-02-09 04:26:36 +01:00
|
|
|
tstack.translateY(0.25);
|
2021-07-19 00:05:12 +02:00
|
|
|
|
2022-02-09 04:26:36 +01:00
|
|
|
lid = makeLidInstance().setTransform(stack);
|
2021-07-19 00:05:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beginFrame() {
|
2022-01-04 06:41:08 +01:00
|
|
|
float progress = blockEntity.getProgress(AnimationTickHolder.getPartialTicks());
|
2021-07-19 00:05:12 +02:00
|
|
|
|
|
|
|
if (progress == lastProgress) return;
|
|
|
|
lastProgress = progress;
|
|
|
|
|
|
|
|
Quaternion spin = Vector3f.YP.rotationDegrees(270.0F * progress);
|
|
|
|
|
2022-04-12 00:11:39 +02:00
|
|
|
TransformStack.cast(stack)
|
|
|
|
.pushPose()
|
2021-07-19 00:05:12 +02:00
|
|
|
.centre()
|
|
|
|
.multiply(spin)
|
|
|
|
.unCentre()
|
|
|
|
.translateY(progress * 0.5f);
|
|
|
|
|
2022-02-09 04:26:36 +01:00
|
|
|
lid.setTransform(stack);
|
2021-07-19 00:05:12 +02:00
|
|
|
|
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() {
|
2022-04-12 00:11:39 +02:00
|
|
|
return materialManager.material(Materials.TRANSFORMED)
|
2022-04-11 02:02:28 +02:00
|
|
|
.model(BASE.apply(texture))
|
2021-07-19 00:05:12 +02:00
|
|
|
.createInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
private ModelData makeLidInstance() {
|
2022-04-12 00:11:39 +02:00
|
|
|
return materialManager.material(Materials.TRANSFORMED)
|
2022-04-11 02:02:28 +02:00
|
|
|
.model(LID.apply(texture))
|
2021-07-19 00:05:12 +02:00
|
|
|
.createInstance();
|
|
|
|
}
|
|
|
|
|
2022-04-11 02:02:28 +02:00
|
|
|
private static ModelPart makeBaseModel(TextureAtlasSprite texture) {
|
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();
|
|
|
|
}
|
|
|
|
|
2022-04-11 02:02:28 +02:00
|
|
|
private static ModelPart makeLidModel(TextureAtlasSprite texture) {
|
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;
|
|
|
|
}
|
|
|
|
}
|