Flywheel/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java

81 lines
2.2 KiB
Java
Raw Normal View History

package com.jozufozu.flywheel.vanilla;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
2021-07-24 08:46:30 +02:00
import com.jozufozu.flywheel.backend.material.MaterialManager;
import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.core.model.ModelPart;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.blockentity.BellRenderer;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.entity.BellBlockEntity;
public class BellInstance extends TileEntityInstance<BellBlockEntity> implements IDynamicInstance {
private final OrientedData bell;
private float lastRingTime = Float.NaN;
public BellInstance(MaterialManager materialManager, BellBlockEntity tile) {
super(materialManager, tile);
bell = createBellInstance()
.setPivot(0.5f, 0.75f, 0.5f)
.setPosition(getInstancePosition());
}
@Override
public void beginFrame() {
2021-07-15 20:36:24 +02:00
float ringTime = (float)tile.ticks + AnimationTickHolder.getPartialTicks();
if (ringTime == lastRingTime) return;
lastRingTime = ringTime;
2021-07-15 20:36:24 +02:00
if (tile.shaking) {
float angle = Mth.sin(ringTime / (float) Math.PI) / (4.0F + ringTime / 3.0F);
2021-07-15 20:36:24 +02:00
Vector3f ringAxis = tile.clickDirection.getCounterClockWise().step();
2021-07-15 20:36:24 +02:00
bell.setRotation(ringAxis.rotation(angle));
} else {
2021-07-15 20:36:24 +02:00
bell.setRotation(Quaternion.ONE);
}
}
@Override
public void updateLight() {
relight(getWorldPosition(), bell);
}
@Override
public void remove() {
bell.delete();
}
private OrientedData createBellInstance() {
return materialManager.defaultCutout()
.material(Materials.ORIENTED)
.model(tile.getType(), BellInstance::createBellModel)
.createInstance();
}
private static ModelPart createBellModel() {
2021-11-09 05:48:02 +01:00
return ModelPart.builder("bell", 32, 32)
.sprite(BellRenderer.BELL_RESOURCE_LOCATION.sprite())
.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();
}
}