trying to fix capabilities
This commit is contained in:
@@ -6,7 +6,7 @@ org.gradle.jvmargs=-Xmx3G
|
||||
mod_group=nmd.primal.forgecraft
|
||||
mod_name=ForgeCraft
|
||||
|
||||
mod_version=1.6.08
|
||||
mod_version=1.6.10
|
||||
forge_version=14.23.4.2744
|
||||
mcp_mappings=snapshot_20171003
|
||||
mc_version=1.12.2
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ModInfo {
|
||||
//public static final String MOD_PREFIX = MOD_ID + ":";
|
||||
public static final String MOD_CHANNEL = MOD_ID;
|
||||
|
||||
public static final String MOD_VERSION = "1.6.08";
|
||||
public static final String MOD_VERSION = "1.6.10";
|
||||
public static final String MC_VERSIONS = "[1.12.0, 1.13.0)";
|
||||
public static final String DEPENDENCIES = "required-after:forge@[14.21.1.2400,);" + "required-after:primal@[0.6.69,);";
|
||||
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
package nmd.primal.forgecraft.capabilities;
|
||||
|
||||
/*
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class SlottedTongsHandler implements ICapabilitySerializable<NBTTagCompound>, IItemHandler {
|
||||
|
||||
@CapabilityInject(SlottedTongsHandler.class)
|
||||
public static Capability<SlottedTongsHandler> CAP;
|
||||
|
||||
private IChangeCallback callback;
|
||||
public final Map<ItemEntry, ItemEntryWithCount> items;
|
||||
private ItemEntryWithCount[] itemsArray;
|
||||
private int totalItemCount;
|
||||
private NBTTagCompound cachedNetData;
|
||||
|
||||
public static AntibarrelData get(ItemStack stack)
|
||||
{
|
||||
AntibarrelData data = stack.getCapability(CAP, null);
|
||||
|
||||
if (BlockUtils.hasData(stack))
|
||||
{
|
||||
data.deserializeNBT(BlockUtils.getData(stack));
|
||||
BlockUtils.removeData(stack);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public SlottedTongsHandler(@Nullable IChangeCallback c)
|
||||
{
|
||||
callback = c;
|
||||
items = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
items.clear();
|
||||
itemsArray = null;
|
||||
totalItemCount = -1;
|
||||
cachedNetData = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
return capability == CAP || capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
return capability == CAP || capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? (T) this : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeNBT()
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for (ItemEntryWithCount entry : items.values())
|
||||
{
|
||||
if (!entry.isEmpty())
|
||||
{
|
||||
list.appendTag(entry.serializeNBT());
|
||||
}
|
||||
}
|
||||
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
nbt.setTag("Inv", list);
|
||||
}
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public NBTTagCompound serializeNBTForNet()
|
||||
{
|
||||
if (cachedNetData != null)
|
||||
{
|
||||
return cachedNetData;
|
||||
}
|
||||
|
||||
cachedNetData = new NBTTagCompound();
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for (ItemEntryWithCount entry : items.values())
|
||||
{
|
||||
if (!entry.isEmpty())
|
||||
{
|
||||
list.appendTag(entry.serializeNBT());
|
||||
}
|
||||
}
|
||||
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
cachedNetData.setTag("Inv", list);
|
||||
}
|
||||
|
||||
return cachedNetData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTTagCompound nbt)
|
||||
{
|
||||
clear();
|
||||
|
||||
NBTTagList list = nbt.getTagList("Inv", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound nbt1 = list.getCompoundTagAt(i);
|
||||
ItemEntryWithCount entryc = new ItemEntryWithCount(nbt1);
|
||||
|
||||
if (!entryc.isEmpty())
|
||||
{
|
||||
items.put(entryc.entry, entryc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void copyFrom(AntibarrelData data)
|
||||
{
|
||||
clear();
|
||||
totalItemCount = data.totalItemCount;
|
||||
|
||||
for (ItemEntryWithCount entry : data.items.values())
|
||||
{
|
||||
items.put(entry.entry, new ItemEntryWithCount(entry.entry, entry.count));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return items.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return slot <= 0 || slot > items.size() ? ItemStack.EMPTY : getItemArray()[slot - 1].getStack(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
|
||||
{
|
||||
if (slot < 0 || slot > items.size() || stack.isEmpty() || stack.isStackable())
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
ItemEntry entry = ItemEntry.get(stack);
|
||||
ItemEntryWithCount entryc;
|
||||
int added = 0;
|
||||
|
||||
if (slot == 0)
|
||||
{
|
||||
entryc = items.get(entry);
|
||||
|
||||
if (entryc != null)
|
||||
{
|
||||
added = Math.min(YabbaConfig.general.antibarrel_items_per_type - entryc.count, stack.getCount());
|
||||
}
|
||||
else if (items.size() < YabbaConfig.general.antibarrel_capacity)
|
||||
{
|
||||
entryc = new ItemEntryWithCount(entry, 0);
|
||||
items.put(entry, entryc);
|
||||
itemsArray = null;
|
||||
totalItemCount = -1;
|
||||
cachedNetData = null;
|
||||
added = Math.min(YabbaConfig.general.antibarrel_items_per_type, stack.getCount());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entryc = getItemArray()[slot - 1];
|
||||
|
||||
if (entryc.entry.equalsEntry(entry))
|
||||
{
|
||||
added = Math.min(YabbaConfig.general.antibarrel_items_per_type - entryc.count, stack.getCount());
|
||||
}
|
||||
}
|
||||
|
||||
if (entryc != null && added > 0)
|
||||
{
|
||||
if (!simulate)
|
||||
{
|
||||
entryc.count += added;
|
||||
totalItemCount = -1;
|
||||
cachedNetData = null;
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
callback.onContentsChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
return added == stack.getCount() ? ItemStack.EMPTY : ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - added);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate)
|
||||
{
|
||||
if (slot <= 0 || slot > items.size() || amount < 1)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemEntryWithCount entryc = getItemArray()[slot - 1];
|
||||
|
||||
if (entryc.isEmpty())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
int extracted = Math.min(amount, entryc.count);
|
||||
|
||||
ItemStack is = entryc.entry.getStack(extracted, true);
|
||||
|
||||
if (!simulate)
|
||||
{
|
||||
entryc.count -= extracted;
|
||||
totalItemCount = -1;
|
||||
cachedNetData = null;
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
callback.onContentsChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
private ItemEntryWithCount[] getItemArray()
|
||||
{
|
||||
if (itemsArray == null)
|
||||
{
|
||||
itemsArray = items.values().toArray(new ItemEntryWithCount[0]);
|
||||
}
|
||||
|
||||
return itemsArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot)
|
||||
{
|
||||
return YabbaConfig.general.antibarrel_items_per_type;
|
||||
}
|
||||
|
||||
public int getTotalItemCount()
|
||||
{
|
||||
if (totalItemCount >= 0)
|
||||
{
|
||||
return totalItemCount;
|
||||
}
|
||||
|
||||
totalItemCount = 0;
|
||||
|
||||
for (ItemEntryWithCount entry : items.values())
|
||||
{
|
||||
totalItemCount += entry.count;
|
||||
}
|
||||
|
||||
return totalItemCount;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -210,8 +210,10 @@ public class BaseMultiItem extends BaseItem {
|
||||
}
|
||||
}
|
||||
if(!entityItem.isWet()){
|
||||
FireHelper.setFire(entityItem.getEntityWorld(),entityItem.getPosition());
|
||||
return true;
|
||||
if(entityItem.getItem().getTagCompound().getBoolean("hot")) {
|
||||
FireHelper.setFire(entityItem.getEntityWorld(), entityItem.getPosition());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -7,13 +7,14 @@ import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.item.IItemPropertyGetter;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
//TODO remove wildcard import
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -23,6 +24,7 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import nmd.primal.core.api.PrimalAPI;
|
||||
@@ -40,6 +42,7 @@ import nmd.primal.forgecraft.items.blocks.ItemNBTCrucible;
|
||||
import nmd.primal.forgecraft.items.parts.ToolPart;
|
||||
import nmd.primal.forgecraft.tiles.TileNBTCrucible;
|
||||
import nmd.primal.forgecraft.util.AnvilHandler;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
@@ -53,6 +56,7 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
|
||||
@CapabilityInject(IItemHandler.class)
|
||||
public static Capability<IItemHandler> ITEM_HANDLER;
|
||||
//public static CapabilityItemHandler ITEM_HANDLER;
|
||||
|
||||
public SlottedTongs(String unlocalizedName) {
|
||||
setUnlocalizedName(unlocalizedName);
|
||||
@@ -68,6 +72,8 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
|
||||
IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null);
|
||||
ItemStack slotStack = inventory.getStackInSlot(0);
|
||||
|
||||
|
||||
//System.out.println(stack.getTagCompound());
|
||||
|
||||
if (stack.getItem() instanceof SlottedTongs) {
|
||||
@@ -303,12 +309,12 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
|
||||
if (!(block instanceof AnvilBase)) {
|
||||
if (!(block instanceof Forge)) {
|
||||
System.out.println(inventory.getStackInSlot(0));
|
||||
if (slotStack.isEmpty()) {
|
||||
if (block instanceof NBTCrucible) {
|
||||
ItemStack tempStack = takeBlock(world, pos, state, face, player, block).copy();
|
||||
inventory.insertItem(0, tempStack, false);
|
||||
world.setBlockState(pos, this.getReplacementBlock(world, pos, state));
|
||||
itemstack.getItem().updateItemStackNBT(itemstack.getTagCompound());
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -322,6 +328,7 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
IBlockState iblockstate1 = temp.getBlock().getStateForPlacement(world, pos, face, hitx, hity, hitz, i, player, hand);
|
||||
temp.placeBlockAt(slotStack, player, world, pos.up(1), face, hitx, hity, hitz, iblockstate1);
|
||||
inventory.extractItem(0, 1, false);
|
||||
itemstack.getItem().updateItemStackNBT(itemstack.getTagCompound());
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -404,6 +411,7 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return EnumActionResult.FAIL;
|
||||
@@ -437,7 +445,7 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
if(!stack.isEmpty())
|
||||
/*if(!stack.isEmpty())
|
||||
{
|
||||
IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null);
|
||||
ItemStack slotStack = inventory.getStackInSlot(0).copy();
|
||||
@@ -459,9 +467,10 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
tooltip.add(ChatFormatting.BLUE + "Lapis Level: " + getLapisLevel(item) );
|
||||
}
|
||||
tooltip.add(ChatFormatting.LIGHT_PURPLE + "Damage: " + item.getItemDamage() );
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -470,6 +479,7 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
return new ICapabilityProvider()
|
||||
{
|
||||
final ItemStackHandler itemHandler = new ItemStackHandler(1);
|
||||
private NBTTagCompound cachedNetData;
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
|
||||
@@ -488,40 +498,45 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
|
||||
return (T) itemHandler;
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Update this with what you need to send to the client
|
||||
*/
|
||||
@Override
|
||||
public NBTTagCompound getNBTShareTag(ItemStack stack)
|
||||
{
|
||||
//return stack.getCapability(ITEM_HANDLER, null).
|
||||
/*
|
||||
AntibarrelData data = stack.getCapability(CAP, null);
|
||||
|
||||
if (BlockUtils.hasData(stack))
|
||||
{
|
||||
data.deserializeNBT(BlockUtils.getData(stack));
|
||||
BlockUtils.removeData(stack);
|
||||
}
|
||||
*/
|
||||
|
||||
IItemHandler data = stack.getCapability(ITEM_HANDLER, null);
|
||||
|
||||
|
||||
System.out.println("Does getNBT ever run");
|
||||
return stack.getTagCompound();
|
||||
}
|
||||
|
||||
/**
|
||||
* What does the item do when it receives nbt Info
|
||||
*/
|
||||
@Override
|
||||
public void readNBTShareTag(ItemStack stack, @Nullable NBTTagCompound nbt)
|
||||
{
|
||||
System.out.println("Does readNBT ever run");
|
||||
if (nbt != null)
|
||||
{
|
||||
AntibarrelData.get(stack).deserializeNBT(nbt);
|
||||
stack.setTagCompound(nbt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getShareTag()
|
||||
{
|
||||
System.out.println("Getting share tag");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateItemStackNBT(NBTTagCompound nbt)
|
||||
{
|
||||
System.out.println("Update NBT");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -300,8 +300,10 @@ public class ToolPart extends Item implements ToolNBT{
|
||||
}
|
||||
}
|
||||
if(!entityItem.isWet()){
|
||||
FireHelper.setFire(entityItem.getEntityWorld(),entityItem.getPosition());
|
||||
return true;
|
||||
if(entityItem.getItem().getTagCompound().getBoolean("hot")) {
|
||||
FireHelper.setFire(entityItem.getEntityWorld(), entityItem.getPosition());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"modid": "forgecraft",
|
||||
"name": "Kitsu's Forgecraft",
|
||||
"description": "Forged with sweat and blood",
|
||||
"version": "1.6.08",
|
||||
"version": "1.6.10",
|
||||
"mcversion": "1.12.2",
|
||||
"url": "",
|
||||
"updateUrl": "",
|
||||
|
||||
Reference in New Issue
Block a user