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