Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.21.4 #363

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

Expand Down
20 changes: 10 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G

minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.15.11
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.1
loader_version=0.16.9

mod_version = 3.10.0
mod_version = 3.11.0
maven_group = dev.emi
archives_base_name = trinkets

fabric_version=0.100.0+1.21
cca_version=6.1.0
mod_menu_version=10.0.0-beta.1
emi_version=1.1.10+1.21
rei_version=15.0.728
cloth_config_version=14.0.126
fabric_version=0.112.2+1.21.4
cca_version=6.2.2
mod_menu_version=13.0.0
emi_version=1.1.16+1.21.1
rei_version=18.0.796
cloth_config_version=17.0.144
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dev/emi/trinkets/SurvivalTrinketSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.emi.trinkets.api.SlotType;
import dev.emi.trinkets.api.TrinketInventory;
import dev.emi.trinkets.api.TrinketsApi;
import dev.emi.trinkets.mixin.accessor.RecipeBookScreenAccessor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
Expand Down Expand Up @@ -55,7 +56,7 @@ public boolean isEnabled() {
MinecraftClient client = MinecraftClient.getInstance();
Screen s = client.currentScreen;
if (s instanceof InventoryScreen screen) {
if (screen.getRecipeBookWidget().isOpen()) {
if (((RecipeBookScreenAccessor) screen).getRecipeBook().isOpen()) {
return false;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/dev/emi/trinkets/TrinketEntityRenderState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.emi.trinkets;

import dev.emi.trinkets.api.SlotReference;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Pair;

import java.util.List;

public interface TrinketEntityRenderState {
void trinkets$setState(List<Pair<ItemStack, SlotReference>> items);
List<Pair<ItemStack, SlotReference>> trinkets$getState();
}
42 changes: 30 additions & 12 deletions src/main/java/dev/emi/trinkets/TrinketFeatureRenderer.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
package dev.emi.trinkets;

import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.TrinketComponent;
import dev.emi.trinkets.api.TrinketsApi;
import dev.emi.trinkets.api.client.TrinketRendererRegistry;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Pair;

public class TrinketFeatureRenderer<T extends LivingEntity, M extends EntityModel<T>> extends FeatureRenderer<T, M> {
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class TrinketFeatureRenderer<T extends LivingEntityRenderState, M extends EntityModel<T>> extends FeatureRenderer<T, M> {

public TrinketFeatureRenderer(FeatureRendererContext<T, M> context) {
super(context);
}

public static void update(LivingEntity livingEntity, LivingEntityRenderState entityState, float tickDelta, TrinketEntityRenderState state) {
Optional<TrinketComponent> component = TrinketsApi.getTrinketComponent(livingEntity);
if (component.isEmpty()) {
state.trinkets$setState(List.of());
} else {
List<Pair<ItemStack, SlotReference>> items = new ArrayList<>();
component.get().forEach((slotReference, stack) -> items.add(new Pair<>(stack, slotReference)));
state.trinkets$setState(items);
}
}

@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
TrinketsApi.getTrinketComponent(entity).ifPresent(component ->
component.forEach((slotReference, stack) ->
TrinketRendererRegistry.getRenderer(stack.getItem()).ifPresent(renderer -> {
matrices.push();
renderer.render(stack, slotReference, this.getContextModel(), matrices, vertexConsumers,
light, entity, limbAngle, limbDistance, tickDelta, animationProgress, headYaw, headPitch);
matrices.pop();
})
)
);
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, T state, float limbAngle, float limbDistance) {
((TrinketEntityRenderState) state).trinkets$getState().forEach(pair -> {
TrinketRendererRegistry.getRenderer(pair.getLeft().getItem()).ifPresent(renderer -> {
matrices.push();
renderer.render(pair.getLeft(), pair.getRight(), this.getContextModel(), matrices, vertexConsumers,
light, state, limbAngle, limbDistance);
matrices.pop();
});
});
}
}
57 changes: 33 additions & 24 deletions src/main/java/dev/emi/trinkets/TrinketScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.emi.trinkets.api.TrinketsApi;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.util.math.Rect2i;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -196,13 +197,13 @@ public static void drawGroup(DrawContext context, SlotGroup group, SlotType type
int x = r.getX() - 4 - (slotsWidth - 1) / 2 * 18;
int y = r.getY() - 4;
if (slotsWidth > 1 || type != null) {
context.drawTexture(MORE_SLOTS, x, y, 0, 0, 4, 26);
drawTexture(context, MORE_SLOTS, x, y, 0, 0, 4, 26);

for (int i = 0; i < slotsWidth; i++) {
context.drawTexture(MORE_SLOTS, x + i * 18 + 4, y, 4, 0, 18, 26);
drawTexture(context, MORE_SLOTS, x + i * 18 + 4, y, 4, 0, 18, 26);
}

context.drawTexture(MORE_SLOTS, x + slotsWidth * 18 + 4, y, 22, 0, 4, 26);
drawTexture(context, MORE_SLOTS, x + slotsWidth * 18 + 4, y, 22, 0, 4, 26);
for (int s = 0; s < slotHeights.size() && s < slotTypes.size(); s++) {
if (slotTypes.get(s) != type) {
continue;
Expand All @@ -214,18 +215,18 @@ public static void drawGroup(DrawContext context, SlotGroup group, SlotType type
int bottom = height / 2;
int slotX = slotHeight.x() - 4 + r.getX();
if (height > 2) {
context.drawTexture(MORE_SLOTS, slotX, y - top * 18, 0, 0, 26, 4);
drawTexture(context, MORE_SLOTS, slotX, y - top * 18, 0, 0, 26, 4);
}

for (int i = 1; i < top + 1; i++) {
context.drawTexture(MORE_SLOTS, slotX, y - i * 18 + 4, 0, 4, 26, 18);
drawTexture(context, MORE_SLOTS, slotX, y - i * 18 + 4, 0, 4, 26, 18);
}

for (int i = 1; i < bottom + 1; i++) {
context.drawTexture(MORE_SLOTS, slotX, y + i * 18 + 4, 0, 4, 26, 18);
drawTexture(context, MORE_SLOTS, slotX, y + i * 18 + 4, 0, 4, 26, 18);
}

context.drawTexture(MORE_SLOTS, slotX, y + 18 + bottom * 18 + 4, 0, 22, 26, 4);
drawTexture(context, MORE_SLOTS, slotX, y + 18 + bottom * 18 + 4, 0, 22, 26, 4);
}
}

Expand All @@ -241,23 +242,27 @@ public static void drawGroup(DrawContext context, SlotGroup group, SlotType type
int slotX = slotHeight.x() + r.getX() + 1;
int top = (height - 1) / 2;
int bottom = height / 2;
context.drawTexture(MORE_SLOTS, slotX, y - top * 18 + 1, 4, 1, 16, 3);
context.drawTexture(MORE_SLOTS, slotX, y + (bottom + 1) * 18 + 4, 4, 22, 16, 3);
drawTexture(context, MORE_SLOTS, slotX, y - top * 18 + 1, 4, 1, 16, 3);
drawTexture(context, MORE_SLOTS, slotX, y + (bottom + 1) * 18 + 4, 4, 22, 16, 3);
}

// Because pre-existing slots are not part of the slotHeights list
if (group.getSlotId() != -1) {
context.drawTexture(MORE_SLOTS, r.getX() + 1, y + 1, 4, 1, 16, 3);
context.drawTexture(MORE_SLOTS, r.getX() + 1, y + 22, 4, 22, 16, 3);
drawTexture(context, MORE_SLOTS, r.getX() + 1, y + 1, 4, 1, 16, 3);
drawTexture(context, MORE_SLOTS, r.getX() + 1, y + 22, 4, 22, 16, 3);
}
} else {
context.drawTexture(MORE_SLOTS, x + 4, y + 4, 4, 4, 18, 18);
drawTexture(context, MORE_SLOTS, x + 4, y + 4, 4, 4, 18, 18);
}

context.getMatrices().pop();
RenderSystem.disableDepthTest();
}

private static void drawTexture(DrawContext context, Identifier texture, int x, int y, int u, int v, int width, int height) {
context.drawTexture(RenderLayer::getGuiTextured, texture, x, y, u, v, width, height, 256, 256);
}

public static void drawActiveGroup(DrawContext context) {
if (TrinketsClient.activeGroup != null) {
TrinketScreenManager.drawGroup(context, TrinketsClient.activeGroup, TrinketsClient.activeType);
Expand All @@ -280,41 +285,45 @@ public static void drawExtraGroups(DrawContext context) {
height = 4;
width--;
}
context.drawTexture(MORE_SLOTS, x + 3, y, 7, 26, 1, 7);
drawTexture(context, MORE_SLOTS, x + 3, y, 7, 26, 1, 7);
// Repeated tops and bottoms
for (int i = 0; i < width; i++) {
context.drawTexture(MORE_SLOTS, x - 15 - 18 * i, y, 7, 26, 18, 7);
context.drawTexture(MORE_SLOTS, x - 15 - 18 * i, y + 79, 7, 51, 18, 7);
drawTexture(context, MORE_SLOTS, x - 15 - 18 * i, y, 7, 26, 18, 7);
drawTexture(context, MORE_SLOTS, x - 15 - 18 * i, y + 79, 7, 51, 18, 7);
}
// Top and bottom
context.drawTexture(MORE_SLOTS, x - 15 - 18 * width, y, 7, 26, 18, 7);
context.drawTexture(MORE_SLOTS, x - 15 - 18 * width, y + 7 + 18 * height, 7, 51, 18, 7);
drawTexture(context, MORE_SLOTS, x - 15 - 18 * width, y, 7, 26, 18, 7);
drawTexture(context, MORE_SLOTS, x - 15 - 18 * width, y + 7 + 18 * height, 7, 51, 18, 7);
// Corners
context.drawTexture(MORE_SLOTS, x - 22 - 18 * width, y, 0, 26, 7, 7);
context.drawTexture(MORE_SLOTS, x - 22 - 18 * width, y + 7 + 18 * height, 0, 51, 7, 7);
drawTexture(context, MORE_SLOTS, x - 22 - 18 * width, y, 0, 26, 7, 7);
drawTexture(context, MORE_SLOTS, x - 22 - 18 * width, y + 7 + 18 * height, 0, 51, 7, 7);
// Outer sides
for (int i = 0; i < height; i++) {
context.drawTexture(MORE_SLOTS, x - 22 - 18 * width, y + 7 + 18 * i, 0, 34, 7, 18);
drawTexture(context, MORE_SLOTS, x - 22 - 18 * width, y + 7 + 18 * i, 0, 34, 7, 18);
}
// Inner sides
if (width > 0) {
for (int i = height; i < 4; i++) {
context.drawTexture(MORE_SLOTS, x - 4 - 18 * width, y + 7 + 18 * i, 0, 34, 7, 18);
drawTexture(context, MORE_SLOTS, x - 4 - 18 * width, y + 7 + 18 * i, 0, 34, 7, 18);
}
}
if (width > 0 && height < 4) {
// Bottom corner
context.drawTexture(MORE_SLOTS, x - 4 - 18 * width, y + 79, 0, 51, 7, 7);
drawTexture(context, MORE_SLOTS, x - 4 - 18 * width, y + 79, 0, 51, 7, 7);
// Inner corner
context.drawTexture(MORE_SLOTS, x - 4 - 18 * width, y + 7 + 18 * height, 0, 58, 7, 7);
drawTexture(context, MORE_SLOTS, x - 4 - 18 * width, y + 7 + 18 * height, 0, 58, 7, 7);
}
if (width > 0 || height == 4) {
// Inner corner
context.drawTexture(MORE_SLOTS, x, y + 79, 0, 58, 3, 7);
drawTexture(context, MORE_SLOTS, x, y + 79, 0, 58, 3, 7);
}
}

public static boolean isClickInsideTrinketBounds(double mouseX, double mouseY) {
if (currentScreen == null || MinecraftClient.getInstance().currentScreen != currentScreen) {
return false;
}

TrinketPlayerScreenHandler handler = currentScreen.trinkets$getHandler();
int x = currentScreen.trinkets$getX();
int y = currentScreen.trinkets$getY();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/emi/trinkets/TrinketsMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -59,10 +59,10 @@ public void onInitialize() {
Trinket trinket = TrinketsApi.getTrinket(stack.getItem());
if (trinket.canEquipFromUse(stack, player)) {
if (TrinketItem.equipItem(player, stack)) {
return TypedActionResult.success(stack);
return ActionResult.SUCCESS;
}
}
return TypedActionResult.pass(stack);
return ActionResult.PASS;
});
Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(MOD_ID, "attribute_modifiers"), TrinketsAttributeModifiersComponent.TYPE);
PayloadTypeRegistry.playS2C().register(TrinketsNetwork.BREAK, BreakPayload.CODEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent;
import net.minecraft.entity.LivingEntity;
Expand Down Expand Up @@ -87,8 +88,8 @@ public void update() {
} else {
if (this.entity instanceof PlayerEntity player) {
player.getInventory().offerOrDrop(stack);
} else {
this.entity.dropStack(stack);
} else if (this.entity.getWorld() instanceof ServerWorld serverWorld) {
this.entity.dropStack(serverWorld, stack);
}
}
}
Expand Down Expand Up @@ -230,8 +231,10 @@ public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup lookup) {
}
}
}
for (ItemStack itemStack : dropped) {
this.entity.dropStack(itemStack);
if (this.entity.getWorld() instanceof ServerWorld serverWorld) {
for (ItemStack itemStack : dropped) {
this.entity.dropStack(serverWorld, itemStack);
}
}
Multimap<String, EntityAttributeModifier> slotMap = HashMultimap.create();
this.forEach((ref, stack) -> {
Expand Down Expand Up @@ -309,7 +312,7 @@ public void writeToNbt(NbtCompound tag, RegistryWrapper.WrapperLookup lookup) {
NbtList list = new NbtList();
TrinketInventory inv = slot.getValue();
for (int i = 0; i < inv.size(); i++) {
NbtCompound c = (NbtCompound) inv.getStack(i).encodeAllowEmpty(lookup);
NbtCompound c = (NbtCompound) inv.getStack(i).toNbtAllowEmpty(lookup);
list.add(c);
}
slotTag.put("Metadata", this.syncing ? inv.getSyncTag() : inv.toTag());
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/dev/emi/trinkets/api/Trinket.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
import dev.emi.trinkets.mixin.accessor.LivingEntityAccessor;
import java.util.function.Consumer;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.EnchantmentEffectComponentTypes;
import net.minecraft.component.type.EquippableComponent;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.item.Equipment;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;

public interface Trinket {
Expand Down Expand Up @@ -100,7 +103,11 @@ default boolean canEquipFromUse(ItemStack stack, LivingEntity entity) {
* @return The {@link SoundEvent} to play for equipping
*/
default RegistryEntry<SoundEvent> getEquipSound(ItemStack stack, SlotReference slot, LivingEntity entity) {
return stack.getItem() instanceof Equipment eq ? eq.getEquipSound() : null;
EquippableComponent component = stack.get(DataComponentTypes.EQUIPPABLE);
if (component != null) {
return component.equipSound();
}
return Registries.SOUND_EVENT.getEntry(SoundEvents.INTENTIONALLY_EMPTY);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/dev/emi/trinkets/api/TrinketInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;

Expand Down Expand Up @@ -178,7 +179,9 @@ public void update() {
if (i < newStacks.size()) {
newStacks.set(i, stack);
} else {
entity.dropStack(stack);
if (entity.getWorld() instanceof ServerWorld serverWorld) {
entity.dropStack(serverWorld, stack);
}
}
}

Expand Down
Loading