Replace MixinItemStack with new API in Fabric.

Also remove un-used ExtendedRecipeRemainder
This commit is contained in:
modmuss50 2022-04-15 00:04:12 +01:00
parent cf6a8ae72c
commit 60fd7b1ab6
11 changed files with 23 additions and 167 deletions

View file

@ -1,37 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.api.items;
import com.google.common.collect.Multimap;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.item.ItemStack;
public interface ItemStackModifiers {
void getAttributeModifiers(EquipmentSlot slot, ItemStack stack, Multimap<EntityAttribute, EntityAttributeModifier> builder);
}

View file

@ -1,35 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.common.recipes;
import net.minecraft.item.ItemStack;
public interface ExtendedRecipeRemainder {
default ItemStack getRemainderStack(ItemStack stack) {
return stack.getItem().hasRecipeRemainder() ? new ItemStack(stack.getItem().getRecipeRemainder()) : ItemStack.EMPTY;
}
}

View file

@ -28,16 +28,13 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingInventory; import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.CraftingResultSlot; import net.minecraft.screen.slot.CraftingResultSlot;
import net.minecraft.util.collection.DefaultedList;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import reborncore.api.events.ItemCraftCallback; import reborncore.api.events.ItemCraftCallback;
import reborncore.common.recipes.ExtendedRecipeRemainder;
@Mixin(CraftingResultSlot.class) @Mixin(CraftingResultSlot.class)
public abstract class MixinCraftingResultSlot { public abstract class MixinCraftingResultSlot {
@ -50,20 +47,6 @@ public abstract class MixinCraftingResultSlot {
@Final @Final
private PlayerEntity player; private PlayerEntity player;
@ModifyVariable(method = "onTakeItem", at = @At(value = "INVOKE"), index = 3)
private DefaultedList<ItemStack> defaultedList(DefaultedList<ItemStack> list) {
for (int i = 0; i < input.size(); i++) {
ItemStack invStack = input.getStack(i);
if (invStack.getItem() instanceof ExtendedRecipeRemainder) {
ItemStack remainder = ((ExtendedRecipeRemainder) invStack.getItem()).getRemainderStack(invStack.copy());
if (!remainder.isEmpty()) {
list.set(i, remainder);
}
}
}
return list;
}
@Inject(method = "onCrafted(Lnet/minecraft/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;onCraft(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;I)V", shift = At.Shift.AFTER)) @Inject(method = "onCrafted(Lnet/minecraft/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;onCraft(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;I)V", shift = At.Shift.AFTER))
private void onCrafted(ItemStack itemStack, CallbackInfo info) { private void onCrafted(ItemStack itemStack, CallbackInfo info) {
ItemCraftCallback.EVENT.invoker().onCraft(itemStack, input, player); ItemCraftCallback.EVENT.invoker().onCraft(itemStack, input, player);

View file

@ -1,57 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.mixin.common;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
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.callback.CallbackInfoReturnable;
import reborncore.api.items.ItemStackModifiers;
@Mixin(ItemStack.class)
public abstract class MixinItemStack {
@Shadow
public abstract Item getItem();
@Inject(method = "getAttributeModifiers", at = @At("RETURN"), cancellable = true)
private void getAttributeModifiers(EquipmentSlot equipmentSlot, CallbackInfoReturnable<Multimap<EntityAttribute, EntityAttributeModifier>> info) {
if (getItem() instanceof ItemStackModifiers item) {
Multimap<EntityAttribute, EntityAttributeModifier> modifierHashMap = ArrayListMultimap.create(info.getReturnValue());
item.getAttributeModifiers(equipmentSlot, (ItemStack) (Object) this, modifierHashMap);
info.setReturnValue(ImmutableMultimap.copyOf(modifierHashMap));
}
}
}

View file

@ -26,7 +26,7 @@
], ],
"depends": { "depends": {
"fabricloader": ">=0.13.3", "fabricloader": ">=0.13.3",
"fabric": ">=0.40.0", "fabric": ">=0.50.0",
"team_reborn_energy": ">=2.2.0", "team_reborn_energy": ">=2.2.0",
"fabric-biome-api-v1": ">=3.0.0", "fabric-biome-api-v1": ">=3.0.0",
"minecraft": "~1.18.2-beta.1" "minecraft": "~1.18.2-beta.1"

View file

@ -11,7 +11,6 @@
"MixinBucketItem", "MixinBucketItem",
"MixinCraftingResultSlot", "MixinCraftingResultSlot",
"MixinItemEntity", "MixinItemEntity",
"MixinItemStack",
"MixinLivingEntity", "MixinLivingEntity",
"MixinPlayerEntity", "MixinPlayerEntity",
"MixinServerPlayerEntity" "MixinServerPlayerEntity"

View file

@ -7,9 +7,9 @@ org.gradle.jvmargs=-Xmx2G
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.18.2 minecraft_version=1.18.2
yarn_version=1.18.2+build.1 yarn_version=1.18.2+build.3
loader_version=0.13.3 loader_version=0.13.3
fapi_version=0.47.8+1.18.2 fapi_version=0.50.0+1.18.2
# Dependencies # Dependencies
energy_version=2.2.0 energy_version=2.2.0

View file

@ -48,7 +48,6 @@ import reborncore.common.screen.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder; import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity; import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity; import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.recipes.ExtendedRecipeRemainder;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
import techreborn.config.TechRebornConfig; import techreborn.config.TechRebornConfig;
@ -240,12 +239,10 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
} }
private ItemStack getRemainderItem(ItemStack stack) { private ItemStack getRemainderItem(ItemStack stack) {
if (stack.getItem() instanceof ExtendedRecipeRemainder) { if (stack.getItem().hasRecipeRemainder()) {
return ((ExtendedRecipeRemainder) stack.getItem()).getRemainderStack(stack);
} else if (stack.getItem().hasRecipeRemainder()) {
return new ItemStack(stack.getItem().getRecipeRemainder()); return new ItemStack(stack.getItem().getRecipeRemainder());
} }
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }

View file

@ -24,7 +24,9 @@
package techreborn.items.armor; package techreborn.items.armor;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttribute;
@ -40,7 +42,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
import reborncore.api.items.ArmorBlockEntityTicker; import reborncore.api.items.ArmorBlockEntityTicker;
import reborncore.api.items.ArmorRemoveHandler; import reborncore.api.items.ArmorRemoveHandler;
import reborncore.api.items.ItemStackModifiers;
import reborncore.common.powerSystem.RcEnergyItem; import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier; import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
@ -48,7 +49,7 @@ import techreborn.TechReborn;
import techreborn.config.TechRebornConfig; import techreborn.config.TechRebornConfig;
import techreborn.utils.InitUtils; import techreborn.utils.InitUtils;
public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers, ArmorBlockEntityTicker, ArmorRemoveHandler, RcEnergyItem { public class QuantumSuitItem extends TRArmourItem implements ArmorBlockEntityTicker, ArmorRemoveHandler, RcEnergyItem {
public final long flyCost = TechRebornConfig.quantumSuitFlyingCost; public final long flyCost = TechRebornConfig.quantumSuitFlyingCost;
public final long swimCost = TechRebornConfig.quantumSuitSwimmingCost; public final long swimCost = TechRebornConfig.quantumSuitSwimmingCost;
@ -65,7 +66,9 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
} }
@Override @Override
public void getAttributeModifiers(EquipmentSlot equipmentSlot, ItemStack stack, Multimap<EntityAttribute, EntityAttributeModifier> attributes) { public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(ItemStack stack, EquipmentSlot equipmentSlot) {
var attributes = ArrayListMultimap.create(super.getAttributeModifiers(stack, slot));
attributes.removeAll(EntityAttributes.GENERIC_MOVEMENT_SPEED); attributes.removeAll(EntityAttributes.GENERIC_MOVEMENT_SPEED);
if (this.slot == EquipmentSlot.LEGS && equipmentSlot == EquipmentSlot.LEGS && enableSprint) { if (this.slot == EquipmentSlot.LEGS && equipmentSlot == EquipmentSlot.LEGS && enableSprint) {
@ -78,6 +81,8 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
attributes.put(EntityAttributes.GENERIC_ARMOR, new EntityAttributeModifier(MODIFIERS[slot.getEntitySlotId()], "Armor modifier", 20, EntityAttributeModifier.Operation.ADDITION)); attributes.put(EntityAttributes.GENERIC_ARMOR, new EntityAttributeModifier(MODIFIERS[slot.getEntitySlotId()], "Armor modifier", 20, EntityAttributeModifier.Operation.ADDITION));
attributes.put(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, new EntityAttributeModifier(MODIFIERS[slot.getEntitySlotId()], "Knockback modifier", 2, EntityAttributeModifier.Operation.ADDITION)); attributes.put(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, new EntityAttributeModifier(MODIFIERS[slot.getEntitySlotId()], "Knockback modifier", 2, EntityAttributeModifier.Operation.ADDITION));
} }
return ImmutableMultimap.copyOf(attributes);
} }
@Override @Override

View file

@ -24,6 +24,8 @@
package techreborn.items.tool.industrial; package techreborn.items.tool.industrial;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
@ -47,7 +49,6 @@ import net.minecraft.util.TypedActionResult;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import reborncore.api.items.ItemStackModifiers;
import reborncore.common.powerSystem.RcEnergyItem; import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier; import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
@ -59,7 +60,7 @@ import techreborn.utils.MessageIDs;
import java.util.List; import java.util.List;
public class NanosaberItem extends SwordItem implements RcEnergyItem, ItemStackModifiers { public class NanosaberItem extends SwordItem implements RcEnergyItem {
public static final int maxCharge = TechRebornConfig.nanosaberCharge; public static final int maxCharge = TechRebornConfig.nanosaberCharge;
public int cost = TechRebornConfig.nanosaberCost; public int cost = TechRebornConfig.nanosaberCost;
@ -168,9 +169,10 @@ public class NanosaberItem extends SwordItem implements RcEnergyItem, ItemStackM
return ItemUtils.getColorForDurabilityBar(stack); return ItemUtils.getColorForDurabilityBar(stack);
} }
// ItemStackModifiers
@Override @Override
public void getAttributeModifiers(EquipmentSlot slot, ItemStack stack, Multimap<EntityAttribute, EntityAttributeModifier> attributes) { public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(ItemStack stack, EquipmentSlot slot) {
var attributes = ArrayListMultimap.create(super.getAttributeModifiers(stack, slot));
attributes.removeAll(EntityAttributes.GENERIC_ATTACK_DAMAGE); attributes.removeAll(EntityAttributes.GENERIC_ATTACK_DAMAGE);
attributes.removeAll(EntityAttributes.GENERIC_ATTACK_SPEED); attributes.removeAll(EntityAttributes.GENERIC_ATTACK_SPEED);
@ -178,5 +180,7 @@ public class NanosaberItem extends SwordItem implements RcEnergyItem, ItemStackM
attributes.put(EntityAttributes.GENERIC_ATTACK_DAMAGE, new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_ID, "Weapon modifier", TechRebornConfig.nanosaberDamage, EntityAttributeModifier.Operation.ADDITION)); attributes.put(EntityAttributes.GENERIC_ATTACK_DAMAGE, new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_ID, "Weapon modifier", TechRebornConfig.nanosaberDamage, EntityAttributeModifier.Operation.ADDITION));
attributes.put(EntityAttributes.GENERIC_ATTACK_SPEED, new EntityAttributeModifier(ATTACK_SPEED_MODIFIER_ID, "Weapon modifier", 3, EntityAttributeModifier.Operation.ADDITION)); attributes.put(EntityAttributes.GENERIC_ATTACK_SPEED, new EntityAttributeModifier(ATTACK_SPEED_MODIFIER_ID, "Weapon modifier", 3, EntityAttributeModifier.Operation.ADDITION));
} }
return ImmutableMultimap.copyOf(attributes);
} }
} }

View file

@ -21,10 +21,7 @@
], ],
"rei": [ "rei": [
"techreborn.compat.rei.ReiPlugin" "techreborn.compat.rei.ReiPlugin"
], ]
"autoswitch": [
"techreborn.compat.autoswitch.AutoSwitchApiImpl"
]
}, },
"custom": { "custom": {
"dashloader:customobject": [ "dashloader:customobject": [
@ -34,7 +31,7 @@
}, },
"depends": { "depends": {
"fabricloader": ">=0.13.3", "fabricloader": ">=0.13.3",
"fabric": ">=0.46.1", "fabric": ">=0.50.0",
"reborncore": "*", "reborncore": "*",
"team_reborn_energy": ">=2.2.0", "team_reborn_energy": ">=2.2.0",
"fabric-biome-api-v1": ">=3.0.0", "fabric-biome-api-v1": ">=3.0.0",