Skip to content

Commit

Permalink
1.2.0 beta for 1.16.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Draylar committed Dec 4, 2020
1 parent 173145c commit 1a9319d
Show file tree
Hide file tree
Showing 38 changed files with 236 additions and 179 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Tiered is entirely data-driven, which means you can add, modify, and remove modi
},
"attributes": [
{
"type": "generic.digSpeed",
"type": "generic.dig_speed",
"modifier": {
"name": "tiered:hasteful",
"operation": "MULTIPLY_TOTAL",
Expand Down
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
plugins {
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

archivesBaseName = project.archives_base_name
version = project.mod_version
version = project.mod_version + "-" + project.minecraft_version
group = project.maven_group

minecraft {
}

repositories {
maven {url "https://maven.jamieswhiteshirt.com/libs-release/"}
maven { url 'https://jitpack.io' }
maven { url 'https://jitpack.io' }
maven { url 'https://jitpack.io' }
}

Expand All @@ -26,11 +27,11 @@ dependencies {

modCompile "io.github.prospector:modmenu:${project.mod_menu_version}"

modImplementation ("com.jamieswhiteshirt:reach-entity-attributes:${project.reach_entity_attributes_version}") {
modCompile ("com.github.Draylar:reach-entity-attributes:1.0.2") {
exclude group: "net.fabricmc.fabric-api"
}

include ("com.jamieswhiteshirt:reach-entity-attributes:${project.reach_entity_attributes_version}") {
include ("com.github.Draylar:reach-entity-attributes:1.0.2") {
exclude group: "net.fabricmc.fabric-api"
}
}
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
minecraft_version=1.15.2
yarn_mappings=1.15.2+build.15
loader_version=0.8.2+build.194
minecraft_version=1.16.4
yarn_mappings=1.16.4+build.7
loader_version=0.10.8

# Mod Properties
mod_version=1.0.3-beta
mod_version=1.2.0-beta
maven_group=draylar
archives_base_name=tiered

# Dependencies
fabric_version=0.7.1+build.301-1.15
cardinal_version=2.3.4
reach_entity_attributes_version=1.0.0
mod_menu_version=1.8.5+build.23
fabric_version=0.27.1+1.16
cardinal_version=2.7.4
reach_entity_attributes_version=1.0.1
mod_menu_version=1.14+
18 changes: 16 additions & 2 deletions src/main/java/draylar/tiered/Tiered.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import draylar.tiered.api.FabricArmorTags;
import draylar.tiered.api.PotentialAttribute;
import draylar.tiered.data.AttributeDataLoader;
import draylar.tiered.mixin.ServerResourceManagerMixin;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.client.ItemTooltipCallback;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ItemStack;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
Expand All @@ -19,7 +24,7 @@ public class Tiered implements ModInitializer {

/**
* Attribute Data Loader instance which handles loading attribute .json files from "data/modid/item_attributes".
* <p> This field is registered to the server's data manager in {@link draylar.tiered.mixin.MinecraftServerMixin}
* <p> This field is registered to the server's data manager in {@link ServerResourceManagerMixin}
*/
public static final AttributeDataLoader ATTRIBUTE_DATA_LOADER = new AttributeDataLoader();

Expand All @@ -43,7 +48,7 @@ public void onInitialize() {
CustomEntityAttributes.init();

if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
setupModifierLabel();
// setupModifierLabel();
}
}

Expand Down Expand Up @@ -77,4 +82,13 @@ private void setupModifierLabel() {
}
});
}

public static boolean isPreferredEquipmentSlot(ItemStack stack, EquipmentSlot slot) {
if(stack.getItem() instanceof ArmorItem) {
ArmorItem item = (ArmorItem) stack.getItem();
return item.getSlotType().equals(slot);
}

return slot == EquipmentSlot.MAINHAND;
}
}
15 changes: 12 additions & 3 deletions src/main/java/draylar/tiered/api/AttributeTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import com.google.gson.annotations.SerializedName;
import draylar.tiered.Tiered;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.ClampedEntityAttribute;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

/**
* Stores information on an AttributeModifier template applied to an ItemStack.
Expand Down Expand Up @@ -54,14 +58,19 @@ public EquipmentSlot[] getOptionalEquipmentSlots() {
* @param multimap map to add {@link AttributeTemplate}
* @param slot
*/
public void realize(Multimap<String, EntityAttributeModifier> multimap, EquipmentSlot slot) {
public void realize(Multimap<EntityAttribute, EntityAttributeModifier> multimap, EquipmentSlot slot) {
EntityAttributeModifier cloneModifier = new EntityAttributeModifier(
Tiered.MODIFIERS[slot.getArmorStandSlotId()],
entityAttributeModifier.getName() + "_" + slot.getName(),
entityAttributeModifier.getAmount(),
entityAttributeModifier.getValue(),
entityAttributeModifier.getOperation()
);

multimap.put(this.attributeTypeID, cloneModifier);
EntityAttribute key = Registry.ATTRIBUTE.get(new Identifier(attributeTypeID));
if(key == null) {
Tiered.LOGGER.warn(String.format("%s was referenced as an attribute type, but it does not exist! A data file in /tiered/item_attributes/ has an invalid type property.", attributeTypeID));
} else {
multimap.put(key, cloneModifier);
}
}
}
10 changes: 8 additions & 2 deletions src/main/java/draylar/tiered/api/CustomEntityAttributes.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package draylar.tiered.api;

import draylar.tiered.Tiered;
import net.minecraft.entity.attribute.ClampedEntityAttribute;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.util.registry.Registry;

public class CustomEntityAttributes {

public static final EntityAttribute DIG_SPEED = new ClampedEntityAttribute(null, "generic.digSpeed", 0.0D, 0.0D, 2048.0D).setTracked(true);
public static final EntityAttribute CRIT_CHANCE = new ClampedEntityAttribute(null, "generic.critChance", 0.0D, 0.0D, 1D).setTracked(true);
public static final EntityAttribute DIG_SPEED = register(new ClampedEntityAttribute("generic.dig_speed", 0.0D, 0.0D, 2048.0D).setTracked(true));
public static final EntityAttribute CRIT_CHANCE = register(new ClampedEntityAttribute("generic.crit_chance", 0.0D, 0.0D, 1D).setTracked(true));
// public static final EntityAttribute DURABLE = new ClampedEntityAttribute(null, "generic.durable", 0.0D, 0.0D, 1D).setTracked(true);

public static void init() {
// NO-OP
}

private static EntityAttribute register(EntityAttribute attribute) {
return Registry.register(Registry.ATTRIBUTE, Tiered.id(attribute.getTranslationKey()), attribute);
}
}
2 changes: 1 addition & 1 deletion src/main/java/draylar/tiered/api/ItemVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean isValid(String itemID) {
if(id != null) {
return itemID.equals(id);
} else if(tag != null) {
Tag<Item> itemTag = ItemTags.getContainer().get(new Identifier(tag));
Tag<Item> itemTag = ItemTags.getTagGroup().getTag(new Identifier(tag));

if(itemTag != null) {
return itemTag.contains(Registry.ITEM.get(new Identifier(itemID)));
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/draylar/tiered/data/AttributeDataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.*;
import draylar.tiered.api.PotentialAttribute;
import draylar.tiered.gson.EntityAttributeModifierDeserializer;
import draylar.tiered.gson.EquipmentSlotDeserializer;
import draylar.tiered.gson.FormattingDeserializer;
import draylar.tiered.gson.TextColorDeserializer;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.resource.JsonDataLoader;
import net.minecraft.resource.ResourceManager;
import net.minecraft.text.Style;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
Expand All @@ -31,7 +30,6 @@ public class AttributeDataLoader extends JsonDataLoader {
.registerTypeAdapter(EntityAttributeModifier.class, new EntityAttributeModifierDeserializer())
.registerTypeAdapter(EquipmentSlot.class, new EquipmentSlotDeserializer())
.registerTypeHierarchyAdapter(Style.class, new Style.Serializer())
.registerTypeAdapter(Formatting.class, new FormattingDeserializer())
.create();

private static final String PARSING_ERROR_MESSAGE = "Parsing error loading recipe {}";
Expand All @@ -45,10 +43,10 @@ public AttributeDataLoader() {
}

@Override
protected void apply(Map<Identifier, JsonObject> loader, ResourceManager manager, Profiler profiler) {
protected void apply(Map<Identifier, JsonElement> loader, ResourceManager manager, Profiler profiler) {
Map<Identifier, PotentialAttribute> readItemAttributes = Maps.newHashMap();

for (Map.Entry<Identifier, JsonObject> entry : loader.entrySet()) {
for (Map.Entry<Identifier, JsonElement> entry : loader.entrySet()) {
Identifier identifier = entry.getKey();

try {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/draylar/tiered/gson/TextColorDeserializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package draylar.tiered.gson;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;

import java.lang.reflect.Type;

public class TextColorDeserializer implements JsonDeserializer<TextColor> {

@Override
public TextColor deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return TextColor.fromFormatting(Formatting.byName(json.getAsString().toUpperCase()));
}
}
25 changes: 0 additions & 25 deletions src/main/java/draylar/tiered/mixin/ItemMixin.java

This file was deleted.

61 changes: 55 additions & 6 deletions src/main/java/draylar/tiered/mixin/ItemStackClientMixin.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package draylar.tiered.mixin;

import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Ordering;
import draylar.tiered.Tiered;
import draylar.tiered.api.PotentialAttribute;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
Expand All @@ -17,11 +21,13 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand All @@ -30,22 +36,65 @@ public abstract class ItemStackClientMixin {

@Shadow public abstract CompoundTag getOrCreateSubTag(String key);

@Shadow public abstract boolean hasTag();

@Shadow public abstract CompoundTag getSubTag(String key);

private boolean isTiered = false;

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/attribute/EntityAttributeModifier;getAmount()D"), method = "getTooltip", locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/attribute/EntityAttributeModifier;getValue()D"), method = "getTooltip", locals = LocalCapture.CAPTURE_FAILHARD)
private void storeAttributeModifier(PlayerEntity player, TooltipContext context, CallbackInfoReturnable<List> cir, List list, int i, EquipmentSlot var6[], int var7, int var8, EquipmentSlot equipmentSlot, Multimap multimap, Iterator var11, Map.Entry entry, EntityAttributeModifier entityAttributeModifier) {
isTiered = entityAttributeModifier.getName().contains("tiered:");
}

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/text/TranslatableText;formatted(Lnet/minecraft/util/Formatting;)Lnet/minecraft/text/Text;", ordinal = 2), method = "getTooltip")
private Text getFormatting(TranslatableText texts, Formatting formatting) {
if(isTiered) {
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/text/TranslatableText;formatted(Lnet/minecraft/util/Formatting;)Lnet/minecraft/text/MutableText;", ordinal = 2), method = "getTooltip")
private MutableText getFormatting(TranslatableText translatableText, Formatting formatting) {
if(this.hasTag() && this.getSubTag(Tiered.NBT_SUBTAG_KEY) != null && isTiered) {
Identifier tier = new Identifier(this.getOrCreateSubTag(Tiered.NBT_SUBTAG_KEY).getString(Tiered.NBT_SUBTAG_DATA_KEY));
PotentialAttribute attribute = Tiered.ATTRIBUTE_DATA_LOADER.getItemAttributes().get(tier);

return texts.setStyle(attribute.getStyle());
return translatableText.setStyle(attribute.getStyle());
} else {
return texts.formatted(formatting);
return translatableText.formatted(formatting);
}
}

@ModifyVariable(
method = "getTooltip",
at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Multimap;isEmpty()Z"),
index = 10
)
private Multimap<EntityAttribute, EntityAttributeModifier> sort(Multimap<EntityAttribute, EntityAttributeModifier> map) {
Multimap<EntityAttribute, EntityAttributeModifier> vanillaFirst = LinkedListMultimap.create();
Multimap<EntityAttribute, EntityAttributeModifier> remaining = LinkedListMultimap.create();

map.forEach((entityAttribute, entityAttributeModifier) -> {
if (!entityAttributeModifier.getName().contains("tiered")) {
vanillaFirst.put(entityAttribute, entityAttributeModifier);
} else {
remaining.put(entityAttribute, entityAttributeModifier);
}
});

vanillaFirst.putAll(remaining);
return vanillaFirst;
}

@Inject(
method = "getName",
at = @At("RETURN"),
cancellable = true
)
private void modifyName(CallbackInfoReturnable<Text> cir) {
if(this.hasTag() && this.getSubTag("display") == null && this.getSubTag(Tiered.NBT_SUBTAG_KEY) != null) {
Identifier tier = new Identifier(getOrCreateSubTag(Tiered.NBT_SUBTAG_KEY).getString(Tiered.NBT_SUBTAG_DATA_KEY));

// attempt to display attribute if it is valid
PotentialAttribute potentialAttribute = Tiered.ATTRIBUTE_DATA_LOADER.getItemAttributes().get(tier);

if(potentialAttribute != null) {
cir.setReturnValue(new TranslatableText(potentialAttribute.getID() + ".label").append(" ").append(cir.getReturnValue()).setStyle(potentialAttribute.getStyle()));
}
}
}
}
Loading

0 comments on commit 1a9319d

Please sign in to comment.