Skip to content

Commit

Permalink
Fix mixin conflicts for 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Jun 5, 2022
1 parent 18c2501 commit 19efbb4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 79 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
modImplementation "com.github.emilyploszaj:step-height-entity-attribute:v1.0.1"
include "com.github.emilyploszaj:step-height-entity-attribute:v1.0.1"

modImplementation "curse.maven:iceberg-539382:3535221"
modImplementation "curse.maven:iceberg-539382:3675784"
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ maven_group=io.github.Andrew6rant
archives_base_name=tiered

# Dependencies
fabric_version=0.54.0+1.18.2
fabric_version=0.55.1+1.18.2
cardinal_version=2.7.4+
reach_entity_attributes_version=2.1.1+
mod_menu_version=1.14+
42 changes: 42 additions & 0 deletions src/main/java/Andrew6rant/tiered/Tiered.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.event.client.ItemTooltipCallback;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.item.v1.ModifyItemAttributeModifiersCallback;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.loader.api.FabricLoader;
Expand All @@ -28,6 +29,9 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

public class Tiered implements ModInitializer {
Expand Down Expand Up @@ -65,6 +69,7 @@ public void onInitialize() {
TieredItemTags.init();
CustomEntityAttributes.init();
registerAttributeSyncer();
registerAttributeModifier();

if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
// setupModifierLabel();
Expand Down Expand Up @@ -177,4 +182,41 @@ public static void registerAttributeSyncer() {
packetSender.sendPacket(ATTRIBUTE_SYNC_PACKET, packet);
});
}

public static void registerAttributeModifier() {
// Registering an event instead of using a mixin.
// because why try to work around fapi's modifications when you can just use them?
ModifyItemAttributeModifiersCallback.EVENT.register((itemStack, slot, modifiers) -> {
if(itemStack.getSubNbt(Tiered.NBT_SUBTAG_KEY) != null) {
Identifier tier = new Identifier(itemStack.getOrCreateSubNbt(Tiered.NBT_SUBTAG_KEY).getString(Tiered.NBT_SUBTAG_DATA_KEY));

if(!itemStack.hasNbt() || !itemStack.getNbt().contains("AttributeModifiers", 9)) {
PotentialAttribute potentialAttribute = Tiered.ATTRIBUTE_DATA_LOADER.getItemAttributes().get(tier);

if(potentialAttribute != null) {
potentialAttribute.getAttributes().forEach(template -> {
// get required equipment slots
if(template.getRequiredEquipmentSlots() != null) {
List<EquipmentSlot> requiredEquipmentSlots = new ArrayList<>(Arrays.asList(template.getRequiredEquipmentSlots()));

if(requiredEquipmentSlots.contains(slot)) {
template.realize(modifiers, slot);
}
}

// get optional equipment slots
if(template.getOptionalEquipmentSlots() != null) {
List<EquipmentSlot> optionalEquipmentSlots = new ArrayList<>(Arrays.asList(template.getOptionalEquipmentSlots()));

// optional equipment slots are valid ONLY IF the equipment slot is valid for the thing
if(optionalEquipmentSlots.contains(slot) && Tiered.isPreferredEquipmentSlot(itemStack, slot)) {
template.realize(modifiers, slot);
}
}
});
}
}
}
});
}
}
76 changes: 0 additions & 76 deletions src/main/java/Andrew6rant/tiered/mixin/ItemStackMixin.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/tiered.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"InventoryAccessor",
"ItemStackMixin",
"LivingEntityMixin",
"PlayerEntityMixin",
"ServerPlayerEntityMixin",
Expand Down

0 comments on commit 19efbb4

Please sign in to comment.