trying to get this damn handler to work

This commit is contained in:
Mohammad-Ali Minaie
2018-09-22 20:10:45 -04:00
parent d5c64228ca
commit 10e5e3d537
7 changed files with 246 additions and 214 deletions

View File

@@ -33,8 +33,9 @@ public class AnvilStone extends AnvilBase {
ItemStack pItem = player.inventory.getCurrentItem();
TileAnvil tile = (TileAnvil) world.getTileEntity(pos);
ItemStack stack12 = tile.getSlotStack(12).copy();
if (hand.equals(hand.MAIN_HAND)) {
if (!world.isRemote) {
if (!world.isRemote) {
if (hand.equals(hand.MAIN_HAND)) {
if (!stack12.isEmpty()) {
if (tile != null) {
if ((pItem.getItem() instanceof Gallagher) || (pItem.getItem() == ModItems.forgehammer)) {
@@ -117,10 +118,11 @@ public class AnvilStone extends AnvilBase {
doAnvilRecipe(pItem, tempArray, world, tile, pos, player);
return true;
}
}
doAnvilInventoryManager(pItem, world, tile, pos, hitx, hity, hitz, state, player);
return true;
doAnvilInventoryManager(pItem, world, tile, pos, hitx, hity, hitz, state, player);
return true;
}
}
return false;
}

View File

@@ -24,6 +24,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import nmd.primal.core.api.PrimalAPI;
import nmd.primal.core.common.helper.PlayerHelper;
import nmd.primal.core.common.recipes.inworld.FireSource;
@@ -36,6 +37,8 @@ import nmd.primal.forgecraft.tiles.TileBloomery;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import static nmd.primal.forgecraft.items.SlottedTongs.ITEM_HANDLER;
/**
* Created by mminaie on 6/11/17.
*/
@@ -195,32 +198,42 @@ public class BloomeryBase extends CustomContainerFacing implements ITileEntityPr
/***SLOTTED TONGS CODE TO PLACE THE ITEMS***/
if(pItem.getItem() instanceof SlottedTongs) {
SlottedTongs temp = (SlottedTongs) pItem.getItem();
if (!pItem.isEmpty() && tile.isItemValidForSlot(1, temp.slotList.get(0))) {
IItemHandler inventory = pItem.getCapability(ITEM_HANDLER, null);
ItemStack slotStack = inventory.getStackInSlot(0).copy();
//SlottedTongs temp = (SlottedTongs) pItem.getItem();
if (!pItem.isEmpty() && tile.isItemValidForSlot(1, slotStack)) {
if (!tileItem1.isEmpty()) {
return false;
}
if(tileItem1.isEmpty()){
ItemStack place_stack = temp.slotList.get(0).copy();
ItemStack place_stack = slotStack.copy();
//if (tile.putStack(slot, place_stack))
tile.setSlotStack(1, place_stack);
temp.slotList.set(0, ItemStack.EMPTY);
inventory.insertItem(0, ItemStack.EMPTY, false);
return true;
}
}
}
/***SLOTTED TONGS CODE TO REMOVE THE ITEMS***/
if(pItem.getItem() instanceof SlottedTongs) {
SlottedTongs temp = (SlottedTongs) pItem.getItem();
if (!pItem.isEmpty() && temp.slotList.get(0).isEmpty()) {
IItemHandler inventory = pItem.getCapability(ITEM_HANDLER, null);
ItemStack slotStack = inventory.getStackInSlot(0).copy();
//SlottedTongs temp = (SlottedTongs) pItem.getItem();
if (!pItem.isEmpty() && inventory.getStackInSlot(0).isEmpty()) {
if (tileItem1.isEmpty()) {
return false;
}
if(!tileItem1.isEmpty()){
ItemStack place_stack = tileItem1.copy();
if(temp.slotList.get(0).isEmpty()){
temp.slotList.set(0, place_stack);
if(inventory.getStackInSlot(0).isEmpty()){
inventory.insertItem(0, place_stack, false);
tile.setSlotStack(1, ItemStack.EMPTY);
return true;
}

View File

@@ -23,6 +23,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import nmd.primal.forgecraft.CommonUtils;
import nmd.primal.forgecraft.ModInfo;
import nmd.primal.forgecraft.blocks.Crucibles.NBTCrucible;
@@ -41,6 +42,7 @@ import nmd.primal.forgecraft.util.ToolNBT;
import java.util.Random;
import static nmd.primal.core.api.PrimalAPI.randomCheck;
import static nmd.primal.forgecraft.items.SlottedTongs.ITEM_HANDLER;
/**
* Created by mminaie on 6/19/17.
@@ -63,13 +65,17 @@ public class CastingForm extends CustomContainerFacing implements CastingFormHan
if (!world.isRemote) {
TileCastingForm tile = (TileCastingForm) world.getTileEntity(pos);
ItemStack pItem = player.inventory.getCurrentItem();
IItemHandler inventory = pItem.getCapability(ITEM_HANDLER, null);
ItemStack slotStack = inventory.getStackInSlot(0).copy();
if(pItem.getItem() != ModItems.slottedtongs) {
doInventoryManager(pItem, world, tile, pos, hitx, hity, hitz, state, player);
}
if(pItem.getItem().equals(ModItems.slottedtongs)){
SlottedTongs tongs = (SlottedTongs) pItem.getItem();
if(tongs.getSlotList().get(0).getItem().equals(Item.getItemFromBlock(ModBlocks.nbtCrucible))) {
ItemStack tongsStack = tongs.getSlotList().get(0).copy();
if(slotStack.getItem().equals(Item.getItemFromBlock(ModBlocks.nbtCrucible))) {
ItemStack tongsStack = slotStack.copy();
NBTTagCompound tag = tongsStack.getTagCompound().copy();
if(tag != null){
@@ -120,7 +126,7 @@ public class CastingForm extends CustomContainerFacing implements CastingFormHan
tag.getCompoundTag("BlockEntityTag").setBoolean("status", false);
tag.getCompoundTag("BlockEntityTag").setInteger("hot", 0);
ItemStackHelper.saveAllItems(tag.getCompoundTag("BlockEntityTag"), ingListEmpty);
tongs.getSlotList().get(0).setTagCompound(tag);
inventory.getStackInSlot(0).setTagCompound(tag);
return true;
}
if(tagOutput == null){
@@ -131,7 +137,7 @@ public class CastingForm extends CustomContainerFacing implements CastingFormHan
tag.getCompoundTag("BlockEntityTag").setBoolean("status", false);
tag.getCompoundTag("BlockEntityTag").setInteger("hot", 0);
ItemStackHelper.saveAllItems(tag.getCompoundTag("BlockEntityTag"), ingListEmpty);
tongs.getSlotList().get(0).setTagCompound(tag);
inventory.getStackInSlot(0).setTagCompound(tag);
return true;
}
}

View File

@@ -93,78 +93,82 @@ public class Forge extends CustomContainerFacing implements ITileEntityProvider,
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
TileForge tile = (TileForge) world.getTileEntity(pos);
if (tile != null) {
if (hand.equals(player.getActiveHand())) {
ItemStack pItem = player.inventory.getCurrentItem().copy();
ItemStack fuelItem = tile.getSlotStack(0);
if (!world.isRemote) {
TileForge tile = (TileForge) world.getTileEntity(pos);
if (tile != null) {
if (hand.equals(player.getActiveHand())) {
if (!world.isRemote) {
/***********************
FUEL SLOT CODE
***********************/
if (!tile.getSlotStack(0).isEmpty()) {
if (player.inventory.getCurrentItem().getItem() instanceof ItemSpade) {
ItemStack returnStack = tile.getSlotStack(0).copy();
PlayerHelper.spawnItemOnPlayer(world, player, returnStack);
tile.clearSlot(0);
return true;
}
}
if (pItem.isEmpty()) {
if (!player.isSneaking()) {
if (world.getBlockState(pos).getValue(PrimalAPI.States.ACTIVE) == true) {
Integer tempInt = tile.getHeat();
String tempString = tempInt.toString();
ITextComponent itextcomponent = new TextComponentString(tempString);
player.sendStatusMessage(itextcomponent, true);
//System.out.println(pos);
ItemStack pItem = player.inventory.getCurrentItem().copy();
ItemStack fuelItem = tile.getSlotStack(0);
if (!world.isRemote) {
/***********************
FUEL SLOT CODE
***********************/
if (!tile.getSlotStack(0).isEmpty()) {
if (player.inventory.getCurrentItem().getItem() instanceof ItemSpade) {
ItemStack returnStack = tile.getSlotStack(0).copy();
PlayerHelper.spawnItemOnPlayer(world, player, returnStack);
tile.clearSlot(0);
return true;
}
}
}
if ((FireSource.useSource(world, pos, facing, player, hand, pItem, hitX, hitY, hitZ))) {
world.setBlockState(pos, state.withProperty(PrimalAPI.States.ACTIVE, true), 2);
tile.setHeat(100);
tile.markDirty();
tile.updateBlock();
return true;
}
if ((!pItem.isEmpty()) && tile.isItemValidForSlot(0, pItem)) {
if (!fuelItem.isEmpty()) {
if (pItem.getItem() == fuelItem.getItem()) {
if (fuelItem.getCount() < 64) {
if (fuelItem.getCount() + pItem.getCount() <= 64) {
fuelItem.grow(pItem.getCount());
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
tile.markDirty();
tile.updateBlock();
return true;
}
if (fuelItem.getCount() + pItem.getCount() > 64) {
pItem.setCount(64 - pItem.getCount());
fuelItem.setCount(64);
tile.markDirty();
tile.updateBlock();
return true;
}
if (pItem.isEmpty()) {
if (!player.isSneaking()) {
if (world.getBlockState(pos).getValue(PrimalAPI.States.ACTIVE) == true) {
Integer tempInt = tile.getHeat();
String tempString = tempInt.toString();
ITextComponent itextcomponent = new TextComponentString(tempString);
player.sendStatusMessage(itextcomponent, true);
//System.out.println(pos);
return true;
}
}
}
if (fuelItem.isEmpty()) {
tile.setSlotStack(0, pItem);
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
if ((FireSource.useSource(world, pos, facing, player, hand, pItem, hitX, hitY, hitZ))) {
world.setBlockState(pos, state.withProperty(PrimalAPI.States.ACTIVE, true), 2);
tile.setHeat(100);
tile.markDirty();
tile.updateBlock();
return true;
}
}
}
if ((!pItem.isEmpty()) && tile.isItemValidForSlot(0, pItem)) {
if (!fuelItem.isEmpty()) {
if (pItem.getItem() == fuelItem.getItem()) {
if (fuelItem.getCount() < 64) {
if (fuelItem.getCount() + pItem.getCount() <= 64) {
fuelItem.grow(pItem.getCount());
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
tile.markDirty();
tile.updateBlock();
return true;
}
if (fuelItem.getCount() + pItem.getCount() > 64) {
pItem.setCount(64 - pItem.getCount());
fuelItem.setCount(64);
tile.markDirty();
tile.updateBlock();
return true;
}
}
}
}
if (fuelItem.isEmpty()) {
tile.setSlotStack(0, pItem);
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
return true;
}
}
if (facing == EnumFacing.UP) {
doForgeInventoryManager(pItem, world, tile, pos, hitX, hitY, hitZ, state, player);
}
}
if (facing == EnumFacing.UP) {
doForgeInventoryManager(pItem, world, tile, pos, hitX, hitY, hitZ, state, player);
}
}
}
return false;
}

View File

@@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
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;
@@ -21,6 +22,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -51,8 +53,12 @@ import java.util.List;
/**
* Created by mminaie on 12/30/17.
*/
public class SlottedTongs extends Item implements IPickup, AnvilHandler{
@CapabilityInject(IItemHandler.class)
public static Capability<IItemHandler> ITEM_HANDLER;
public SlottedTongs(String unlocalizedName) {
setUnlocalizedName(unlocalizedName);
@@ -60,65 +66,61 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
this.setMaxStackSize(1);
this.setCreativeTab(ModInfo.TAB_FORGECRAFT);
@CapabilityInject(IItemHandler.class)
public static Capability<IItemHandler.class> ITEM_HANDLER;
this.addPropertyOverride(new ResourceLocation("type"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
{
SlottedTongs item = (SlottedTongs) stack.getItem();
ItemStack slotStack = item.getSlotList().get(0).copy();
IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null);
ItemStack slotStack = inventory.getStackInSlot(0).copy();
if (stack.getItem() instanceof SlottedTongs) {
if (slotStack.getItem() instanceof ItemNBTCrucible) {
/***Render Empty Crucible***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 0){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 0){
return 0.99f;
}
/***Render Level 1***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 1){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 1){
return 0.011f;
}
/***Render Level 2***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 2){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 2){
return 0.012f;
}
/***Render Level 3***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 3){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 3){
return 0.013f;
}
/***Render Level 4***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 4){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 4){
return 0.014f;
}
/***Render Level 5***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 5){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 5){
return 0.015f;
}
/***Render Level Cooked***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 6){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 6){
return 0.016f;
}
/***Render Failed***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 7){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 7){
return 0.017f;
}
/***Render Hot***/
if(item.getSlotList().get(0).getSubCompound("BlockEntityTag").getInteger("hot") == 15){
if(inventory.getStackInSlot(0).getSubCompound("BlockEntityTag").getInteger("hot") == 15){
return 0.025f;
}
}
if(slotStack.getItem() instanceof ToolPart){
ToolPart toolPart = (ToolPart) item.getSlotList().get(0).getItem();
ToolPart toolPart = (ToolPart) inventory.getStackInSlot(0).getItem();
if(toolPart.getID() == "pickaxe"){
if (item.getSlotList().get(0).getSubCompound("tags") != null) {
if (inventory.getStackInSlot(0).getSubCompound("tags") != null) {
if (slotStack.getSubCompound("tags").getBoolean("hot")) {
return 0.03f;
}
if (!item.getSlotList().get(0).getSubCompound("tags").getBoolean("hot")) {
if (!inventory.getStackInSlot(0).getSubCompound("tags").getBoolean("hot")) {
if(toolPart.getMaterial() == PrimalAPI.ToolMaterials.TOOL_WROUGHT_IRON){
return 0.04f;
}
@@ -138,11 +140,11 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
}
}
if(toolPart.getID() == "axe"){
if (item.getSlotList().get(0).getSubCompound("tags") != null) {
if (inventory.getStackInSlot(0).getSubCompound("tags") != null) {
if (slotStack.getSubCompound("tags").getBoolean("hot")) {
return 0.09f;
}
if (!item.getSlotList().get(0).getSubCompound("tags").getBoolean("hot")) {
if (!inventory.getStackInSlot(0).getSubCompound("tags").getBoolean("hot")) {
if(toolPart.getMaterial() == PrimalAPI.ToolMaterials.TOOL_WROUGHT_IRON){
return 0.10f;
}
@@ -162,11 +164,11 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
}
}
if(toolPart.getID() == "shovel"){
if (item.getSlotList().get(0).getSubCompound("tags") != null) {
if (inventory.getStackInSlot(0).getSubCompound("tags") != null) {
if (slotStack.getSubCompound("tags").getBoolean("hot")) {
return 0.15f;
}
if (!item.getSlotList().get(0).getSubCompound("tags").getBoolean("hot")) {
if (!inventory.getStackInSlot(0).getSubCompound("tags").getBoolean("hot")) {
if(toolPart.getMaterial() == PrimalAPI.ToolMaterials.TOOL_WROUGHT_IRON){
return 0.16f;
}
@@ -186,11 +188,11 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
}
}
if(toolPart.getID() == "hoe"){
if (item.getSlotList().get(0).getSubCompound("tags") != null) {
if (inventory.getStackInSlot(0).getSubCompound("tags") != null) {
if (slotStack.getSubCompound("tags").getBoolean("hot")) {
return 0.21f;
}
if (!item.getSlotList().get(0).getSubCompound("tags").getBoolean("hot")) {
if (!inventory.getStackInSlot(0).getSubCompound("tags").getBoolean("hot")) {
if(toolPart.getMaterial() == PrimalAPI.ToolMaterials.TOOL_WROUGHT_IRON){
return 0.22f;
}
@@ -315,27 +317,16 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
};
}
public NonNullList<ItemStack> getSlotList() {
return slotList;
}
public void setSlotList(ItemStack stack) {
slotList.set(0, stack);
}
public NonNullList<ItemStack> slotList = NonNullList.withSize(1, ItemStack.EMPTY);
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing face, float hitx, float hity, float hitz)
{
//if(!world.isRemote){
if (hand.equals(player.getActiveHand())) {
IBlockState state = world.getBlockState(pos);
Block block = world.getBlockState(pos).getBlock();
ItemStack itemstack = player.getHeldItem(hand);
ItemStack slotStack = slotList.get(0);
if(!world.isRemote) {
if (hand.equals(player.getActiveHand())) {
IBlockState state = world.getBlockState(pos);
Block block = world.getBlockState(pos).getBlock();
ItemStack itemstack = player.getHeldItem(hand);
IItemHandler inventory = itemstack.getCapability(ITEM_HANDLER, null);
ItemStack slotStack = inventory.getStackInSlot(0).copy();
/*
if (block instanceof AnvilStone) {
TileAnvil tile = (TileAnvil) world.getTileEntity(pos);
@@ -343,105 +334,107 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
return EnumActionResult.SUCCESS;
}
*/
if (slotList.get(0).isEmpty()) {
if (block instanceof NBTCrucible) {
ItemStack tempStack = takeBlock(world, pos, state, face, player, block).copy();
slotList.set(0, tempStack);
world.setBlockState(pos, this.getReplacementBlock(world, pos, state));
return EnumActionResult.SUCCESS;
}
}
if (!slotList.get(0).isEmpty()) {
if (slotList.get(0).getItem() instanceof ItemNBTCrucible) {
NBTTagCompound tag = this.slotList.get(0).getSubCompound("BlockEntityTag").copy();
NBTTagCompound defaultNBT = this.slotList.get(0).getTagCompound();
if (tag != null) {
ItemBlock temp = (ItemBlock) slotList.get(0).getItem();
int i = this.getMetadata(slotList.get(0).getMetadata());
IBlockState iblockstate1 = temp.getBlock().getStateForPlacement(world, pos, face, hitx, hity, hitz, i, player, hand);
temp.placeBlockAt(slotList.get(0), player, world, pos.up(1), face, hitx, hity, hitz, iblockstate1);
slotList.set(0, ItemStack.EMPTY);
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));
return EnumActionResult.SUCCESS;
}
}
}
if (!slotStack.isEmpty()) {
if (slotStack.getItem() instanceof ItemNBTCrucible) {
NBTTagCompound tag = slotStack.getSubCompound("BlockEntityTag").copy();
/*****
DROPS the ToolParts into the World
*****/
if (!slotList.get(0).isEmpty()) {
if (!(block instanceof AnvilBase)) {
if (slotList.get(0).getItem() instanceof ToolPart) {
ItemStack tempStack = slotList.get(0).copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
slotList.set(0, ItemStack.EMPTY);
return EnumActionResult.SUCCESS;
}
}
}
/*****
Cools the Ingots on the Tongs
*****/
if (!slotList.get(0).isEmpty()) {
if (world.getBlockState(pos).getBlock() == PrimalAPI.Blocks.BARREL) {
AbstractTileTank tileTank = (AbstractTileTank) world.getTileEntity(pos);
if (slotStack.getTagCompound().getBoolean("hot")) {
if (tileTank.getContainedFluid().getFluid().equals(FluidRegistry.WATER) ||
tileTank.getContainedFluid().getFluid().equals(PrimalAPI.Fluids.RAIN_WATER)
) {
ItemStack tempStack = slotList.get(0).copy();
tempStack.getTagCompound().setBoolean("hot", false);
slotList.set(0, ItemStack.EMPTY);
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.AMBIENT, 1.0F, PrimalAPI.getRandom().nextFloat() * 0.4F + 0.8F);
slotList.set(0, ItemStack.EMPTY);
if (tag != null) {
ItemBlock temp = (ItemBlock) slotStack.getItem();
int i = this.getMetadata(slotStack.getMetadata());
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);
return EnumActionResult.SUCCESS;
}
}
}
}
/*****
DROPS the Ingots into the World
*****/
if (!slotList.get(0).isEmpty()) {
if (!(block instanceof AnvilBase)) {
if (!(block instanceof Forge)) {
if (slotList.get(0).getItem() instanceof BaseMultiItem) {
ItemStack tempStack = slotList.get(0).copy();
/*****
DROPS the ToolParts into the World
*****/
if (!slotStack.isEmpty()) {
if (!(block instanceof AnvilBase)) {
if (slotStack.getItem() instanceof ToolPart) {
ItemStack tempStack = slotStack;
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
slotList.set(0, ItemStack.EMPTY);
inventory.extractItem(0, 1, false);
return EnumActionResult.SUCCESS;
}
if (!(slotList.get(0).getItem() instanceof BaseMultiItem)) {
if (RecipeHelper.isOreName(slotList.get(0).getItem(), "ingotIron")) {
ItemStack tempStack = slotList.get(0).copy();
}
}
/*****
Cools the Ingots on the Tongs
*****/
if (!slotStack.isEmpty()) {
if (world.getBlockState(pos).getBlock() == PrimalAPI.Blocks.BARREL) {
AbstractTileTank tileTank = (AbstractTileTank) world.getTileEntity(pos);
if (slotStack.getTagCompound().getBoolean("hot")) {
if (tileTank.getContainedFluid().getFluid().equals(FluidRegistry.WATER) ||
tileTank.getContainedFluid().getFluid().equals(PrimalAPI.Fluids.RAIN_WATER)
) {
ItemStack tempStack = slotStack.copy();
tempStack.getTagCompound().setBoolean("hot", false);
inventory.extractItem(0, 1, false);
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
slotList.set(0, ItemStack.EMPTY);
return EnumActionResult.SUCCESS;
}
if (RecipeHelper.isOreName(slotList.get(0).getItem(), "nuggetIron")) {
ItemStack tempStack = slotList.get(0).copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
slotList.set(0, ItemStack.EMPTY);
return EnumActionResult.SUCCESS;
}
if (RecipeHelper.isOreName(slotList.get(0).getItem(), "ingotSteel")) {
ItemStack tempStack = slotList.get(0).copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
slotList.set(0, ItemStack.EMPTY);
return EnumActionResult.SUCCESS;
}
if (RecipeHelper.isOreName(slotList.get(0).getItem(), "nuggetSteel")) {
ItemStack tempStack = slotList.get(0).copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
slotList.set(0, ItemStack.EMPTY);
world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.AMBIENT, 1.0F, PrimalAPI.getRandom().nextFloat() * 0.4F + 0.8F);
return EnumActionResult.SUCCESS;
}
}
}
}
/*****
DROPS the Ingots into the World
*****/
if (!slotStack.isEmpty()) {
if (!(block instanceof AnvilBase)) {
if (!(block instanceof Forge)) {
if (slotStack.getItem() instanceof BaseMultiItem) {
ItemStack tempStack = slotStack.copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
inventory.extractItem(0, 1, false);
return EnumActionResult.SUCCESS;
}
if (!(slotStack.getItem() instanceof BaseMultiItem)) {
if (RecipeHelper.isOreName(slotStack.getItem(), "ingotIron")) {
ItemStack tempStack = slotStack.copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
inventory.extractItem(0, 1, false);
return EnumActionResult.SUCCESS;
}
if (RecipeHelper.isOreName(slotStack.getItem(), "nuggetIron")) {
ItemStack tempStack = slotStack.copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
inventory.extractItem(0, 1, false);
return EnumActionResult.SUCCESS;
}
if (RecipeHelper.isOreName(slotStack.getItem(), "ingotSteel")) {
ItemStack tempStack = slotStack.copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
inventory.extractItem(0, 1, false);
return EnumActionResult.SUCCESS;
}
if (RecipeHelper.isOreName(slotStack.getItem(), "nuggetSteel")) {
ItemStack tempStack = slotStack.copy();
PlayerHelper.spawnItemOnGround(world, pos, tempStack);
inventory.extractItem(0, 1, false);
//inventory.insertItem(0, ItemStack.EMPTY, false);
return EnumActionResult.SUCCESS;
}
}
}
}
}
return EnumActionResult.FAIL;
}
return EnumActionResult.FAIL;
}
@@ -478,9 +471,8 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
{
if(!stack.isEmpty())
{
SlottedTongs item = (SlottedTongs) stack.getItem();
ItemStack slotStack = item.getSlotList().get(0).copy();
System.out.println(slotStack);
IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null);
ItemStack slotStack = inventory.getStackInSlot(0).copy();
if (!slotStack.isEmpty())
{
tooltip.add(ChatFormatting.GRAY + "Holding: " + slotStack.getItem().getUnlocalizedName());
@@ -504,17 +496,28 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{
}
}
@Nullable
@Override
public NBTTagCompound getNBTShareTag(ItemStack stack)
{
super.getNBTShareTag(stack);
IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null);
NonNullList<ItemStack> setList = NonNullList.<ItemStack>withSize(1, ItemStack.EMPTY);
ItemStackHelper.saveAllItems(stack.getTagCompound(), setList);
return stack.getTagCompound();
}
@Override
public void readNBTShareTag(ItemStack stack, @Nullable NBTTagCompound nbt)
{
stack.setTagCompound(nbt);
super.readNBTShareTag(stack, nbt);
stack.deserializeNBT(nbt);
IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null);
NonNullList<ItemStack> setList = NonNullList.<ItemStack>withSize(1, ItemStack.EMPTY);
ItemStackHelper.loadAllItems(nbt, setList);
inventory.insertItem(0, setList.get(0), false);
}
}

View File

@@ -11,6 +11,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import nmd.primal.core.api.PrimalAPI;
import nmd.primal.core.common.items.tools.Gallagher;
import nmd.primal.forgecraft.CommonUtils;
@@ -25,6 +26,7 @@ import nmd.primal.forgecraft.tiles.TileAnvil;
import java.util.concurrent.ThreadLocalRandom;
import static nmd.primal.forgecraft.blocks.CustomContainerFacing.FACING;
import static nmd.primal.forgecraft.items.SlottedTongs.ITEM_HANDLER;
/**
* Created by mminaie on 6/10/17.
@@ -236,13 +238,13 @@ public interface AnvilHandler {
if (pItem.getItem().equals(ModItems.slottedtongs)) {
SlottedTongs tongs = (SlottedTongs) pItem.getItem();
ItemStack tongStack = tongs.getSlotList().get(0).copy();
IItemHandler inventory = pItem.getCapability(ITEM_HANDLER, null);
ItemStack tongStack = inventory.getStackInSlot(0).copy();
if (tongStack.isEmpty()) {
if (!tile.getSlotStack(counter).isEmpty()) {
ItemStack tempStack = tile.getSlotStack(counter).copy();
tongs.setSlotList(tempStack);
inventory.insertItem(0,tempStack, false);
tile.setSlotStack(counter, ItemStack.EMPTY);
return true;
}
@@ -250,9 +252,9 @@ public interface AnvilHandler {
if (!tongStack.isEmpty()) {
if (tile.getSlotStack(counter).isEmpty()) {
ItemStack tempStack = tongs.getSlotList().get(0).copy();
ItemStack tempStack = tongStack.copy();
tile.setSlotStack(counter, tempStack);
tongs.setSlotList(ItemStack.EMPTY);
inventory.extractItem(0, 1, false);
return true;
}
}

View File

@@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import nmd.primal.core.common.helper.RecipeHelper;
import nmd.primal.core.common.items.tools.Gallagher;
import nmd.primal.forgecraft.init.ModItems;
@@ -18,6 +19,7 @@ import nmd.primal.forgecraft.tiles.TileAnvil;
import nmd.primal.forgecraft.tiles.TileForge;
import static nmd.primal.forgecraft.blocks.CustomContainerFacing.FACING;
import static nmd.primal.forgecraft.items.SlottedTongs.ITEM_HANDLER;
/**
* Created by mminaie on 9/22/18.
@@ -109,13 +111,13 @@ public interface ForgeHandler {
static boolean doWork(ItemStack pItem, Integer counter, TileForge tile, World world, BlockPos pos, EntityPlayer player) {
if (pItem.getItem().equals(ModItems.slottedtongs)) {
IItemHandler inventory = pItem.getCapability(ITEM_HANDLER, null);
ItemStack tongsStack = inventory.getStackInSlot(0).copy();
SlottedTongs tongs = (SlottedTongs) pItem.getItem();
ItemStack tongsStack = tongs.getSlotList().get(0).copy();
if (tongsStack.isEmpty()) {
if (!tile.getSlotStack(counter).isEmpty()) {
ItemStack tempStack = tile.getSlotStack(counter).copy();
tongs.setSlotList(tempStack);
inventory.insertItem(0, tempStack, false);
tile.setSlotStack(counter, ItemStack.EMPTY);
return true;
}
@@ -123,9 +125,9 @@ public interface ForgeHandler {
if (!tongsStack.isEmpty()) {
if (tile.getSlotStack(counter).isEmpty()) {
ItemStack tempStack = tongs.getSlotList().get(0).copy();
ItemStack tempStack = tongsStack;
tile.setSlotStack(counter, tempStack);
tongs.setSlotList(ItemStack.EMPTY);
inventory.extractItem(0, 1, false);
return true;
}
}