Skip to content

Commit

Permalink
feat: update to 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamalam360 committed Dec 18, 2024
1 parent 0f325fb commit 1232053
Show file tree
Hide file tree
Showing 26 changed files with 189 additions and 194 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- (fix) game will no longer crash when `player.accessoriesCapability()` returns null (#59)
Update to 1.21.4
17 changes: 15 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.9-SNAPSHOT" apply false
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
id "com.github.breadmoirai.github-release" version "2.4.1"
}
Expand Down Expand Up @@ -48,7 +48,10 @@ subprojects {

dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings loom.officialMojangMappings()
mappings loom.layered() {
officialMojangMappings()
parchment "org.parchmentmc.data:parchment-${libs.versions.parchment.minecraft.get()}:${libs.versions.parchment.asProvider().get()}@zip"
}
}
}

Expand Down Expand Up @@ -88,6 +91,16 @@ allprojects {
name = "Wisp Forests Maven"
url = "https://maven.wispforest.io/releases"
}

maven {
name = "ParchmentMC"
url = "https://maven.parchmentmc.org"
}

maven {
name = "Gegy"
url = "https://maven.gegy.dev"
}
}

tasks.withType(JavaCompile) {
Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ dependencies {

compileOnly libs.mixin.extras.common
annotationProcessor libs.mixin.extras.common

modCompileOnly libs.lambdynamiclights.api
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.github.jamalam360.utility_belt.client.compat;

import dev.lambdaurora.lambdynlights.api.DynamicLightsContext;
import dev.lambdaurora.lambdynlights.api.DynamicLightsInitializer;
import dev.lambdaurora.lambdynlights.api.entity.luminance.EntityLuminance;
import dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;
import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.UtilityBeltInventory;
import io.github.jamalam360.utility_belt.UtilityBeltItem;
import io.github.jamalam360.utility_belt.state.StateManager;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;

public class LambDynamicLightsCompat implements DynamicLightsInitializer {

@Override
public void onInitializeDynamicLights(DynamicLightsContext ctx) {
UtilityBelt.LOGGER.info("Initializing LambDynamicLights compat for Utility Belt.");
ctx.entityLightSourceManager().onRegisterEvent().register((registerContext) -> {
registerContext.register(EntityType.PLAYER, UtilityBeltEntityLuminance.INSTANCE);
});
}

private static class UtilityBeltEntityLuminance implements EntityLuminance {

public static final UtilityBeltEntityLuminance INSTANCE = new UtilityBeltEntityLuminance();

public static final EntityLuminance.Type TYPE = EntityLuminance.Type.registerSimple(
UtilityBelt.id("belt_luminance"),
INSTANCE
);

private UtilityBeltEntityLuminance() {}

@Override
public @NotNull Type type() {
return TYPE;
}

@Override
public @Range(from = 0L, to = 15L) int getLuminance(@NotNull ItemLightSourceManager itemLightSourceManager, @NotNull Entity entity) {
if (!(entity instanceof Player player)) {
return 0;
}

int luminance = 0;
StateManager stateManager = StateManager.getStateManager(player);
if (stateManager.hasBelt(player)) {
UtilityBeltInventory inv = stateManager.getInventory(player);

for (ItemStack stack : inv.items()) {
luminance = Math.max(luminance, itemLightSourceManager.getLuminance(stack));
}
}

return luminance;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import java.util.function.Function;

@Environment(EnvType.CLIENT)
@Mixin(Gui.class)
public abstract class GuiMixin {
Expand All @@ -22,11 +25,11 @@ public abstract class GuiMixin {
method = "renderItemHotbar",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V",
target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V",
ordinal = 1
)
)
private boolean utilitybelt$disableHotbarHighlight(GuiGraphics instance, ResourceLocation arg, int i, int j, int k, int l) {
private boolean utilitybelt$disableHotbarHighlight(GuiGraphics instance, Function<ResourceLocation, RenderType> renderTypeGetter, ResourceLocation sprite, int x, int y, int width, int height) {
return !StateManager.getStateManager(true).isInBelt(this.getCameraPlayer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.CoreShaders;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

@Environment(EnvType.CLIENT)
public class BeltHotbarRenderer {

private static final ResourceLocation UTILITY_BELT_WIDGET_TEXTURE = UtilityBelt
.id("textures/gui/utility_belt_widget.png");
private static final ResourceLocation UTILITY_BELT_HOTBAR_TEXTURE = UtilityBelt
.id("utility_belt_hotbar");
private static final ResourceLocation HOTBAR_SELECTION_SPRITE = ResourceLocation.withDefaultNamespace("hud/hotbar_selection");

public static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
Expand Down Expand Up @@ -48,21 +49,21 @@ public static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
y += UtilityBeltClient.CONFIG.get().hotbarOffsetY;

RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShader(CoreShaders.POSITION_TEX);

graphics.blit(UTILITY_BELT_WIDGET_TEXTURE, x, y, 0, 0, 22, 88);
graphics.blitSprite(RenderType::guiTextured, UTILITY_BELT_HOTBAR_TEXTURE, x, y, 22, 88);

if (stateManager.isInBelt(player)) {
graphics.blitSprite(HOTBAR_SELECTION_SPRITE, x - 1, y - 1 + stateManager.getSelectedBeltSlot(player) * 20, 0, 24, 23);
graphics.blitSprite(RenderType::guiTextured, HOTBAR_SELECTION_SPRITE, x - 1, y - 1 + stateManager.getSelectedBeltSlot(player) * 22, 24, 23);
}

UtilityBeltInventory inv = stateManager.getInventory(player);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
int m = 1;

for (int n = 0; n < inv.getContainerSize(); ++n) {
renderHotbarItem(graphics, x, y + n * 20 + 3, deltaTracker.getGameTimeDeltaTicks(), player, inv.getItem(n), m++);
for (int n = 0; n < inv.getContainerSize(); n++) {
renderHotbarItem(graphics, x, y + n * 22 + 3, deltaTracker.getGameTimeDeltaTicks(), player, inv.getItem(n), m++);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import net.minecraft.client.model.geom.PartNames;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
import net.minecraft.world.entity.LivingEntity;

@Environment(EnvType.CLIENT)
public class BeltModel extends HumanoidModel<LivingEntity> {
public class BeltModel extends HumanoidModel<HumanoidRenderState> {

public BeltModel(ModelPart root) {
super(root);
Expand All @@ -19,22 +20,14 @@ public BeltModel(ModelPart root) {
}

public static LayerDefinition createLayerDefinition() {
MeshDefinition mesh = new MeshDefinition();
MeshDefinition mesh = HumanoidModel.createMesh(CubeDeformation.NONE, 0.0F);
PartDefinition root = mesh.getRoot();
PartDefinition body = root.addOrReplaceChild(
PartNames.BODY,
CubeListBuilder.create().texOffs(0, 0).addBox(-5.0F, 10.0F, -3.0F, 10.0F, 2.0F, 6.0F, new CubeDeformation(0.0F))
.texOffs(0, 8).addBox(-4.0F, 11.0F, -4.0F, 4.0F, 4.0F, 1.0F, new CubeDeformation(0.0F))
.texOffs(10, 8).addBox(1.0F, 11.0F, -4.0F, 3.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.rotation(0.0F, 0.0F, 0.0F));
body.addOrReplaceChild("pouch", CubeListBuilder.create().texOffs(18, 8).addBox(0.0F, -13.0F, -6.0F, 2.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 24.0F, 0.0F, 0.0F, 1.5708F, 0.0F));

root.addOrReplaceChild(PartNames.HEAD, CubeListBuilder.create(), PartPose.ZERO);
root.addOrReplaceChild(PartNames.HAT, CubeListBuilder.create(), PartPose.ZERO);
root.addOrReplaceChild(PartNames.RIGHT_ARM, CubeListBuilder.create(), PartPose.ZERO);
root.addOrReplaceChild(PartNames.LEFT_ARM, CubeListBuilder.create(), PartPose.ZERO);
root.addOrReplaceChild(PartNames.RIGHT_LEG, CubeListBuilder.create(), PartPose.ZERO);
root.addOrReplaceChild(PartNames.LEFT_LEG, CubeListBuilder.create(), PartPose.ZERO);

return LayerDefinition.create(mesh, 64, 64);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -26,26 +28,25 @@
public class BeltRenderer implements AccessoryRenderer {

private static final ResourceLocation TEXTURE = UtilityBelt.id("textures/entity/belt.png");
private static final Supplier<HumanoidModel<LivingEntity>> MODEL = Suppliers.memoize(() ->
private static final Supplier<HumanoidModel<HumanoidRenderState>> MODEL = Suppliers.memoize(() ->
new BeltModel(BeltModel.createLayerDefinition().bakeRoot())
);

@Override
public <M extends LivingEntity> void render(ItemStack stack, SlotReference reference, PoseStack matrices, EntityModel<M> model, MultiBufferSource multiBufferSource, int light, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
HumanoidModel<LivingEntity> beltModel = MODEL.get();
beltModel.setupAnim(reference.entity(), limbSwing, limbSwingAmount, partialTicks, ageInTicks, headPitch);
beltModel.prepareMobModel(reference.entity(), limbSwing, limbSwingAmount, partialTicks);
public <S extends LivingEntityRenderState> void render(ItemStack stack, SlotReference reference, PoseStack matrices, EntityModel<S> entityModel, S state, MultiBufferSource multiBufferSource, int light, float v) {
HumanoidModel<HumanoidRenderState> beltModel = MODEL.get();
beltModel.setupAnim((HumanoidRenderState) state);
followBodyRotations(reference.entity(), beltModel);
VertexConsumer vertexConsumer = multiBufferSource.getBuffer(beltModel.renderType(TEXTURE));
beltModel.renderToBuffer(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY);
}

@SuppressWarnings("unchecked")
private static void followBodyRotations(LivingEntity entity, HumanoidModel<LivingEntity> model) {
EntityRenderer<? super LivingEntity> render = Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(entity);
private static void followBodyRotations(LivingEntity entity, HumanoidModel<HumanoidRenderState> model) {
EntityRenderer<? super LivingEntity, ?> render = Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(entity);

if (render instanceof LivingEntityRenderer<?, ?> renderer && renderer.getModel() instanceof HumanoidModel<?> entityModel) {
((HumanoidModel<LivingEntity>) entityModel).copyPropertiesTo(model);
if (render instanceof LivingEntityRenderer<?, ?, ?> renderer && renderer.getModel() instanceof HumanoidModel<?> entityModel) {
((HumanoidModel<HumanoidRenderState>) entityModel).copyPropertiesTo(model);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.github.jamalam360.utility_belt.screen.UtilityBeltMenu;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.*;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -26,11 +26,9 @@ protected void init() {

@Override
protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShader(CoreShaders.POSITION_TEX);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int x = (width - this.imageWidth) / 2;
int y = (height - this.imageHeight) / 2;
graphics.blit(TEXTURE, x, y, 0, 0, this.imageWidth, this.imageHeight);
graphics.blit(RenderType::guiTextured, TEXTURE, this.leftPos, this.topPos, 0F, 0F, this.imageWidth, this.imageHeight, 256, 256);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "utility_belt:item/utility_belt"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
"type": "minecraft:crafting_shaped",
"category": "equipment",
"key": {
"D": {
"item": "minecraft:diamond"
},
"L": {
"item": "minecraft:leather"
},
"S": {
"item": "minecraft:string"
}
"D": "minecraft:diamond",
"L": "minecraft:leather",
"S": "minecraft:string"
},
"pattern": [
"SDS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,30 @@
import io.wispforest.accessories.api.AccessoryItem;
import io.wispforest.accessories.api.slot.SlotEntryReference;
import io.wispforest.accessories.api.slot.SlotReference;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.ARGB;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.SlotAccess;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.ClickAction;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.BrushItem;
import net.minecraft.world.item.FishingRodItem;
import net.minecraft.world.item.FlintAndSteelItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ProjectileWeaponItem;
import net.minecraft.world.item.ShearsItem;
import net.minecraft.world.item.SpyglassItem;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.TridentItem;
import net.minecraft.world.item.*;
import org.jetbrains.annotations.Nullable;

public class UtilityBeltItem extends AccessoryItem {

private static final int BAR_COLOR = Mth.color(0.4F, 0.4F, 1.0F);
private static final int BAR_COLOR = ARGB.color((int) (0.4 * 255), (int) (0.4 * 255), (int) (1.0 * 255));

public UtilityBeltItem() {
super(new Item.Properties().stacksTo(1).component(UtilityBelt.UTILITY_BELT_INVENTORY_COMPONENT_TYPE.get(), UtilityBeltInventory.EMPTY));
super(new Item.Properties().stacksTo(1).component(UtilityBelt.UTILITY_BELT_INVENTORY_COMPONENT_TYPE.get(), UtilityBeltInventory.EMPTY).setId(ResourceKey.create(Registries.ITEM, UtilityBelt.id("utility_belt"))));
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
Expand Down Expand Up @@ -69,7 +64,7 @@ private static void playInsertSound(Entity entity) {
}

public static boolean isValidItem(ItemStack stack) {
return stack.getItem() instanceof TieredItem || stack.getItem() instanceof ProjectileWeaponItem || stack.getItem() instanceof FishingRodItem || stack.getItem() instanceof SpyglassItem || stack.getItem() instanceof TridentItem || stack.getItem() instanceof FlintAndSteelItem || stack.getItem() instanceof ShearsItem || stack.getItem() instanceof BrushItem || stack.isEmpty() || stack.is(UtilityBelt.ALLOWED_IN_UTILITY_BELT);
return stack.getItem() instanceof DiggerItem || stack.getItem() instanceof MaceItem || stack.getItem() instanceof SwordItem || stack.getItem() instanceof ProjectileWeaponItem || stack.getItem() instanceof FishingRodItem || stack.getItem() instanceof FoodOnAStickItem<?> || stack.getItem() instanceof SpyglassItem || stack.getItem() instanceof TridentItem || stack.getItem() instanceof FlintAndSteelItem || stack.getItem() instanceof ShearsItem || stack.getItem() instanceof BrushItem || stack.isEmpty() || stack.is(UtilityBelt.ALLOWED_IN_UTILITY_BELT);
}

public static UtilityBeltInventory getInventory(ItemStack stack) {
Expand Down Expand Up @@ -169,8 +164,8 @@ public void onDestroyed(ItemEntity itemEntity) {
UtilityBeltInventory inv = getInventory(itemEntity.getItem());

for (ItemStack stack : inv.items()) {
if (!stack.isEmpty()) {
itemEntity.spawnAtLocation(stack);
if (!stack.isEmpty() && itemEntity.level() instanceof ServerLevel server) {
itemEntity.spawnAtLocation(server, stack);
}
}
}
Expand Down
Loading

0 comments on commit 1232053

Please sign in to comment.