mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-16 18:54:50 +00:00
Works!
This commit is contained in:
1 parent
63628854e6
commit
ccb06943df
4 files changed
+40
-25
No files matched your search
@@ -2,40 +2,39 @@ package com.myname.mymodid;
|
||||
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.registry.RegistryDelegate;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemStackKey {
|
||||
private final String modId;
|
||||
private final String itemName;
|
||||
private final Item item;
|
||||
private final int meta;
|
||||
|
||||
public ItemStackKey(String modId, String itemName, int meta) {
|
||||
this.modId = modId;
|
||||
this.itemName = itemName;
|
||||
public ItemStackKey(Item item, int meta) {
|
||||
this.item = item;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public ItemStackKey(ItemStack stack) {
|
||||
this(stack.getItem().getUnlocalizedName().substring(4),
|
||||
GameRegistry.findUniqueIdentifierFor(stack.getItem()).modId,
|
||||
stack.getItemDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ItemStackKey that = (ItemStackKey) o;
|
||||
return meta == that.meta &&
|
||||
Objects.equals(modId, that.modId) &&
|
||||
Objects.equals(itemName, that.itemName);
|
||||
return (this.meta == that.meta) && Objects.equals(this.item, that.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(modId, itemName, meta);
|
||||
return Objects.hash(item, meta);
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public RegistryDelegate<Item> getItem() {
|
||||
return item.delegate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraft.init.Items;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -19,6 +20,7 @@ public class MyMod {
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
ReplacementManager.addReplacement(Items.apple, 0, Items.bow, 10);
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReplacementManager {
|
||||
private static final Map<ItemStackKey, ItemStack> replacementMap = new HashMap<>();
|
||||
private static final Map<ItemStackKey, ItemStackKey> replacementMap = new HashMap<>();
|
||||
|
||||
public static void addReplacement(String modId, String itemName, int meta, ItemStack replacement) {
|
||||
replacementMap.put(new ItemStackKey(modId, itemName, meta), replacement);
|
||||
public static void addReplacement(Item itemIn, int metaIn, Item itemOut, int metaOut) {
|
||||
replacementMap.put(new ItemStackKey(itemIn, metaIn), new ItemStackKey(itemOut, metaOut));
|
||||
}
|
||||
|
||||
public static ItemStack getReplacement(ItemStack original) {
|
||||
return replacementMap.getOrDefault(new ItemStackKey(original), original);
|
||||
public static ItemStackKey getReplacement(Item itemIn, int metaIn) {
|
||||
ItemStackKey stackKey = new ItemStackKey(itemIn, metaIn);
|
||||
return replacementMap.getOrDefault(stackKey, stackKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
package com.myname.mymodid.mixins.early;
|
||||
|
||||
|
||||
import com.myname.mymodid.ItemStackKey;
|
||||
import com.myname.mymodid.ReplacementManager;
|
||||
import net.minecraft.init.Items;
|
||||
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.CallbackInfo;
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
public abstract class MixinItemStack{
|
||||
public abstract class MixinItemStack {
|
||||
|
||||
@Shadow
|
||||
private cpw.mods.fml.common.registry.RegistryDelegate<Item> delegate;
|
||||
@Shadow
|
||||
private int itemDamage; // Metadata
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/item/Item;II)V", at = @At("RETURN"))
|
||||
private void onConstructorHead(Item item, int stackSize, int metadata, CallbackInfo ci) {
|
||||
System.out.println(item.getUnlocalizedName() + " " + metadata + " " + stackSize);
|
||||
private void onConstructorHead(Item item, int size, int metadata, CallbackInfo ci) {
|
||||
ItemStackKey replacement = ReplacementManager.getReplacement(item, metadata);
|
||||
|
||||
// Edit private variables here.
|
||||
itemDamage = replacement.getDamage();
|
||||
delegate = replacement.getItem();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user