2021-07-12 23:52:54 +02:00
|
|
|
package com.jozufozu.flywheel.vanilla;
|
|
|
|
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
|
|
|
|
import com.jozufozu.flywheel.backend.model.BufferedModel;
|
|
|
|
import com.jozufozu.flywheel.core.Materials;
|
|
|
|
import com.jozufozu.flywheel.core.materials.OrientedData;
|
|
|
|
import com.jozufozu.flywheel.core.model.ModelPart;
|
|
|
|
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.tileentity.BellTileEntityRenderer;
|
|
|
|
import net.minecraft.tileentity.BellTileEntity;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
2021-07-13 00:19:20 +02:00
|
|
|
import net.minecraft.util.math.vector.Quaternion;
|
2021-07-12 23:52:54 +02:00
|
|
|
import net.minecraft.util.math.vector.Vector3f;
|
|
|
|
|
|
|
|
public class BellInstance extends TileEntityInstance<BellTileEntity> implements IDynamicInstance {
|
|
|
|
|
|
|
|
private final OrientedData bell;
|
|
|
|
|
2021-07-13 00:19:20 +02:00
|
|
|
private float lastRingTime = Float.NaN;
|
|
|
|
|
2021-07-12 23:52:54 +02:00
|
|
|
public BellInstance(MaterialManager<?> materialManager, BellTileEntity tile) {
|
|
|
|
super(materialManager, tile);
|
|
|
|
|
|
|
|
bell = createBellInstance()
|
|
|
|
.setPivot(0.5f, 0.75f, 0.5f)
|
|
|
|
.setPosition(getInstancePosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beginFrame() {
|
2021-07-13 00:19:20 +02:00
|
|
|
float ringTime = (float)tile.ringingTicks + AnimationTickHolder.getPartialTicks();
|
|
|
|
|
|
|
|
if (ringTime == lastRingTime) return;
|
|
|
|
lastRingTime = ringTime;
|
|
|
|
|
2021-07-12 23:52:54 +02:00
|
|
|
if (tile.isRinging) {
|
2021-07-13 00:19:20 +02:00
|
|
|
float angle = MathHelper.sin(ringTime / (float) Math.PI) / (4.0F + ringTime / 3.0F);
|
2021-07-12 23:52:54 +02:00
|
|
|
|
|
|
|
Vector3f ringAxis = tile.ringDirection.rotateYCCW().getUnitVector();
|
|
|
|
|
|
|
|
bell.setRotation(ringAxis.getRadialQuaternion(angle));
|
2021-07-13 00:19:20 +02:00
|
|
|
} else {
|
|
|
|
bell.setRotation(Quaternion.IDENTITY);
|
2021-07-12 23:52:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateLight() {
|
|
|
|
relight(getWorldPosition(), bell);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove() {
|
|
|
|
bell.delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
private OrientedData createBellInstance() {
|
|
|
|
return materialManager.getMaterial(Materials.ORIENTED)
|
|
|
|
.get(tile.getType(), BellInstance::createBellModel)
|
|
|
|
.createInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static BufferedModel createBellModel() {
|
|
|
|
return ModelPart.builder(32, 32)
|
|
|
|
.sprite(BellTileEntityRenderer.field_217653_c.getSprite())
|
|
|
|
.cuboid()
|
|
|
|
.start(5.0F, 6.0F, 5.0F)
|
|
|
|
.size(6.0F, 7.0F, 6.0F)
|
|
|
|
.endCuboid()
|
|
|
|
.cuboid()
|
|
|
|
.textureOffset(0, 13)
|
|
|
|
.start(4.0F, 4.0F, 4.0F)
|
|
|
|
.size(8.0F, 2.0F, 8.0F)
|
|
|
|
.endCuboid()
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|