Abstract altar inventory handling for usage elsewhere
This commit is contained in:
parent
9a6d8d6d60
commit
fb94914b91
|
@ -4,6 +4,7 @@ import WayofTime.bloodmagic.BloodMagic;
|
||||||
import WayofTime.bloodmagic.api.altar.IAltarManipulator;
|
import WayofTime.bloodmagic.api.altar.IAltarManipulator;
|
||||||
import WayofTime.bloodmagic.api.iface.IAltarReader;
|
import WayofTime.bloodmagic.api.iface.IAltarReader;
|
||||||
import WayofTime.bloodmagic.tile.TileAltar;
|
import WayofTime.bloodmagic.tile.TileAltar;
|
||||||
|
import WayofTime.bloodmagic.util.Utils;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -64,17 +65,7 @@ public class BlockAltar extends BlockContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (altar.getStackInSlot(0) == null && playerItem != null) {
|
Utils.insertItemToTile(altar, player);
|
||||||
ItemStack newItem = playerItem.copy();
|
|
||||||
newItem.stackSize = 1;
|
|
||||||
playerItem.stackSize--;
|
|
||||||
altar.setInventorySlotContents(0, newItem);
|
|
||||||
// altar.startCycle();
|
|
||||||
} else if (altar.getStackInSlot(0) != null && playerItem == null) {
|
|
||||||
player.inventory.addItemStackToInventory(altar.getStackInSlot(0));
|
|
||||||
altar.clear();
|
|
||||||
// altar.setActive();
|
|
||||||
}
|
|
||||||
|
|
||||||
world.markBlockForUpdate(pos);
|
world.markBlockForUpdate(pos);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package WayofTime.bloodmagic.util;
|
package WayofTime.bloodmagic.util;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.tile.TileInventory;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
public static boolean isInteger(String integer) {
|
public static boolean isInteger(String integer) {
|
||||||
|
@ -13,4 +18,27 @@ public class Utils {
|
||||||
// only got here if we didn't return false
|
// only got here if we didn't return false
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for inserting an ItemStack with a stacksize of 1 to a tile's inventory at slot 0.
|
||||||
|
*
|
||||||
|
* EG: Block Altar
|
||||||
|
*
|
||||||
|
* @param tile - The {@link TileInventory} to input the item to
|
||||||
|
* @param player - The player to take the item from.
|
||||||
|
*/
|
||||||
|
public static void insertItemToTile(TileInventory tile, EntityPlayer player) {
|
||||||
|
if (tile.getStackInSlot(0) == null && player.getHeldItem() != null) {
|
||||||
|
ItemStack input = player.getHeldItem().copy();
|
||||||
|
input.stackSize = 1;
|
||||||
|
player.getHeldItem().stackSize--;
|
||||||
|
tile.setInventorySlotContents(0, input);
|
||||||
|
} else if (tile.getStackInSlot(0) != null && player.getHeldItem() == null) {
|
||||||
|
if (!tile.getWorld().isRemote) {
|
||||||
|
EntityItem invItem = new EntityItem(tile.getWorld(), player.posX, player.posY + 0.25, player.posZ, tile.getStackInSlot(0));
|
||||||
|
tile.getWorld().spawnEntityInWorld(invItem);
|
||||||
|
}
|
||||||
|
tile.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue