Skip to content

Commit 76537ce

Browse files
committed
- fixes and ability rework start
1 parent deeae25 commit 76537ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+478
-313
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
## v2.0.5 (1.21)
2-
- fixed fake-tag ingredient interactions
3-
- fixed crash related to opening statistics on forge (or other unaccounted accesses of armorrendering)
4-
- adjusted armor strength for generated materials
1+
## v2.0.6 (1.21)
2+
- fixed tool miss-identification on neoforge
3+
- fixed bug where fake enchants could become permanent (whoops)
4+
- fixed vein mining max being not set correctly
5+
- fixed bug where we expected the item name to be added to the lore list
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package smartin.miapi;
2+
3+
public class MixinContextFlags {
4+
public static final ThreadLocal<Boolean> CALLED_FROM_MUTABLE = ThreadLocal.withInitial(() -> false);
5+
}
6+

common/src/main/java/smartin/miapi/client/MiapiClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static void init() {
8686
if (config.getInstance() == null) {
8787
config.load();
8888
}
89-
if ( Platform.getMod("nucleus").getVersion().equals("1.1.4")) {
89+
if (Platform.getMod("nucleus").getVersion().equals("1.1.4")) {
9090
RenderEvents.LIVING_ENTITY_RENDER.register((stage, model, entity, entityYaw, partialTick, matrixStack, multiBufferSource, packedLight) -> {
9191
if (stage != RenderEvents.EntityRenderStage.PRE) return EventResult.pass();
9292
for (Map.Entry<Holder<MobEffect>, MobEffectInstance> entry : entity.getActiveEffectsMap().entrySet()) {
@@ -186,6 +186,8 @@ public static void init() {
186186
RegistryInventory.MODULAR_ITEMS.addCallback((item -> {
187187
ModularModelPredicateProvider.registerModelOverride(item, Miapi.id("damage"), (stack, world, entity, seed) -> stack.isDamageableItem() && stack.getDamageValue() > 0 ? ((float) stack.getDamageValue() / stack.getMaxDamage()) : 0.0f);
188188
ModularModelPredicateProvider.registerModelOverride(item, Miapi.id("damaged"), (stack, world, entity, seed) -> stack.isDamaged() ? 1.0F : 0.0F);
189+
ModularModelPredicateProvider.registerModelOverride(item, Miapi.id("use"), (stack, world, entity, seed) -> entity.isUsingItem() && stack.equals(entity.getUseItem()) ? 1.0F : 0.0F);
190+
ModularModelPredicateProvider.registerModelOverride(item, Miapi.id("use_ticks"), (stack, world, entity, seed) -> entity.isUsingItem() && stack.equals(entity.getUseItem()) ? entity.getTicksUsingItem() : 0.0f);
189191
}));
190192
ReloadEvents.START.subscribe((isClient, registryAccess) -> {
191193
if (isClient) {

common/src/main/java/smartin/miapi/mixin/BCWeaponRegistryMixin.java

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package smartin.miapi.mixin;
2+
3+
import net.minecraft.world.item.enchantment.ItemEnchantments;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.injection.At;
6+
import org.spongepowered.asm.mixin.injection.Inject;
7+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
8+
import smartin.miapi.MixinContextFlags;
9+
10+
@Mixin(ItemEnchantments.Mutable.class)
11+
public class EnchantmentMutableMixin {
12+
@Inject(method = {"set", "upgrade", "removeIf"}, at = @At("HEAD"))
13+
private void onModifyEnchantments(CallbackInfo ci) {
14+
MixinContextFlags.CALLED_FROM_MUTABLE.set(true);
15+
}
16+
17+
@Inject(method = {"set", "upgrade", "removeIf"}, at = @At("RETURN"))
18+
private void afterModifyEnchantments(CallbackInfo ci) {
19+
MixinContextFlags.CALLED_FROM_MUTABLE.set(false);
20+
}
21+
}

common/src/main/java/smartin/miapi/mixin/ItemEnchantmentsMixin.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.world.item.enchantment.ItemEnchantments;
99
import org.spongepowered.asm.mixin.Mixin;
1010
import org.spongepowered.asm.mixin.injection.At;
11+
import smartin.miapi.MixinContextFlags;
1112
import smartin.miapi.item.modular.ModularItem;
1213
import smartin.miapi.modules.properties.enchanment.FakeEnchantmentManager;
1314

@@ -18,6 +19,9 @@ public abstract class ItemEnchantmentsMixin {
1819

1920
@ModifyReturnValue(method = "entrySet()Ljava/util/Set;", at = @At("RETURN"))
2021
public Set<Object2IntMap.Entry<Holder<Enchantment>>> miapi$adjustFakeEnchants(Set<Object2IntMap.Entry<Holder<Enchantment>>> original) {
22+
if (MixinContextFlags.CALLED_FROM_MUTABLE.get()) {
23+
return original;
24+
}
2125
ItemEnchantments itemEnchantments = (ItemEnchantments) (Object) this;
2226
ItemStack itemStack = FakeEnchantmentManager.lookupMap.get(itemEnchantments);
2327
if (itemStack != null && ModularItem.isModularItem(itemStack)) {
@@ -29,6 +33,9 @@ public abstract class ItemEnchantmentsMixin {
2933

3034
@ModifyReturnValue(method = "getLevel", at = @At("RETURN"))
3135
public int miapi$adjustEnchantLevel(int original, Holder<Enchantment> enchantment) {
36+
if (MixinContextFlags.CALLED_FROM_MUTABLE.get()) {
37+
return original;
38+
}
3239
ItemEnchantments itemEnchantments = (ItemEnchantments) (Object) this;
3340
ItemStack itemStack = FakeEnchantmentManager.lookupMap.get(itemEnchantments);
3441
if (itemStack != null && ModularItem.isModularItem(itemStack)) {

common/src/main/java/smartin/miapi/modules/abilities/AreaHarvestReplant.java

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package smartin.miapi.modules.abilities;
22

3-
import com.mojang.serialization.Codec;
4-
import com.mojang.serialization.DynamicOps;
3+
import com.mojang.serialization.MapCodec;
54
import com.redpxnda.nucleus.codec.auto.AutoCodec;
65
import com.redpxnda.nucleus.codec.behavior.CodecBehavior;
76
import net.minecraft.core.BlockPos;
@@ -10,7 +9,6 @@
109
import net.minecraft.world.InteractionHand;
1110
import net.minecraft.world.InteractionResult;
1211
import net.minecraft.world.InteractionResultHolder;
13-
import net.minecraft.world.entity.LivingEntity;
1412
import net.minecraft.world.entity.player.Player;
1513
import net.minecraft.world.item.ItemStack;
1614
import net.minecraft.world.item.UseAnim;
@@ -20,17 +18,21 @@
2018
import net.minecraft.world.level.block.CropBlock;
2119
import net.minecraft.world.level.block.entity.BlockEntity;
2220
import net.minecraft.world.level.block.state.BlockState;
23-
import smartin.miapi.item.modular.StatResolver;
2421
import smartin.miapi.modules.ModuleInstance;
2522
import smartin.miapi.modules.abilities.util.ItemAbilityManager;
26-
import smartin.miapi.modules.abilities.util.ItemUseDefaultCooldownAbility;
27-
import smartin.miapi.modules.abilities.util.ItemUseMinHoldAbility;
23+
import smartin.miapi.modules.abilities.util.MinMaxCDAbility;
24+
import smartin.miapi.modules.properties.util.DoubleOperationResolvable;
25+
import smartin.miapi.modules.properties.util.MergeType;
2826

2927
import java.util.List;
3028

31-
public class AreaHarvestReplant implements ItemUseDefaultCooldownAbility<AreaHarvestReplant.AreaHarvestJson>, ItemUseMinHoldAbility<AreaHarvestReplant.AreaHarvestJson> {
29+
public class AreaHarvestReplant extends MinMaxCDAbility<AreaHarvestReplant.AreaHarvestJson> {
3230
public static String KEY = "area_harvest_ability";
33-
public static Codec<AreaHarvestJson> CODEC = AutoCodec.of(AreaHarvestJson.class).codec();
31+
public static MapCodec<AreaHarvestJson> CODEC = AutoCodec.of(AreaHarvestJson.class);
32+
33+
public AreaHarvestReplant() {
34+
super(0, 0);
35+
}
3436

3537
@Override
3638
public boolean allowedOnItem(ItemStack itemStack, Level world, Player player, InteractionHand hand, ItemAbilityManager.AbilityHitContext abilityHitContext) {
@@ -56,11 +58,6 @@ public UseAnim getUseAction(ItemStack itemStack) {
5658
return UseAnim.BRUSH;
5759
}
5860

59-
@Override
60-
public int getMaxUseTime(ItemStack itemStack, LivingEntity entity) {
61-
return 10;
62-
}
63-
6461
@Override
6562
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
6663
return null;
@@ -70,7 +67,7 @@ public InteractionResult useOnBlock(UseOnContext context) {
7067
ItemStack itemStack = context.getItemInHand();
7168
if (!context.getLevel().isClientSide() && context.getPlayer() instanceof ServerPlayer serverPlayer) {
7269
int blocksHarvested = 0;
73-
int range = getSpecialContext(itemStack).range.evaluatedOutput;
70+
int range = getData(itemStack).map(a -> a.range.getValue()).orElse(1.0).intValue();
7471
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
7572
BlockPos origin = context.getClickedPos();
7673

@@ -99,47 +96,27 @@ public InteractionResult useOnBlock(UseOnContext context) {
9996
return InteractionResult.FAIL;
10097
}
10198

102-
public <K> AreaHarvestJson decode(DynamicOps<K> ops, K prefix) {
103-
return CODEC.decode(ops, prefix).getOrThrow().getFirst();
104-
}
105-
106-
public AreaHarvestJson initialize(AreaHarvestJson data, ModuleInstance moduleInstance) {
107-
return data.initialize(moduleInstance);
108-
}
109-
11099
@Override
111-
public AreaHarvestJson getDefaultContext() {
112-
return null;
100+
protected AreaHarvestJson mergeData(AreaHarvestJson left, AreaHarvestJson right, MergeType mergeType) {
101+
return left;
113102
}
114103

115-
@Override
116-
public int getCooldown(ItemStack itemstack) {
117-
return getSpecialContext(itemstack).cooldown.evaluatedOutput;
104+
public AreaHarvestJson initializeData(AreaHarvestJson data, ModuleInstance moduleInstance) {
105+
return data.initialize(moduleInstance);
118106
}
119107

120108
@Override
121-
public int getMinHoldTime(ItemStack itemStack) {
122-
return getSpecialContext(itemStack).minUseTime.evaluatedOutput;
109+
protected MapCodec<AreaHarvestJson> getMapCodec() {
110+
return CODEC;
123111
}
124112

125113
public static class AreaHarvestJson {
126-
//TODO:move to DoubleResovlables?
127-
@CodecBehavior.Optional
128-
@AutoCodec.Name("min_hold_time")
129-
public StatResolver.IntegerFromStat minUseTime = new StatResolver.IntegerFromStat(0);
130-
@CodecBehavior.Optional
131-
public StatResolver.IntegerFromStat cooldown = new StatResolver.IntegerFromStat(0);
132114
@CodecBehavior.Optional
133-
public StatResolver.IntegerFromStat range = new StatResolver.IntegerFromStat(1);
115+
public DoubleOperationResolvable range = new DoubleOperationResolvable(0);
134116

135117
public AreaHarvestJson initialize(ModuleInstance moduleInstance) {
136118
AreaHarvestJson init = new AreaHarvestJson();
137-
init.cooldown = cooldown;
138-
init.minUseTime = minUseTime;
139-
init.range = range;
140-
init.cooldown.evaluate(moduleInstance);
141-
init.minUseTime.evaluate(moduleInstance);
142-
init.range.evaluate(moduleInstance);
119+
init.range = range.initialize(moduleInstance);
143120
return init;
144121
}
145122

common/src/main/java/smartin/miapi/modules/abilities/BlockAbility.java

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import com.google.common.collect.ArrayListMultimap;
44
import com.google.common.collect.Multimap;
5-
import com.mojang.serialization.Codec;
6-
import com.mojang.serialization.DynamicOps;
5+
import com.mojang.serialization.MapCodec;
76
import com.redpxnda.nucleus.codec.auto.AutoCodec;
8-
import com.redpxnda.nucleus.codec.behavior.CodecBehavior;
97
import com.redpxnda.nucleus.pose.server.ServerPoseFacet;
108
import net.minecraft.core.Holder;
119
import net.minecraft.network.chat.Component;
@@ -22,13 +20,13 @@
2220
import net.minecraft.world.level.Level;
2321
import smartin.miapi.Miapi;
2422
import smartin.miapi.attributes.AttributeRegistry;
25-
import smartin.miapi.item.modular.StatResolver;
2623
import smartin.miapi.modules.ModuleInstance;
2724
import smartin.miapi.modules.abilities.util.AbilityMangerProperty;
2825
import smartin.miapi.modules.abilities.util.EntityAttributeAbility;
2926
import smartin.miapi.modules.abilities.util.ItemAbilityManager;
3027
import smartin.miapi.modules.properties.LoreProperty;
3128
import smartin.miapi.modules.properties.util.DoubleOperationResolvable;
29+
import smartin.miapi.modules.properties.util.MergeType;
3230

3331
import java.util.ArrayList;
3432
import java.util.List;
@@ -38,7 +36,7 @@
3836
* transforms the Value of {@link BlockAbility#calculate(double)} to the actual damage resistance and slowdown percentages
3937
*/
4038
public class BlockAbility extends EntityAttributeAbility<BlockAbility.BlockAbilityJson> {
41-
public static Codec<BlockAbilityJson> CODEC = AutoCodec.of(BlockAbilityJson.class).codec();
39+
public static MapCodec<BlockAbilityJson> CODEC = AutoCodec.of(BlockAbilityJson.class);
4240
ResourceLocation id = Miapi.id("block_ability_temporary_attribute");
4341

4442
public BlockAbility() {
@@ -55,8 +53,7 @@ public BlockAbility() {
5553
@Override
5654
protected Multimap<Holder<Attribute>, AttributeModifier> getAttributes(ItemStack itemStack) {
5755
Multimap<Holder<Attribute>, AttributeModifier> multimap = ArrayListMultimap.create();
58-
BlockAbilityJson json = getSpecialContext(itemStack);
59-
double value = json.blocking.getValue();
56+
double value = getData(itemStack).map(c -> c.blocking.getValue()).orElse(1.0).doubleValue();
6057
value = calculate(value);
6158
multimap.put(Attributes.MOVEMENT_SPEED, new AttributeModifier(id, -(value / 2) / 100, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
6259
multimap.put(AttributeRegistry.DAMAGE_RESISTANCE, new AttributeModifier(id, value, AttributeModifier.Operation.ADD_VALUE));
@@ -72,11 +69,6 @@ public boolean allowedOnItem(ItemStack itemStack, Level world, Player player, In
7269
return true;
7370
}
7471

75-
@Override
76-
public int getMaxUseTime(ItemStack itemStack, LivingEntity entity) {
77-
return 20 * 60 * 60;
78-
}
79-
8072
@Override
8173
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
8274
setAnimation(user, hand);
@@ -101,11 +93,6 @@ public void onStoppedHolding(ItemStack stack, Level world, LivingEntity user) {
10193
super.onStoppedHolding(stack, world, user);
10294
}
10395

104-
@Override
105-
public BlockAbilityJson getDefaultContext() {
106-
return null;
107-
}
108-
10996
public void setAnimation(Player p, InteractionHand hand) {
11097
if (p instanceof ServerPlayer player) {
11198
ServerPoseFacet facet = ServerPoseFacet.KEY.get(player);
@@ -124,38 +111,27 @@ public void resetAnimation(LivingEntity entity) {
124111
}
125112

126113
@Override
127-
public int getCooldown(ItemStack itemstack) {
128-
return getSpecialContext(itemstack).cooldown.evaluatedOutput;
114+
protected BlockAbilityJson mergeData(BlockAbilityJson left, BlockAbilityJson right, MergeType mergeType) {
115+
BlockAbilityJson blockAbilityJson = new BlockAbilityJson();
116+
blockAbilityJson.blocking = DoubleOperationResolvable.merge(left.blocking, right.blocking, mergeType);
117+
return blockAbilityJson;
129118
}
130119

131-
@Override
132-
public int getMinHoldTime(ItemStack itemStack) {
133-
return getSpecialContext(itemStack).minUseTime.evaluatedOutput;
134-
}
135-
136-
public <K> BlockAbilityJson decode(DynamicOps<K> ops, K prefix) {
137-
return CODEC.decode(ops, prefix).getOrThrow().getFirst();
120+
public BlockAbilityJson initializeData(BlockAbilityJson data, ModuleInstance moduleInstance) {
121+
return data.initialize(moduleInstance);
138122
}
139123

140-
public BlockAbilityJson initialize(BlockAbilityJson data, ModuleInstance moduleInstance) {
141-
return data.initialize(moduleInstance);
124+
@Override
125+
protected MapCodec<BlockAbilityJson> getMapCodec() {
126+
return CODEC;
142127
}
143128

144129
public static class BlockAbilityJson {
145-
@CodecBehavior.Optional
146-
@AutoCodec.Name("min_hold_time")
147-
public StatResolver.IntegerFromStat minUseTime = new StatResolver.IntegerFromStat(0);
148-
@CodecBehavior.Optional
149-
public StatResolver.IntegerFromStat cooldown = new StatResolver.IntegerFromStat(0);
150130
public DoubleOperationResolvable blocking = new DoubleOperationResolvable(10);
151131

152132

153133
public BlockAbilityJson initialize(ModuleInstance moduleInstance) {
154134
BlockAbilityJson init = new BlockAbilityJson();
155-
init.minUseTime = minUseTime;
156-
init.cooldown = cooldown;
157-
minUseTime.evaluate(moduleInstance);
158-
cooldown.evaluate(moduleInstance);
159135
init.blocking = blocking.initialize(moduleInstance);
160136
return init;
161137
}

common/src/main/java/smartin/miapi/modules/abilities/CastLightingAbility.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package smartin.miapi.modules.abilities;
22

33
import com.mojang.serialization.Codec;
4-
import com.mojang.serialization.DynamicOps;
54
import com.mojang.serialization.codecs.RecordCodecBuilder;
65
import net.minecraft.server.level.ServerPlayer;
76
import net.minecraft.sounds.SoundEvent;
@@ -82,8 +81,8 @@ public InteractionResult useOnBlock(UseOnContext context) {
8281
}
8382

8483
@Override
85-
public <K> CastLightingContext decode(DynamicOps<K> ops, K prefix) {
86-
return CastLightingContext.CODEC.decode(ops, prefix).getOrThrow().getFirst();
84+
public Codec<CastLightingContext> getCodec() {
85+
return CastLightingContext.CODEC;
8786
}
8887

8988
@Override

0 commit comments

Comments
 (0)