mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
EnchantmentMixin
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package com.dfsek.terra.fabric.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class FabricEnchantment implements Enchantment {
|
||||
private final net.minecraft.enchantment.Enchantment enchantment;
|
||||
|
||||
public FabricEnchantment(net.minecraft.enchantment.Enchantment enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.enchantment.Enchantment getHandle() {
|
||||
return enchantment;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public boolean canEnchantItem(ItemStack itemStack) {
|
||||
return enchantment.isAcceptableItem((net.minecraft.item.ItemStack) (Object) itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return Objects.requireNonNull(Registry.ENCHANTMENT.getId(enchantment)).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(Enchantment other) {
|
||||
return !enchantment.canCombine(FabricAdapter.adapt(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return enchantment.getMaxLevel();
|
||||
}
|
||||
}
|
||||
@@ -26,11 +26,11 @@ public class FabricItemHandle implements ItemHandle {
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment(String id) {
|
||||
return FabricAdapter.adapt(Registry.ENCHANTMENT.get(Identifier.tryParse(id)));
|
||||
return (Enchantment) (Registry.ENCHANTMENT.get(Identifier.tryParse(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return Registry.ENCHANTMENT.stream().map(FabricAdapter::adapt).collect(Collectors.toSet());
|
||||
return Registry.ENCHANTMENT.stream().map(enchantment -> (Enchantment) enchantment).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.dfsek.terra.fabric.mixin.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Mixin(Enchantment.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.inventory.item.Enchantment.class, prefix = "vw$"))
|
||||
public abstract class EnchantmentMixin {
|
||||
@Shadow
|
||||
public abstract boolean isAcceptableItem(net.minecraft.item.ItemStack stack);
|
||||
|
||||
@Shadow
|
||||
public abstract boolean canCombine(Enchantment other);
|
||||
|
||||
public Object vw$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public boolean vw$canEnchantItem(ItemStack itemStack) {
|
||||
return isAcceptableItem((net.minecraft.item.ItemStack) (Object) itemStack);
|
||||
}
|
||||
|
||||
public String vw$getID() {
|
||||
return Objects.requireNonNull(Registry.ENCHANTMENT.getId((Enchantment) (Object) this)).toString();
|
||||
}
|
||||
|
||||
public boolean vw$conflictsWith(com.dfsek.terra.api.platform.inventory.item.Enchantment other) {
|
||||
return !canCombine((Enchantment) other);
|
||||
}
|
||||
}
|
||||
@@ -38,12 +38,12 @@ public abstract class ItemStackMetaMixin {
|
||||
|
||||
getEnchantments().forEach(enchantment -> {
|
||||
CompoundTag eTag = (CompoundTag) enchantment;
|
||||
map.put(FabricAdapter.adapt(Registry.ENCHANTMENT.get(eTag.getInt("id"))), eTag.getInt("lvl"));
|
||||
map.put((Enchantment) Registry.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl"));
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
public void vw$addEnchantment(Enchantment enchantment, int level) {
|
||||
addEnchantment(FabricAdapter.adapt(enchantment), level);
|
||||
addEnchantment((net.minecraft.enchantment.Enchantment) enchantment, level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.fabric.inventory.FabricEnchantment;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockType;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricDirectional;
|
||||
@@ -87,14 +85,6 @@ public final class FabricAdapter {
|
||||
return ((FabricEntityType) entityType).getHandle();
|
||||
}
|
||||
|
||||
public static Enchantment adapt(net.minecraft.enchantment.Enchantment enchantment) {
|
||||
return new FabricEnchantment(enchantment);
|
||||
}
|
||||
|
||||
public static net.minecraft.enchantment.Enchantment adapt(Enchantment enchantment) {
|
||||
return ((FabricEnchantment) enchantment).getHandle();
|
||||
}
|
||||
|
||||
public WorldAccess adapt(FabricWorldHandle worldHandle) {
|
||||
return worldHandle.getWorld();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"entity.EntityMixin",
|
||||
"entity.PlayerEntityMixin",
|
||||
"entity.ServerCommandSourceMixin",
|
||||
"inventory.EnchantmentMixin",
|
||||
"inventory.ItemMixin",
|
||||
"inventory.ItemStackDamageableMixin",
|
||||
"inventory.ItemStackMetaMixin",
|
||||
|
||||
Reference in New Issue
Block a user