diff --git a/build.gradle b/build.gradle index ceeb368f..6f45f7c1 100644 --- a/build.gradle +++ b/build.gradle @@ -56,8 +56,8 @@ dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings loom.fromCommit("minecraft-cursed-legacy/Plasma", "b464f27") {spec -> - spec.version = "b1.7.3-12" + mappings loom.fromCommit("minecraft-cursed-legacy/Plasma", "f900cd3") {spec -> + spec.version = "b1.7.3-14" } // for config api diff --git a/gradle.properties b/gradle.properties index 4b72d433..cee9b7a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,6 @@ org.gradle.jvmargs=-Xmx1G loader_version=8f014a3 # Mod Properties - mod_version = 0.6.2 + mod_version = 0.6.3 maven_group = io.github.minecraftcursedlegacy.api archives_base_name = cursed-legacy-api diff --git a/src/main/java/io/github/minecraftcursedlegacy/api/data/AttachedData.java b/src/main/java/io/github/minecraftcursedlegacy/api/data/AttachedData.java new file mode 100644 index 00000000..b0d04b15 --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/api/data/AttachedData.java @@ -0,0 +1,27 @@ +package io.github.minecraftcursedlegacy.api.data; + +import io.github.minecraftcursedlegacy.api.registry.Id; +import net.minecraft.util.io.CompoundTag; + +/** + * Data which can be attached to various vanilla objects, such as items and blocks. + * @see {@link DataManager}. + */ +public interface AttachedData { + /** + * @return the id of this modded data. + */ + Id getId(); + /** + * @return a tag representation of this data. + */ + CompoundTag toTag(CompoundTag tag); + /** + * @param tag the tag from which to load data. + */ + void fromTag(CompoundTag tag); + /** + * Creates a deep copy of this {@link AttachedData}, similar to the recommendations for {@link Object#clone}. + */ + AttachedData copy(); +} diff --git a/src/main/java/io/github/minecraftcursedlegacy/api/data/DataManager.java b/src/main/java/io/github/minecraftcursedlegacy/api/data/DataManager.java new file mode 100644 index 00000000..daccb846 --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/api/data/DataManager.java @@ -0,0 +1,86 @@ +package io.github.minecraftcursedlegacy.api.data; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; + +import io.github.minecraftcursedlegacy.api.registry.Id; +import io.github.minecraftcursedlegacy.impl.data.DataStorage; +import net.minecraft.item.ItemInstance; +import net.minecraft.util.io.CompoundTag; + +/** + * Manager for data which can be attached to various vanilla objects, such as items and blocks. + */ +public final class DataManager { + private final Map> attachedDataFactories = new HashMap<>(); + + /** + * Adds the specified attached data to the {@link DataManager} instance. This data can later be accessed on an instance of the object via {@link #getAttachedData}. + * @return a key to use to retrieve the attached data from an object. + */ + public DataKey addAttachedData(Id id, Function dataProvider) { + this.attachedDataFactories.put(id, dataProvider); + return new DataKey<>(id); + } + + /** + * Retrieves the specified attached data from the object. + */ + public E getAttachedData(T object, DataKey key) throws ClassCastException { + return key.apply(((DataStorage) object).getAttachedData(key.id, () -> this.attachedDataFactories.get(key.id).apply(object))); + } + + /** + * Used by the implementation. + * @return a {@linkplain Set set} of all {@linkplain Id ids} of {@link AttachedData} instances registered to this manager. + */ + public Set getDataKeys() { + return this.attachedDataFactories.keySet(); + } + + /** + * Used by the implementation. + * @return an attached data instance of the given type constructed by the given tag. + */ + public AttachedData deserialize(T object, Id id, CompoundTag data) { + AttachedData result = this.attachedDataFactories.get(id).apply(object); + result.fromTag(data); + return result; + } + + /** + * Used by the implementation. + * @param from the object to use the data of. + * @param to the object to receive the data. + */ + public void copyData(T from, T to) { + DataStorage to_ = (DataStorage) (Object) to; + + ((DataStorage) (Object) from).getAllAttachedData().forEach(entry -> { + Id dataId = entry.getKey(); + AttachedData data = entry.getValue(); + to_.putAttachedData(dataId, data.copy()); + }); + } + + public static final DataManager ITEM_INSTANCE = new DataManager<>(); + + public static final class DataKey { + private DataKey(Id id) throws NullPointerException { + if (id == null) { + throw new NullPointerException("DataKey cannot store a null ID!"); + } + + this.id = id; + } + + private final Id id; + + @SuppressWarnings("unchecked") + private T apply(AttachedData data) throws ClassCastException { + return (T) data; + } + } +} diff --git a/src/main/java/io/github/minecraftcursedlegacy/api/event/TileInteractionCallback.java b/src/main/java/io/github/minecraftcursedlegacy/api/event/TileInteractionCallback.java new file mode 100644 index 00000000..49bcde65 --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/api/event/TileInteractionCallback.java @@ -0,0 +1,46 @@ +package io.github.minecraftcursedlegacy.api.event; + +import javax.annotation.Nullable; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import net.minecraft.entity.player.Player; +import net.minecraft.item.ItemInstance; +import net.minecraft.level.Level; +import net.minecraft.tile.Tile; + +/** + * Callback for right clicking a tile. This is run both client and server side. + * + *

Upon return: + *

    + *
  • SUCCESS cancels further event processing and vanilla code, and the method this is event is called from returns true (succeeds). + *
  • PASS falls back to further event processing. If all events PASS, then vanilla behaviour runs. + *
  • FAIL cancels further event processing and vanilla code, and the method this is event is called from returns false (fails). + *
+ */ +@FunctionalInterface +public interface TileInteractionCallback { + Event EVENT = EventFactory.createArrayBacked(TileInteractionCallback.class, + (listeners) -> (player, level, item, tile, x, y, z, face) -> { + for (TileInteractionCallback listener : listeners) { + ActionResult result = listener.onTileInteract(player, level, item, tile, x, y, z, face); + + if (result != ActionResult.PASS) { + return result; + } + } + + return ActionResult.PASS; + }); + + /** + * @param player the player causing the tile interaction. + * @param level the level the tile is being interacted with in. + * @param item the item instance that the player is using to interact with the tile. + * @param tile the tile being interacted with at the time of this event firing. This does not change if an event subscriber alters the tile at that position. + * @param face probably the tile face. The last parameter of {@link ItemInstance#useOnTile(Player, Level, int, int, int, int)}; + * @return the action result, as specified in the javadoc of {@link TileInteractionCallback}. + */ + ActionResult onTileInteract(Player player, Level level, @Nullable ItemInstance item, Tile tile, int x, int y, int z, int face); +} diff --git a/src/main/java/io/github/minecraftcursedlegacy/impl/client/CustomAtlas.java b/src/main/java/io/github/minecraftcursedlegacy/impl/client/CustomAtlas.java index 9bbb5f78..733447d7 100644 --- a/src/main/java/io/github/minecraftcursedlegacy/impl/client/CustomAtlas.java +++ b/src/main/java/io/github/minecraftcursedlegacy/impl/client/CustomAtlas.java @@ -6,11 +6,10 @@ import javax.imageio.ImageIO; -import net.minecraft.client.texture.TextureManager; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.texture.TextureManager; class CustomAtlas implements Atlas { private static final short MAX_SLOTS = 16 * 16; @@ -65,7 +64,7 @@ public int allocate(BufferedImage sprite) { @Environment(EnvType.CLIENT) public int getTextureID(TextureManager manager) { if (textureID < 0) { - textureID = manager.method_1088(image); + textureID = manager.glLoadImage(image); needsRefresh = false; } else if (needsRefresh) { needsRefresh = false; diff --git a/src/main/java/io/github/minecraftcursedlegacy/impl/data/DataStorage.java b/src/main/java/io/github/minecraftcursedlegacy/impl/data/DataStorage.java new file mode 100644 index 00000000..e1c0e28a --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/impl/data/DataStorage.java @@ -0,0 +1,16 @@ +package io.github.minecraftcursedlegacy.impl.data; + +import java.util.Map.Entry; +import java.util.Set; +import java.util.function.Supplier; + +import io.github.minecraftcursedlegacy.api.data.AttachedData; +import io.github.minecraftcursedlegacy.api.registry.Id; +import net.minecraft.util.io.CompoundTag; + +public interface DataStorage { + CompoundTag getModdedTag(); + void putAttachedData(Id id, AttachedData data); + AttachedData getAttachedData(Id id, Supplier supplier); + Set> getAllAttachedData(); +} diff --git a/src/main/java/io/github/minecraftcursedlegacy/impl/event/TileInteractionImpl.java b/src/main/java/io/github/minecraftcursedlegacy/impl/event/TileInteractionImpl.java new file mode 100644 index 00000000..dfd31702 --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/impl/event/TileInteractionImpl.java @@ -0,0 +1,21 @@ +package io.github.minecraftcursedlegacy.impl.event; + +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import io.github.minecraftcursedlegacy.api.event.ActionResult; +import io.github.minecraftcursedlegacy.api.event.TileInteractionCallback; +import net.minecraft.entity.player.Player; +import net.minecraft.item.ItemInstance; +import net.minecraft.level.Level; +import net.minecraft.tile.Tile; + +public class TileInteractionImpl { + public static void onTileInteract(Player player, Level level, ItemInstance item, int x, int y, int z, int i1, CallbackInfoReturnable info) { + int tile = level.getTileId(x, y, z); + ActionResult result = TileInteractionCallback.EVENT.invoker().onTileInteract(player, level, item, Tile.BY_ID[tile], x, y, z, i1); + + if (result != ActionResult.PASS) { + info.setReturnValue(result == ActionResult.SUCCESS); + } + } +} diff --git a/src/main/java/io/github/minecraftcursedlegacy/impl/levelgen/LevelGenImpl.java b/src/main/java/io/github/minecraftcursedlegacy/impl/levelgen/LevelGenImpl.java index db4083df..cf03b743 100644 --- a/src/main/java/io/github/minecraftcursedlegacy/impl/levelgen/LevelGenImpl.java +++ b/src/main/java/io/github/minecraftcursedlegacy/impl/levelgen/LevelGenImpl.java @@ -16,7 +16,7 @@ public void onInitialize() { int xToGen = x + rand.nextInt(16) + 8; int zToGen = z + rand.nextInt(16) + 8; Feature var18 = biome.getTree(rand); - var18.method_1143(1.0D, 1.0D, 1.0D); + var18.setupTreeGeneration(1.0D, 1.0D, 1.0D); var18.generate(level, rand, xToGen, level.getHeight(xToGen, zToGen), zToGen); } } diff --git a/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinClientInteractionManager.java b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinClientInteractionManager.java new file mode 100644 index 00000000..9ff4fa09 --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinClientInteractionManager.java @@ -0,0 +1,20 @@ +package io.github.minecraftcursedlegacy.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import io.github.minecraftcursedlegacy.impl.event.TileInteractionImpl; +import net.minecraft.client.ClientInteractionManager; +import net.minecraft.entity.player.Player; +import net.minecraft.item.ItemInstance; +import net.minecraft.level.Level; + +@Mixin(ClientInteractionManager.class) +public class MixinClientInteractionManager { + @Inject(at = @At("HEAD"), method = "useItemOnTile", cancellable = true) + private void api_onTileInteract(Player player, Level level, ItemInstance item, int x, int y, int z, int i1, CallbackInfoReturnable info) { + TileInteractionImpl.onTileInteract(player, level, item, x, y, z, i1, info); + } +} diff --git a/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinClass_556.java b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinHandItemRenderer.java similarity index 88% rename from src/main/java/io/github/minecraftcursedlegacy/mixin/MixinClass_556.java rename to src/main/java/io/github/minecraftcursedlegacy/mixin/MixinHandItemRenderer.java index 299bc978..524e434b 100644 --- a/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinClass_556.java +++ b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinHandItemRenderer.java @@ -1,28 +1,26 @@ package io.github.minecraftcursedlegacy.mixin; import org.objectweb.asm.Opcodes; - 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.CallbackInfo; -import net.minecraft.class_556; +import io.github.minecraftcursedlegacy.impl.client.AtlasMapper; import net.minecraft.client.Minecraft; +import net.minecraft.client.render.HandItemRenderer; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemInstance; -import io.github.minecraftcursedlegacy.impl.client.AtlasMapper; - -@Mixin(class_556.class) -abstract class MixinClass_556 { +@Mixin(HandItemRenderer.class) +abstract class MixinHandItemRenderer { @Shadow private Minecraft field_2401; @Inject(method = "method_1862", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/Tessellator;INSTANCE:Lnet/minecraft/client/render/Tessellator;", opcode = Opcodes.GETSTATIC) - ) + ) private void fixAtlas(LivingEntity entity, ItemInstance item, CallbackInfo info) { AtlasMapper.getAtlas(field_2401.textureManager, item.itemId, item.getDamage()).ifPresent(field_2401.textureManager::bindTexture); } diff --git a/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinItemInstance.java b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinItemInstance.java new file mode 100644 index 00000000..bdb2969b --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinItemInstance.java @@ -0,0 +1,87 @@ +package io.github.minecraftcursedlegacy.mixin; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.function.Supplier; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import io.github.minecraftcursedlegacy.api.data.AttachedData; +import io.github.minecraftcursedlegacy.api.data.DataManager; +import io.github.minecraftcursedlegacy.api.registry.Id; +import io.github.minecraftcursedlegacy.impl.data.DataStorage; +import net.minecraft.item.ItemInstance; +import net.minecraft.util.io.CompoundTag; + +@Mixin(ItemInstance.class) +public abstract class MixinItemInstance implements DataStorage { + private CompoundTag api_data = new CompoundTag(); + private Map api_attachedDataMap = new HashMap<>(); + + @Inject(at = @At("RETURN"), method = "copy") + private void api_copyData(CallbackInfoReturnable info) { + DataStorage ds = ((DataStorage) (Object) info.getReturnValue()); + + this.api_attachedDataMap.forEach((id, data) -> { + ds.putAttachedData(id, data.copy()); + }); + } + + @Inject(at = @At("RETURN"), method = "toTag") + private void api_addData(CompoundTag tag, CallbackInfoReturnable info) { + tag.put("moddedData", this.getModdedTag()); + } + + @Inject(at = @At("RETURN"), method = "split") + private void api_copySplitData(int countToTake, CallbackInfoReturnable info) { + DataStorage ds = ((DataStorage) (Object) info.getReturnValue()); + + this.api_attachedDataMap.forEach((id, data) -> { + ds.putAttachedData(id, this.api_attachedDataMap.get(id).copy()); + }); + } + + @Inject(at = @At("RETURN"), method = "fromTag") + private void api_readData(CompoundTag tag, CallbackInfo info) { + if (tag.containsKey("moddedData")) { + this.api_data = tag.getCompoundTag("moddedData"); + } + + // Load Data + DataManager.ITEM_INSTANCE.getDataKeys().forEach(id -> { + if (this.api_data.containsKey(id.toString())) { + this.putAttachedData(id, DataManager.ITEM_INSTANCE.deserialize((ItemInstance) (Object) this, id, this.api_data.getCompoundTag(id.toString()))); + } + }); + } + + @Override + public CompoundTag getModdedTag() { + this.api_attachedDataMap.forEach((id, data) -> { + this.api_data.put(id.toString(), data.toTag(new CompoundTag())); + }); + + return this.api_data; + } + + @Override + public Set> getAllAttachedData() { + return this.api_attachedDataMap.entrySet(); + } + + @Override + public void putAttachedData(Id id, AttachedData data) { + this.api_attachedDataMap.put(id, data); + } + + @Override + public AttachedData getAttachedData(Id id, Supplier supplier) { + return this.api_attachedDataMap.computeIfAbsent(id, i -> supplier.get()); + } +} diff --git a/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinPlayerInventory.java b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinPlayerInventory.java new file mode 100644 index 00000000..c34937cf --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinPlayerInventory.java @@ -0,0 +1,19 @@ +package io.github.minecraftcursedlegacy.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import io.github.minecraftcursedlegacy.api.data.DataManager; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemInstance; + +@Mixin(PlayerInventory.class) +public class MixinPlayerInventory { + @Redirect(method = "method_685", at = @At(value = "NEW", target = "net/minecraft/item/ItemInstance")) + private ItemInstance api_injectForItemPickup(int id, int count, int damage, ItemInstance param) { + ItemInstance result = new ItemInstance(id, count, damage); + DataManager.ITEM_INSTANCE.copyData(param, result); + return result; + } +} diff --git a/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinServerInteractionManager.java b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinServerInteractionManager.java new file mode 100644 index 00000000..d6909a3c --- /dev/null +++ b/src/main/java/io/github/minecraftcursedlegacy/mixin/MixinServerInteractionManager.java @@ -0,0 +1,20 @@ +package io.github.minecraftcursedlegacy.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import io.github.minecraftcursedlegacy.impl.event.TileInteractionImpl; +import net.minecraft.entity.player.Player; +import net.minecraft.item.ItemInstance; +import net.minecraft.level.Level; +import net.minecraft.server.ServerInteractionManager; + +@Mixin(ServerInteractionManager.class) +public class MixinServerInteractionManager { + @Inject(at = @At("HEAD"), method = "activateTile", cancellable = true) + private void api_onTileInteract(Player player, Level level, ItemInstance item, int x, int y, int z, int i1, CallbackInfoReturnable info) { + TileInteractionImpl.onTileInteract(player, level, item, x, y, z, i1, info); + } +} diff --git a/src/main/resources/api.mixins.json b/src/main/resources/api.mixins.json index 0c0d5ae5..e6e17366 100644 --- a/src/main/resources/api.mixins.json +++ b/src/main/resources/api.mixins.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "MixinBiome", + "MixinItemInstance", "MixinItemType", "MixinMcRegionLevelStorage", "MixinNetherLevelSource", @@ -11,6 +12,7 @@ "MixinOverlay", "MixinOverworldLevelSource", "MixinPlaceableTileItem", + "MixinPlayerInventory", "MixinShapedRecipe", "MixinSmeltingRecipeRegistry", "MixinTile", @@ -18,15 +20,17 @@ "MixinTitleScreen" ], "client": [ - "MixinResourceDownloadThread", - "MixinClass_556", + "MixinClientInteractionManager", + "MixinHandItemRenderer", "MixinHandshakeC2SClient", "MixinItemRenderer", - "MixinMinecraft" + "MixinMinecraft", + "MixinResourceDownloadThread" ], "server": [ "MixinMinecraftServer", "MixinPendingConnection", + "MixinServerInteractionManager", "MixinServerPlayerPacketHandler" ], "injectors": { diff --git a/src/test/java/io/github/minecraftcursedlegacy/test/ItemDataTest.java b/src/test/java/io/github/minecraftcursedlegacy/test/ItemDataTest.java new file mode 100644 index 00000000..e240a5a3 --- /dev/null +++ b/src/test/java/io/github/minecraftcursedlegacy/test/ItemDataTest.java @@ -0,0 +1,77 @@ +package io.github.minecraftcursedlegacy.test; + +import javax.annotation.Nullable; + +import io.github.minecraftcursedlegacy.api.data.AttachedData; +import io.github.minecraftcursedlegacy.api.data.DataManager; +import io.github.minecraftcursedlegacy.api.data.DataManager.DataKey; +import io.github.minecraftcursedlegacy.api.event.ActionResult; +import io.github.minecraftcursedlegacy.api.event.TileInteractionCallback; +import io.github.minecraftcursedlegacy.api.registry.Id; +import io.github.minecraftcursedlegacy.api.registry.Registries; +import net.fabricmc.api.ModInitializer; +import net.minecraft.item.ItemType; +import net.minecraft.util.io.CompoundTag; + +// Adds data attached to wooden axes. When a wooden axe is first right clicked on a tile, it picks up that tile's essence. +// Subsequent right clicks change the tiles interacted with to the stored essence. +public class ItemDataTest implements ModInitializer { + @Override + public void onInitialize() { + test_axe = DataManager.ITEM_INSTANCE.addAttachedData(TestAxeData.ID, item -> new TestAxeData(null)); + + TileInteractionCallback.EVENT.register((player, level, item, tile, x, y, z, i1) -> { + if (tile != null && item.getType() == ItemType.hatchetWood) { + TestAxeData data = DataManager.ITEM_INSTANCE.getAttachedData(item, test_axe); + + if (data.tile == null) { + data.tile = Registries.TILE.getId(tile); + } else { + level.setTile(x, y, z, Registries.TILE.getById(data.tile).id); + } + } + + return ActionResult.PASS; + }); + } + + public static DataKey test_axe; + + public static class TestAxeData implements AttachedData { + public TestAxeData(Id tileId) { + this.tile = tileId; + } + + @Nullable + public Id tile; + + @Override + public Id getId() { + return ID; + } + + @Override + public CompoundTag toTag(CompoundTag tag) { + tag.put("tile", this.tile == null ? "NULL" : this.tile.toString()); + return tag; + } + + @Override + public void fromTag(CompoundTag tag) { + String tile = tag.getString("tile"); + + if (tile.equals("NULL")) { + this.tile = null; + } else { + this.tile = new Id(tile); + } + } + + @Override + public AttachedData copy() { + return new TestAxeData(this.tile); + } + + public static final Id ID = new Id("modid", "test_axe"); + } +} diff --git a/src/test/java/io/github/minecraftcursedlegacy/testmixin/MixinPlayer.java b/src/test/java/io/github/minecraftcursedlegacy/testmixin/MixinPlayer.java new file mode 100644 index 00000000..dadcaf9f --- /dev/null +++ b/src/test/java/io/github/minecraftcursedlegacy/testmixin/MixinPlayer.java @@ -0,0 +1,13 @@ +package io.github.minecraftcursedlegacy.testmixin; + +import org.spongepowered.asm.mixin.Mixin; + +import net.minecraft.entity.player.Player; + +@Mixin(Player.class) +public class MixinPlayer { +// @Inject(at = @At("HEAD"), method = "dropItem(Lnet/minecraft/item/ItemInstance;Z)V") +// private void dropItem(ItemInstance arg, boolean flag, CallbackInfo info) { +// System.out.println(DataManager.ITEM_INSTANCE.getAttachedData(arg, ItemDataTest.test_axe).tile); +// } +} diff --git a/src/test/resources/fabric.mod.json b/src/test/resources/fabric.mod.json index 3919180a..0ea20923 100644 --- a/src/test/resources/fabric.mod.json +++ b/src/test/resources/fabric.mod.json @@ -21,7 +21,8 @@ "init": [ "io.github.minecraftcursedlegacy.test.RegistryTest", "io.github.minecraftcursedlegacy.test.LevelGenTest", - "io.github.minecraftcursedlegacy.test.AtlasTest" + "io.github.minecraftcursedlegacy.test.AtlasTest", + "io.github.minecraftcursedlegacy.test.ItemDataTest" ] }, @@ -29,5 +30,9 @@ "fabricloader": "*", "api": "*", "minecraft": "1.0.0-beta.7.3" - } + }, + + "mixins": [ + "test.mixins.json" + ] } diff --git a/src/test/resources/test.mixins.json b/src/test/resources/test.mixins.json new file mode 100644 index 00000000..42af24f0 --- /dev/null +++ b/src/test/resources/test.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "io.github.minecraftcursedlegacy.testmixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "MixinPlayer" + ], + "injectors": { + "defaultRequire": 1 + } +}