2021-07-12 14:52:54 -07:00
|
|
|
package com.jozufozu.flywheel.vanilla;
|
|
|
|
|
2022-05-11 18:42:31 -07:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2022-04-10 17:02:28 -07:00
|
|
|
|
2021-12-14 22:00:44 -08:00
|
|
|
import com.jozufozu.flywheel.api.MaterialManager;
|
2022-01-03 21:41:08 -08:00
|
|
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
2022-04-30 19:42:57 -07:00
|
|
|
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
2022-05-11 18:42:31 -07:00
|
|
|
import com.jozufozu.flywheel.core.Materials;
|
2021-12-22 00:22:41 -08:00
|
|
|
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
2022-01-03 21:41:08 -08:00
|
|
|
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
2021-07-12 14:52:54 -07:00
|
|
|
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
|
|
|
|
2022-04-11 15:11:39 -07:00
|
|
|
import net.minecraft.client.renderer.RenderType;
|
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
|
|
|
|
2022-01-03 21:41:08 -08:00
|
|
|
public class BellInstance extends BlockEntityInstance<BellBlockEntity> implements DynamicInstance {
|
2021-07-12 14:52:54 -07:00
|
|
|
|
2022-04-30 19:42:57 -07:00
|
|
|
private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, RenderType.cutoutMipped());
|
2022-04-10 17:02:28 -07:00
|
|
|
|
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;
|
|
|
|
|
2022-01-03 21:41:08 -08:00
|
|
|
public BellInstance(MaterialManager materialManager, BellBlockEntity blockEntity) {
|
|
|
|
super(materialManager, blockEntity);
|
2021-07-12 14:52:54 -07:00
|
|
|
|
|
|
|
bell = createBellInstance()
|
|
|
|
.setPivot(0.5f, 0.75f, 0.5f)
|
|
|
|
.setPosition(getInstancePosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beginFrame() {
|
2022-01-03 21:41:08 -08:00
|
|
|
float ringTime = (float)blockEntity.ticks + AnimationTickHolder.getPartialTicks();
|
2021-07-12 15:19:20 -07:00
|
|
|
|
|
|
|
if (ringTime == lastRingTime) return;
|
|
|
|
lastRingTime = ringTime;
|
|
|
|
|
2022-01-03 21:41:08 -08:00
|
|
|
if (blockEntity.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
|
|
|
|
2022-01-03 21:41:08 -08:00
|
|
|
Vector3f ringAxis = blockEntity.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() {
|
2022-04-11 15:11:39 -07:00
|
|
|
return materialManager.material(Materials.ORIENTED)
|
2022-04-10 17:02:28 -07:00
|
|
|
.model(MODEL)
|
2021-07-12 14:52:54 -07:00
|
|
|
.createInstance();
|
|
|
|
}
|
|
|
|
|
2022-05-11 18:42:31 -07:00
|
|
|
@NotNull
|
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();
|
|
|
|
}
|
|
|
|
}
|