2021-07-12 23:52:54 +02:00
|
|
|
package com.jozufozu.flywheel.vanilla;
|
|
|
|
|
2022-06-20 08:25:44 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2022-05-12 03:42:31 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2022-04-11 02:02:28 +02:00
|
|
|
|
2022-06-20 08:25:44 +02:00
|
|
|
import com.jozufozu.flywheel.api.InstancedPart;
|
2022-05-16 05:09:47 +02:00
|
|
|
import com.jozufozu.flywheel.api.InstancerManager;
|
2022-01-04 06:41:08 +01:00
|
|
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
2022-05-16 05:09:47 +02:00
|
|
|
import com.jozufozu.flywheel.api.material.Material;
|
2022-01-04 06:41:08 +01:00
|
|
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
2022-05-01 04:42:57 +02:00
|
|
|
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
2021-12-22 09:22:41 +01:00
|
|
|
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
2022-05-16 05:09:47 +02:00
|
|
|
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
|
|
|
import com.jozufozu.flywheel.core.structs.StructTypes;
|
2022-06-20 08:25:44 +02:00
|
|
|
import com.jozufozu.flywheel.core.structs.oriented.OrientedPart;
|
2021-07-12 23:52:54 +02:00
|
|
|
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
|
|
|
|
2022-05-14 08:58:24 +02:00
|
|
|
import net.minecraft.client.renderer.Sheets;
|
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
|
|
|
|
2022-01-04 06:41:08 +01:00
|
|
|
public class BellInstance extends BlockEntityInstance<BellBlockEntity> implements DynamicInstance {
|
2021-07-12 23:52:54 +02:00
|
|
|
|
2022-05-21 06:14:31 +02:00
|
|
|
private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new Material(Sheets.solidBlockSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT));
|
2022-04-11 02:02:28 +02:00
|
|
|
|
2022-06-20 08:25:44 +02:00
|
|
|
private final OrientedPart bell;
|
2021-07-12 23:52:54 +02:00
|
|
|
|
2021-07-13 00:19:20 +02:00
|
|
|
private float lastRingTime = Float.NaN;
|
|
|
|
|
2022-05-16 05:09:47 +02:00
|
|
|
public BellInstance(InstancerManager instancerManager, BellBlockEntity blockEntity) {
|
|
|
|
super(instancerManager, blockEntity);
|
2021-07-12 23:52:54 +02:00
|
|
|
|
|
|
|
bell = createBellInstance()
|
|
|
|
.setPivot(0.5f, 0.75f, 0.5f)
|
|
|
|
.setPosition(getInstancePosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beginFrame() {
|
2022-01-04 06:41:08 +01:00
|
|
|
float ringTime = (float)blockEntity.ticks + AnimationTickHolder.getPartialTicks();
|
2021-07-13 00:19:20 +02:00
|
|
|
|
|
|
|
if (ringTime == lastRingTime) return;
|
|
|
|
lastRingTime = ringTime;
|
|
|
|
|
2022-01-04 06:41:08 +01: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 23:52:54 +02:00
|
|
|
|
2022-01-04 06:41:08 +01:00
|
|
|
Vector3f ringAxis = blockEntity.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);
|
|
|
|
}
|
|
|
|
|
2022-06-20 08:25:44 +02:00
|
|
|
@Override
|
|
|
|
public void addCrumblingParts(List<InstancedPart> data) {
|
|
|
|
Collections.addAll(data, bell);
|
|
|
|
}
|
|
|
|
|
2021-07-12 23:52:54 +02:00
|
|
|
@Override
|
|
|
|
public void remove() {
|
|
|
|
bell.delete();
|
|
|
|
}
|
|
|
|
|
2022-06-20 08:25:44 +02:00
|
|
|
private OrientedPart createBellInstance() {
|
2022-05-16 05:09:47 +02:00
|
|
|
return instancerManager.factory(StructTypes.ORIENTED)
|
2022-04-11 02:02:28 +02:00
|
|
|
.model(MODEL)
|
2021-07-12 23:52:54 +02:00
|
|
|
.createInstance();
|
|
|
|
}
|
|
|
|
|
2022-05-12 03:42:31 +02:00
|
|
|
@NotNull
|
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();
|
|
|
|
}
|
|
|
|
}
|