Skip to content

Commit

Permalink
Significantly Optimize And Improve MC LIVE Tendrils
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Nov 27, 2024
1 parent e2fdd38 commit d7a0131
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 947 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Put the changelog BELOW the dashes. ANYTHING ABOVE IS IGNORED
hi
-----------------
- Dark Oak Forests no longer use the warm water color.
- Significantly optimized Sculk Sensor rendering with the `Minecraft Live Tendrils` resource pack.
- Fixed many recipe unlocks being broken in 1.21.2+.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package net.frozenblock.wilderwild.block.entity.impl;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -49,4 +50,8 @@ public interface SculkSensorTickInterface {

void wilderWild$setPrevActive(boolean active);

Direction wilderWild$getFacing();

void wilderWild$setFacing(Direction facing);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package net.frozenblock.wilderwild.entity.render.blockentity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.frozenblock.wilderwild.WWConstants;
Expand All @@ -41,52 +42,67 @@
@Environment(EnvType.CLIENT)
public class SculkSensorBlockEntityRenderer<T extends SculkSensorBlockEntity> implements BlockEntityRenderer<T> {
private static final float RAD_25 = 25F * Mth.DEG_TO_RAD;
private static final RenderType SENSOR_LAYER = RenderType.entityCutout(WWConstants.id("textures/entity/sculk_sensor/inactive.png"));
private static final float TENDRIL_ANGLE = 45F * Mth.DEG_TO_RAD;
private static final float TENDRIL_ANGLE_SOUTH = 225F * Mth.DEG_TO_RAD;
private static final RenderType ACTIVE_SENSOR_LAYER = RenderType.entityCutout(WWConstants.id("textures/entity/sculk_sensor/active.png"));
private final ModelPart root;
private final ModelPart ne;
private final ModelPart se;
private final ModelPart nw;
private final ModelPart sw;
private final ModelPart tendril1;
private final ModelPart tendril2;
private final ModelPart tendril3;
private final ModelPart tendril4;

public SculkSensorBlockEntityRenderer(@NotNull Context ctx) {
this.root = ctx.bakeLayer(WWModelLayers.SCULK_SENSOR);
this.ne = this.root.getChild("ne");
this.se = this.root.getChild("se");
this.nw = this.root.getChild("nw");
this.sw = this.root.getChild("sw");
this.tendril1 = this.root.getChild("tendril1");
this.tendril2 = this.root.getChild("tendril2");
this.tendril3 = this.root.getChild("tendril3");
this.tendril4 = this.root.getChild("tendril4");
}

@NotNull
public static LayerDefinition getTexturedModelData() {
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
CubeListBuilder tendril = CubeListBuilder.create().texOffs(0, 0).addBox(-4F, -8F, 0F, 8F, 8F, 0.002F);
modelPartData.addOrReplaceChild("ne", tendril, PartPose.offsetAndRotation(3F, 8F, 3F, 0, -0.7854F, Mth.PI));
modelPartData.addOrReplaceChild("se", tendril, PartPose.offsetAndRotation(3F, 8F, 13F, 0, 0.7854F, Mth.PI));
modelPartData.addOrReplaceChild("nw", tendril, PartPose.offsetAndRotation(13F, 8F, 13F, 0, -0.7854F, Mth.PI));
modelPartData.addOrReplaceChild("sw", tendril, PartPose.offsetAndRotation(13F, 8F, 3F, 0, 0.7854F, Mth.PI));
modelPartData.addOrReplaceChild(
"tendril1",
CubeListBuilder.create().texOffs(0, 0).addBox(-4F, -8F, 0F, 8F, 8F, 0.001F),
PartPose.offsetAndRotation(3F, 8F, 3F, 0, -TENDRIL_ANGLE, Mth.PI)
);
modelPartData.addOrReplaceChild(
"tendril2",
CubeListBuilder.create().texOffs(0, 0).mirror().addBox(-4F, -8F, 0F, 8F, 8F, 0.001F),
PartPose.offsetAndRotation(13F, 8F, 3F, 0, TENDRIL_ANGLE, Mth.PI)
);
modelPartData.addOrReplaceChild(
"tendril3",
CubeListBuilder.create().texOffs(0, 0).addBox(-4F, -8F, 0F, 8F, 8F, 0.001F),
PartPose.offsetAndRotation(13F, 8F, 13F, 0, -TENDRIL_ANGLE_SOUTH, Mth.PI)
);
modelPartData.addOrReplaceChild(
"tendril4",
CubeListBuilder.create().texOffs(0, 0).mirror().addBox(-4F, -8F, 0F, 8F, 8F, 0.001F),
PartPose.offsetAndRotation(3F, 8F, 13F, 0, TENDRIL_ANGLE_SOUTH, Mth.PI)
);
return LayerDefinition.create(modelData, 64, 64);
}

@Override
public void render(@NotNull T entity, float partialTick, @NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer, int light, int overlay) {
if (WWConstants.MC_LIVE_TENDRILS) {
SculkSensorTickInterface tickInterface = ((SculkSensorTickInterface) entity);
if (tickInterface.wilderWild$isActive()) {
int prevTicks = tickInterface.wilderWild$getPrevAnimTicks();
float xRot = (prevTicks + partialTick * (tickInterface.wilderWild$getAnimTicks() - prevTicks)) * 0.1F * ((float) Math.cos((tickInterface.wilderWild$getAge() + partialTick) * 2.25F) * RAD_25);
this.ne.xRot = xRot;
this.se.xRot = -xRot;
this.nw.xRot = -xRot;
this.sw.xRot = xRot;
if (WWConstants.MC_LIVE_TENDRILS && entity instanceof SculkSensorTickInterface sculkSensorTickInterface) {
if (sculkSensorTickInterface.wilderWild$isActive()) {
int prevTicks = sculkSensorTickInterface.wilderWild$getPrevAnimTicks();
float rotation = sculkSensorTickInterface.wilderWild$getFacing().toYRot();
poseStack.translate(0.5F, 0.5F, 0.5F);
poseStack.mulPose(Axis.YP.rotationDegrees(-rotation));
poseStack.translate(-0.5F, -0.5F, -0.5F);
float xRot = (prevTicks + partialTick * (sculkSensorTickInterface.wilderWild$getAnimTicks() - prevTicks))
* 0.1F
* ((float) Math.cos((sculkSensorTickInterface.wilderWild$getAge() + partialTick) * 2.25F) * RAD_25);
this.tendril1.xRot = xRot;
this.tendril2.xRot = xRot;
this.tendril3.xRot = xRot;
this.tendril4.xRot = xRot;
this.root.render(poseStack, buffer.getBuffer(ACTIVE_SENSOR_LAYER), light, overlay);
} else {
this.ne.xRot = 0;
this.se.xRot = 0;
this.nw.xRot = 0;
this.sw.xRot = 0;
this.root.render(poseStack, buffer.getBuffer(SENSOR_LAYER), light, overlay);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.frozenblock.wilderwild.block.entity.impl.SculkSensorTickInterface;
import net.frozenblock.wilderwild.registry.WWGameEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -31,8 +32,10 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.CalibratedSculkSensorBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity;
import net.minecraft.world.level.block.entity.SculkSensorBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
Expand All @@ -48,6 +51,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Objects;

@Mixin(SculkSensorBlockEntity.class)
public abstract class SculkSensorBlockEntityMixin extends BlockEntity implements SculkSensorTickInterface {
Expand All @@ -62,6 +66,8 @@ public abstract class SculkSensorBlockEntityMixin extends BlockEntity implements
public boolean wilderWild$active;
@Unique
public boolean wilderWild$prevActive;
@Unique
public Direction wilderWild$facing = Direction.NORTH;

private SculkSensorBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
Expand Down Expand Up @@ -94,6 +100,11 @@ private SculkSensorBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, Block
}
}
this.wilderWild$setPrevActive(this.wilderWild$isActive());
if (sensor instanceof CalibratedSculkSensorBlockEntity) {
if (state.hasProperty(CalibratedSculkSensorBlock.FACING)) {
this.wilderWild$setFacing(state.getValue(CalibratedSculkSensorBlock.FACING));
}
}
}

@Unique
Expand Down Expand Up @@ -167,13 +178,28 @@ private SculkSensorBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, Block
this.wilderWild$animTicks = i;
}

@Unique
@Override
public void wilderWild$setFacing(Direction facing) {
this.wilderWild$facing = facing;
}

@Unique
@Override
public Direction wilderWild$getFacing() {
return this.wilderWild$facing;
}

@Inject(method = "loadAdditional", at = @At("TAIL"))
private void wilderWild$load(CompoundTag nbt, HolderLookup.Provider provider, CallbackInfo info) {
this.wilderWild$setAge(nbt.getInt("age"));
this.wilderWild$setAnimTicks(nbt.getInt("animTicks"));
this.wilderWild$setPrevAnimTicks(nbt.getInt("prevAnimTicks"));
this.wilderWild$setActive(nbt.getBoolean("active"));
this.wilderWild$setPrevActive(nbt.getBoolean("prevActive"));

Direction facing = Direction.byName(nbt.getString("facing"));
this.wilderWild$setFacing(Objects.requireNonNullElse(facing, Direction.SOUTH));
}

@Inject(method = "saveAdditional", at = @At("TAIL"))
Expand All @@ -183,6 +209,7 @@ private SculkSensorBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, Block
nbt.putInt("prevAnimTicks", this.wilderWild$getPrevAnimTicks());
nbt.putBoolean("active", this.wilderWild$isActive());
nbt.putBoolean("prevActive", this.wilderWild$isPrevActive());
nbt.putString("facing", this.wilderWild$getFacing().getName());
}

@Mixin(SculkSensorBlockEntity.VibrationUser.class)
Expand Down
Loading

0 comments on commit d7a0131

Please sign in to comment.