Creation of 1.16.3 branch
Initial publishing of the 1.16.3 branch of the mod. A lot of systems are missing (such as Rituals and Living Armour), but enough is present for a decent Alpha release.
This commit is contained in:
parent
0e02b983f1
commit
d617911d7a
1662 changed files with 18791 additions and 85075 deletions
src/main/java/WayofTime/bloodmagic/tile
|
@ -1,261 +1,317 @@
|
|||
package WayofTime.bloodmagic.tile;
|
||||
package wayoftime.bloodmagic.tile;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import WayofTime.bloodmagic.tile.base.TileBase;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
import wayoftime.bloodmagic.tile.base.TileBase;
|
||||
|
||||
public class TileInventory extends TileBase implements IInventory {
|
||||
protected int[] syncedSlots = new int[0];
|
||||
protected NonNullList<ItemStack> inventory;
|
||||
IItemHandler handlerDown;
|
||||
IItemHandler handlerUp;
|
||||
IItemHandler handlerNorth;
|
||||
IItemHandler handlerSouth;
|
||||
IItemHandler handlerWest;
|
||||
IItemHandler handlerEast;
|
||||
private int size;
|
||||
public class TileInventory extends TileBase implements IInventory
|
||||
{
|
||||
protected int[] syncedSlots = new int[0];
|
||||
protected NonNullList<ItemStack> inventory;
|
||||
LazyOptional<IItemHandler> handlerDown;
|
||||
LazyOptional<IItemHandler> handlerUp;
|
||||
LazyOptional<IItemHandler> handlerNorth;
|
||||
LazyOptional<IItemHandler> handlerSouth;
|
||||
LazyOptional<IItemHandler> handlerWest;
|
||||
LazyOptional<IItemHandler> handlerEast;
|
||||
private int size;
|
||||
|
||||
// IInventory
|
||||
private String name;
|
||||
// IInventory
|
||||
private String name;
|
||||
|
||||
public TileInventory(int size, String name) {
|
||||
this.inventory = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
this.size = size;
|
||||
this.name = name;
|
||||
initializeItemHandlers();
|
||||
}
|
||||
public TileInventory(TileEntityType<?> type, int size, String name)
|
||||
{
|
||||
super(type);
|
||||
this.inventory = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
this.size = size;
|
||||
this.name = name;
|
||||
initializeItemHandlers();
|
||||
}
|
||||
|
||||
protected boolean isSyncedSlot(int slot) {
|
||||
for (int s : this.syncedSlots) {
|
||||
if (s == slot) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected boolean isSyncedSlot(int slot)
|
||||
{
|
||||
for (int s : this.syncedSlots)
|
||||
{
|
||||
if (s == slot)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(CompoundNBT tagCompound) {
|
||||
super.deserialize(tagCompound);
|
||||
ListNBT tags = tagCompound.getTagList("Items", 10);
|
||||
inventory = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
@Override
|
||||
public void deserialize(CompoundNBT tagCompound)
|
||||
{
|
||||
super.deserialize(tagCompound);
|
||||
|
||||
for (int i = 0; i < tags.tagCount(); i++) {
|
||||
if (!isSyncedSlot(i)) {
|
||||
CompoundNBT data = tags.getCompound(i);
|
||||
byte j = data.getByte("Slot");
|
||||
this.inventory = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
if (j >= 0 && j < inventory.size()) {
|
||||
inventory.set(j, new ItemStack(data)); // No matter how much an i looks like a j, it is not one. They are drastically different characters and cause drastically different things to happen. Apparently I didn't know this at one point. - TehNut
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemStackHelper.loadAllItems(tagCompound, this.inventory);
|
||||
|
||||
@Override
|
||||
public CompoundNBT serialize(CompoundNBT tagCompound) {
|
||||
super.serialize(tagCompound);
|
||||
ListNBT tags = new ListNBT();
|
||||
// ListNBT tags = tagCompound.getList("Items", 10);
|
||||
// inventory = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
//
|
||||
//
|
||||
//
|
||||
// for (int i = 0; i < tags.size(); i++)
|
||||
// {
|
||||
// if (!isSyncedSlot(i))
|
||||
// {
|
||||
// CompoundNBT data = tags.getCompoundTagAt(i);
|
||||
// byte j = data.getByte("Slot");
|
||||
//
|
||||
// if (j >= 0 && j < inventory.size())
|
||||
// {
|
||||
// inventory.set(j, new ItemStack(data)); // No matter how much an i looks like a j, it is not one.
|
||||
// // They are drastically different characters and cause
|
||||
// // drastically different things to happen. Apparently I
|
||||
// // didn't know this at one point. - TehNut
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
if ((!inventory.get(i).isEmpty()) && !isSyncedSlot(i)) {
|
||||
CompoundNBT data = new CompoundNBT();
|
||||
data.setByte("Slot", (byte) i);
|
||||
inventory.get(i).writeToNBT(data);
|
||||
tags.appendTag(data);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public CompoundNBT serialize(CompoundNBT tagCompound)
|
||||
{
|
||||
super.serialize(tagCompound);
|
||||
|
||||
tagCompound.putTag("Items", tags);
|
||||
return tagCompound;
|
||||
}
|
||||
ItemStackHelper.saveAllItems(tagCompound, this.inventory);
|
||||
// NBTTagList tags = new NBTTagList();
|
||||
//
|
||||
// for (int i = 0; i < inventory.size(); i++)
|
||||
// {
|
||||
// if ((!inventory.get(i).isEmpty()) && !isSyncedSlot(i))
|
||||
// {
|
||||
// CompoundNBT data = new CompoundNBT();
|
||||
// data.putByte("Slot", (byte) i);
|
||||
// inventory.get(i).write(data);
|
||||
// tags.appendTag(data);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// tagCompound.setTag("Items", tags);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
public void dropItems() {
|
||||
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);
|
||||
}
|
||||
public void dropItems()
|
||||
{
|
||||
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return size;
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index) {
|
||||
return inventory.get(index);
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
return inventory.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count) {
|
||||
if (!getStackInSlot(index).isEmpty()) {
|
||||
if (!getWorld().isRemote)
|
||||
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count)
|
||||
{
|
||||
if (!getStackInSlot(index).isEmpty())
|
||||
{
|
||||
if (!getWorld().isRemote)
|
||||
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
|
||||
|
||||
if (getStackInSlot(index).getCount() <= count) {
|
||||
ItemStack itemStack = inventory.get(index);
|
||||
inventory.set(index, ItemStack.EMPTY);
|
||||
markDirty();
|
||||
return itemStack;
|
||||
}
|
||||
if (getStackInSlot(index).getCount() <= count)
|
||||
{
|
||||
ItemStack itemStack = inventory.get(index);
|
||||
inventory.set(index, ItemStack.EMPTY);
|
||||
markDirty();
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ItemStack itemStack = inventory.get(index).splitStack(count);
|
||||
markDirty();
|
||||
return itemStack;
|
||||
}
|
||||
ItemStack itemStack = inventory.get(index).split(count);
|
||||
markDirty();
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot) {
|
||||
if (!inventory.get(slot).isEmpty()) {
|
||||
ItemStack itemStack = inventory.get(slot);
|
||||
setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
return itemStack;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot)
|
||||
{
|
||||
if (!inventory.get(slot).isEmpty())
|
||||
{
|
||||
ItemStack itemStack = inventory.get(slot);
|
||||
setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
return itemStack;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
inventory.set(slot, stack);
|
||||
if (!stack.isEmpty() && stack.getCount() > getInventoryStackLimit())
|
||||
stack.setCount(getInventoryStackLimit());
|
||||
markDirty();
|
||||
if (!getWorld().isRemote)
|
||||
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
inventory.set(slot, stack);
|
||||
if (!stack.isEmpty() && stack.getCount() > getInventoryStackLimit())
|
||||
stack.setCount(getInventoryStackLimit());
|
||||
markDirty();
|
||||
if (!getWorld().isRemote)
|
||||
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(PlayerEntity player) {
|
||||
@Override
|
||||
public void openInventory(PlayerEntity player)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(PlayerEntity player) {
|
||||
@Override
|
||||
public void closeInventory(PlayerEntity player)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// IWorldNameable
|
||||
// IWorldNameable
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return 0;
|
||||
}
|
||||
// @Override
|
||||
// public int getField(int id)
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setField(int id, int value)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getFieldCount()
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
this.inventory = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
for (ItemStack stack : inventory) if (!stack.isEmpty())
|
||||
return false;
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.inventory = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
}
|
||||
@Override
|
||||
public boolean isUsableByPlayer(PlayerEntity player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
for (ItemStack stack : inventory)
|
||||
if (!stack.isEmpty())
|
||||
return false;
|
||||
// @Override
|
||||
// public String getName()
|
||||
// {
|
||||
// return TextHelper.localize("tile.bloodmagic." + name + ".name");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean hasCustomName()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ITextComponent getDisplayName()
|
||||
// {
|
||||
// return new TextComponentString(getName());
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
protected void initializeItemHandlers()
|
||||
{
|
||||
if (this instanceof ISidedInventory)
|
||||
{
|
||||
handlerDown = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN));
|
||||
handlerUp = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN));
|
||||
handlerNorth = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN));
|
||||
handlerSouth = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN));
|
||||
handlerWest = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN));
|
||||
handlerEast = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN));
|
||||
} else
|
||||
{
|
||||
handlerDown = LazyOptional.of(() -> new InvWrapper(this));
|
||||
handlerUp = handlerDown;
|
||||
handlerNorth = handlerDown;
|
||||
handlerSouth = handlerDown;
|
||||
handlerWest = handlerDown;
|
||||
handlerEast = handlerDown;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer(PlayerEntity player) {
|
||||
return true;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing)
|
||||
{
|
||||
if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
{
|
||||
switch (facing)
|
||||
{
|
||||
case DOWN:
|
||||
return handlerDown.cast();
|
||||
case EAST:
|
||||
return handlerEast.cast();
|
||||
case NORTH:
|
||||
return handlerNorth.cast();
|
||||
case SOUTH:
|
||||
return handlerSouth.cast();
|
||||
case UP:
|
||||
return handlerUp.cast();
|
||||
case WEST:
|
||||
return handlerWest.cast();
|
||||
}
|
||||
} else if (facing == null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
{
|
||||
return handlerDown.cast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return TextHelper.localize("tile.bloodmagic." + name + ".name");
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new StringTextComponent(getName());
|
||||
}
|
||||
|
||||
protected void initializeItemHandlers() {
|
||||
if (this instanceof ISidedInventory) {
|
||||
handlerDown = new SidedInvWrapper((ISidedInventory) this, Direction.DOWN);
|
||||
handlerUp = new SidedInvWrapper((ISidedInventory) this, Direction.UP);
|
||||
handlerNorth = new SidedInvWrapper((ISidedInventory) this, Direction.NORTH);
|
||||
handlerSouth = new SidedInvWrapper((ISidedInventory) this, Direction.SOUTH);
|
||||
handlerWest = new SidedInvWrapper((ISidedInventory) this, Direction.WEST);
|
||||
handlerEast = new SidedInvWrapper((ISidedInventory) this, Direction.EAST);
|
||||
} else {
|
||||
handlerDown = new InvWrapper(this);
|
||||
handlerUp = handlerDown;
|
||||
handlerNorth = handlerDown;
|
||||
handlerSouth = handlerDown;
|
||||
handlerWest = handlerDown;
|
||||
handlerEast = handlerDown;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, Direction facing) {
|
||||
if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
switch (facing) {
|
||||
case DOWN:
|
||||
return (T) handlerDown;
|
||||
case EAST:
|
||||
return (T) handlerEast;
|
||||
case NORTH:
|
||||
return (T) handlerNorth;
|
||||
case SOUTH:
|
||||
return (T) handlerSouth;
|
||||
case UP:
|
||||
return (T) handlerUp;
|
||||
case WEST:
|
||||
return (T) handlerWest;
|
||||
}
|
||||
} else if (facing == null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
return (T) handlerDown;
|
||||
}
|
||||
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, Direction facing) {
|
||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public boolean hasCapability(Capability<?> capability, Direction facing)
|
||||
// {
|
||||
// return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
// }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue