Working on a new implementation of the loot ball mechanics, still buggy
This commit is contained in:
parent
39585ef5cb
commit
fafb96ce2a
|
@ -119,6 +119,8 @@ public class ConfigurationManager {
|
|||
DARK_MATTER_ARMOR = prop.getInt();
|
||||
prop = config.getOrCreateIntProperty("wardOfXeno", CATEGORY_ITEM, 27297);
|
||||
WARD_OF_XENOPHOBIA = prop.getInt();
|
||||
prop = config.getOrCreateIntProperty("lootBall", CATEGORY_ITEM, 27298);
|
||||
LOOT_BALL = prop.getInt();
|
||||
|
||||
/* Keybinds */
|
||||
prop = config.getOrCreateIntProperty("extra", CATEGORY_KEYBIND, 46);
|
||||
|
|
38
ee3_common/ee3/core/PickupHandler.java
Normal file
38
ee3_common/ee3/core/PickupHandler.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package ee3.core;
|
||||
|
||||
import ee3.item.ItemLootBall;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.forge.IPickupHandler;
|
||||
|
||||
public class PickupHandler implements IPickupHandler {
|
||||
|
||||
public PickupHandler() { }
|
||||
|
||||
@Override
|
||||
public boolean onItemPickup(EntityPlayer player, EntityItem entityItem) {
|
||||
ItemStack itemstack = entityItem.item;
|
||||
|
||||
if (itemstack == null || itemstack.stackSize <= 0)
|
||||
return false;
|
||||
|
||||
if (entityItem.item.getItem() instanceof ItemLootBall) {
|
||||
System.out.println("Found a loot ball");
|
||||
|
||||
ItemLootBall lootBall = (ItemLootBall) itemstack.getItem();
|
||||
ItemStack[] loot = lootBall.inventory.getInventoryContents();
|
||||
if (loot != null)
|
||||
for (int i = 0; i < loot.length; i++) {
|
||||
if (player.inventory.addItemStackToInventory(loot[i]) == false)
|
||||
player.dropPlayerItem(loot[i]);
|
||||
}
|
||||
|
||||
// Destroy the itemstack
|
||||
itemstack.stackSize = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
75
ee3_common/ee3/item/InventoryLootBall.java
Normal file
75
ee3_common/ee3/item/InventoryLootBall.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
package ee3.item;
|
||||
|
||||
import ee3.lib.Reference;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.NBTTagList;
|
||||
|
||||
public class InventoryLootBall implements IInventory {
|
||||
|
||||
public ItemStack parent;
|
||||
public ItemStack[] inventoryStacks;
|
||||
|
||||
public InventoryLootBall(int i) {
|
||||
inventoryStacks = new ItemStack[i];
|
||||
}
|
||||
|
||||
public InventoryLootBall(ItemStack parent, ItemStack[] itemStacks) {
|
||||
this.parent = parent;
|
||||
this.inventoryStacks = itemStacks;
|
||||
|
||||
readFromNBT(parent.getTagCompound());
|
||||
}
|
||||
|
||||
private void save() {
|
||||
NBTTagCompound nbttagcompound = parent.getTagCompound();
|
||||
if(nbttagcompound == null)
|
||||
nbttagcompound = new NBTTagCompound();
|
||||
writeToNBT(nbttagcompound);
|
||||
parent.setTagCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
if(nbttagcompound == null)
|
||||
return;
|
||||
|
||||
if(nbttagcompound.hasKey("Items")) {
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
|
||||
inventoryStacks = new ItemStack[getSizeInventory()];
|
||||
for(int i = 0; i < nbttaglist.tagCount(); i++) {
|
||||
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
|
||||
byte byte0 = nbttagcompound1.getByte("Slot");
|
||||
if(byte0 >= 0 && byte0 < inventoryStacks.length)
|
||||
inventoryStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
for(int i = 0; i < inventoryStacks.length; i++)
|
||||
if(inventoryStacks[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte)i);
|
||||
inventoryStacks[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
nbttagcompound.setTag("Items", nbttaglist);
|
||||
}
|
||||
|
||||
public ItemStack[] getInventoryContents() { return inventoryStacks; }
|
||||
@Override public int getSizeInventory() { return inventoryStacks.length; }
|
||||
@Override public ItemStack getStackInSlot(int var1) { return inventoryStacks[var1]; }
|
||||
@Override public ItemStack decrStackSize(int var1, int var2) { return null; }
|
||||
@Override public ItemStack getStackInSlotOnClosing(int var1) { return null; }
|
||||
@Override public void setInventorySlotContents(int var1, ItemStack var2) { inventoryStacks[var1] = var2; }
|
||||
@Override public String getInvName() { return "Loot Ball"; }
|
||||
@Override public int getInventoryStackLimit() { return 64; }
|
||||
@Override public void onInventoryChanged() { }
|
||||
@Override public boolean isUseableByPlayer(EntityPlayer var1) { return true; }
|
||||
@Override public void openChest() { }
|
||||
@Override public void closeChest() { }
|
||||
}
|
23
ee3_common/ee3/item/ItemLootBall.java
Normal file
23
ee3_common/ee3/item/ItemLootBall.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package ee3.item;
|
||||
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class ItemLootBall extends ItemEE {
|
||||
|
||||
public InventoryLootBall inventory;
|
||||
|
||||
public ItemLootBall(int i) {
|
||||
super(i);
|
||||
inventory = new InventoryLootBall(new ItemStack(this), null);
|
||||
}
|
||||
|
||||
public ItemLootBall(int i, ItemStack[] itemStack) {
|
||||
super(i);
|
||||
inventory = new InventoryLootBall(new ItemStack(this), itemStack);
|
||||
}
|
||||
|
||||
public void setInventory(ItemStack[] items) {
|
||||
inventory = new InventoryLootBall(new ItemStack(this), items);
|
||||
}
|
||||
}
|
|
@ -14,18 +14,24 @@ public class ModItems {
|
|||
private static boolean initialized;
|
||||
|
||||
public static Item philStone;
|
||||
public static Item lootBall;
|
||||
|
||||
public static void init() {
|
||||
if (initialized)
|
||||
initialized = true;
|
||||
|
||||
System.out.println("philStone: " + ItemIds.PHIL_STONE);
|
||||
System.out.println("lootBall: " + ItemIds.LOOT_BALL);
|
||||
|
||||
/* Initialise each mod item individually */
|
||||
philStone = new ItemPhilosopherStone(ItemIds.PHIL_STONE).setIconCoord(0, 0).setItemName("philStone");
|
||||
lootBall = new ItemLootBall(ItemIds.LOOT_BALL).setIconCoord(11, 6).setItemName("lootBall");
|
||||
|
||||
/* Set the Container items for our mod items */
|
||||
philStone.setContainerItem(philStone);
|
||||
|
||||
/* Add the item names to the mod items */
|
||||
ModLoader.addName(philStone, "Philosopher's Stone");
|
||||
ModLoader.addName(lootBall, "Loot Ball");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ package ee3.lib;
|
|||
*/
|
||||
public class ItemIds {
|
||||
public static int IMPERFECT_PHIL_STONE;
|
||||
public static int PHIL_STONE;
|
||||
public static int PHIL_STONE = 27271;
|
||||
public static int DJINN_RING;
|
||||
public static int EYE_OF_THE_VOID;
|
||||
public static int IDOL_OF_GAIA;
|
||||
|
@ -36,4 +36,5 @@ public class ItemIds {
|
|||
public static int DARK_MATTER_BOW;
|
||||
public static int DARK_MATTER_FISHING_ROD;
|
||||
public static int DARK_MATTER_ARMOR;
|
||||
public static int LOOT_BALL = 27298;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public class Reference {
|
|||
public static final String CONFIG_FILE = "EE3.cfg";
|
||||
public static final String CONFIG_DIR = "config/ee3/";
|
||||
|
||||
public static final String SPRITE_SHEET_LOCATION = "/ee3/art/sprites/";
|
||||
public static final String SPRITE_SHEET_LOCATION = "/ee3/ee3/art/sprites/";
|
||||
public static final String ITEM_SPRITE_SHEET = "eqexsheet.png";
|
||||
public static final String GUI_SHEET_LOCATION = "/ee3/art/gui/";
|
||||
public static final String ARMOR_SHEET_LOCATION = "/ee3/art/armor/";
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.minecraft.src;
|
|||
|
||||
import ee3.addons.BuildCraftAddon;
|
||||
import ee3.core.ConfigurationManager;
|
||||
import ee3.core.PickupHandler;
|
||||
import ee3.core.RecipesPhilStone;
|
||||
import ee3.core.ServerClientProxy;
|
||||
import ee3.core.Version;
|
||||
|
@ -59,6 +60,8 @@ public class mod_EE3 extends NetworkMod {
|
|||
RecipesPhilStone.initRecipes();
|
||||
|
||||
BuildCraftAddon.init();
|
||||
|
||||
MinecraftForge.registerPickupHandler(new PickupHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue