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