本文整理匯總了Java中net.minecraft.tileentity.TileEntityHopper.putStackInInventoryAllSlots方法的典型用法代碼示例。如果您正苦於以下問題:Java TileEntityHopper.putStackInInventoryAllSlots方法的具體用法?Java TileEntityHopper.putStackInInventoryAllSlots怎麽用?Java TileEntityHopper.putStackInInventoryAllSlots使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.tileentity.TileEntityHopper
的用法示例。
在下文中一共展示了TileEntityHopper.putStackInInventoryAllSlots方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleItems
import net.minecraft.tileentity.TileEntityHopper; //導入方法依賴的package包/類
private void handleItems(IEnergyStorage energy, boolean pickup, AxisAlignedBB bounds) {
List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, bounds.expand(1, 1, 1));
for (EntityItem item : items) {
if (energy.getEnergyStored() < 1)
break;
if (item == null) {
continue;
} else {
ItemStack itemstack = item.getItem().copy();
ItemStack itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(this, this, itemstack, EnumFacing.UP);
if (itemstack1 != null && itemstack1.getCount() != 0) {
item.setItem(itemstack1);
} else {
item.setDead();
}
energy.extractEnergy(0.1D, false);
}
}
for (int slot : SLOTS) {
ItemStack stack = inv.getStackInSlot(slot);
if (!stack.isEmpty()) {
inv.setInventorySlotContents(slot, TomsModUtils.pushStackToNeighbours(stack, world, pos, EnumFacing.VALUES));
}
}
}
示例2: onBlockActivated
import net.minecraft.tileentity.TileEntityHopper; //導入方法依賴的package包/類
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem != null) {
TileEntityGenerator te = (TileEntityGenerator) worldIn.getTileEntity(pos);
if (te.isItemValidForSlot(0, heldItem) && te.fuelStack == null) {
ItemStack leftStack = TileEntityHopper.putStackInInventoryAllSlots(te, te, heldItem.splitStack(1), side);
if (leftStack != null) {
EntityItem item = new EntityItem(worldIn, pos.getX() + 0.5D, pos.getY() + 1, pos.getZ() + 0.5D, leftStack);
worldIn.spawnEntity(item);
}
return true;
}
}
return false;
}
示例3: tick
import net.minecraft.tileentity.TileEntityHopper; //導入方法依賴的package包/類
@Override
public void tick()
{
// build molecules listed in the placed book using atoms from the network
// each line of the book is a molecule
ItemStack stack = this.getStackInSlot(0);
TileLaserRelay relay = this.getAttachedRelay();
if(stack != null && stack.stackSize > 0 && relay != null){
//get item scheme
Map<Molecule, Integer> scheme = FundamentalChemistry.getItemComposition(stack.getItem());
if(scheme != null){
//build molecules request
ChemicalStorage request = new ChemicalStorage();
ChemicalStorage required = new ChemicalStorage(null, scheme); //required molecules
required.addEnergy(required.countAtoms()); //required energy
//fetch required
request.add(required); // base scheme
request.take(this.buffer); // sub already buffered
relay.fetch(this.buffer, request); // do request
if(this.buffer.contains(required)){ // process
this.buffer.take(required); // take reagents
// output
TileEntityChest chest = getAttachedChest();
if(chest != null){ // output in chest
ItemStack residual = TileEntityHopper.putStackInInventoryAllSlots(chest, new ItemStack(stack.getItem(), 1), EnumFacing.NORTH);
//output residual
if(residual != null && residual.stackSize > 0)
this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.pos.getX(), this.pos.getY(), this.pos.getZ(), residual));
}
else //output in world
this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.pos.getX(), this.pos.getY(), this.pos.getZ(), new ItemStack(stack.getItem(), 1)));
}
}
}
}
示例4: dispense
import net.minecraft.tileentity.TileEntityHopper; //導入方法依賴的package包/類
protected void dispense(World worldIn, BlockPos pos)
{
BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
if (tileentitydispenser != null)
{
int i = tileentitydispenser.getDispenseSlot();
if (i < 0)
{
worldIn.playAuxSFX(1001, pos, 0);
}
else
{
ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
if (itemstack != null)
{
EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
BlockPos blockpos = pos.offset(enumfacing);
IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
ItemStack itemstack1;
if (iinventory == null)
{
itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);
if (itemstack1 != null && itemstack1.stackSize <= 0)
{
itemstack1 = null;
}
}
else
{
itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());
if (itemstack1 == null)
{
itemstack1 = itemstack.copy();
if (--itemstack1.stackSize <= 0)
{
itemstack1 = null;
}
}
else
{
itemstack1 = itemstack.copy();
}
}
tileentitydispenser.setInventorySlotContents(i, itemstack1);
}
}
}
}
示例5: dispense
import net.minecraft.tileentity.TileEntityHopper; //導入方法依賴的package包/類
protected void dispense(World worldIn, BlockPos pos)
{
BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
if (tileentitydispenser != null)
{
int i = tileentitydispenser.getDispenseSlot();
if (i < 0)
{
worldIn.playEvent(1001, pos, 0);
}
else
{
ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
if (!itemstack.func_190926_b())
{
EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
BlockPos blockpos = pos.offset(enumfacing);
IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
ItemStack itemstack1;
if (iinventory == null)
{
itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);
}
else
{
itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(tileentitydispenser, iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());
if (itemstack1.func_190926_b())
{
itemstack1 = itemstack.copy();
itemstack1.func_190918_g(1);
}
else
{
itemstack1 = itemstack.copy();
}
}
tileentitydispenser.setInventorySlotContents(i, itemstack1);
}
}
}
}
示例6: dispense
import net.minecraft.tileentity.TileEntityHopper; //導入方法依賴的package包/類
protected void dispense(World worldIn, BlockPos pos)
{
BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
if (tileentitydispenser != null)
{
int i = tileentitydispenser.getDispenseSlot();
if (i < 0)
{
worldIn.playEvent(1001, pos, 0);
}
else
{
ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
if (itemstack != null && net.minecraftforge.items.VanillaInventoryCodeHooks.dropperInsertHook(worldIn, pos, tileentitydispenser, i, itemstack))
{
EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
BlockPos blockpos = pos.offset(enumfacing);
IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
ItemStack itemstack1;
if (iinventory == null)
{
itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);
if (itemstack1 != null && itemstack1.stackSize <= 0)
{
itemstack1 = null;
}
}
else
{
itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());
if (itemstack1 == null)
{
itemstack1 = itemstack.copy();
if (--itemstack1.stackSize <= 0)
{
itemstack1 = null;
}
}
else
{
itemstack1 = itemstack.copy();
}
}
tileentitydispenser.setInventorySlotContents(i, itemstack1);
}
}
}
}
示例7: update
import net.minecraft.tileentity.TileEntityHopper; //導入方法依賴的package包/類
@Override
public void update() {
if (core != null && !worldObj.isRemote) {
boolean updateCore = false;
BlockPos location = getPos().offset(EnumFacing.UP);
TileEntity tileentity = worldObj.getTileEntity(location);
if (tileentity instanceof IInventory) {
IInventory inventory = (IInventory)tileentity;
if (inventory != null) {
List<ItemGroup> inventoryList = core.inventory.inventory;
if (inventoryList != null && inventoryList.size() > 0) {
ItemGroup group = inventoryList.get(0);
if (group != null) {
ItemStack stack = group.itemStack;
stack.stackSize = (int) Math.min((long)stack.getMaxStackSize(), group.count);
int stackSize = stack.stackSize;
ItemStack leftOver = TileEntityHopper.putStackInInventoryAllSlots(inventory, stack, EnumFacing.DOWN);
if (leftOver != null) {
int remaining = stackSize - leftOver.stackSize;
if (remaining > 0) {
group.count -= remaining;
updateCore = true;
}
} else {
group.count -= stackSize;
updateCore = true;
}
if (group.count <= 0) {
core.inventory.inventory.remove(0);
}
}
}
}
}
if (updateCore) {
this.worldObj.markBlockForUpdate(core.getPos());
core.markDirty();
}
}
}
示例8: update
import net.minecraft.tileentity.TileEntityHopper; //導入方法依賴的package包/類
@Override
public void update() {
super.update();
if(core != null && !worldObj.isRemote && !worldObj.isBlockPowered(pos)) {
boolean updateCore = false;
BlockPos targetPos = getPos().offset(EnumFacing.UP);
TileEntity targetTile = worldObj.getTileEntity(targetPos);
// make sure there's a inventory tile entity above it
if (targetTile != null && targetTile instanceof IInventory) {
IInventory targetInv = (IInventory) targetTile;
Block targetBlock = worldObj.getBlockState(targetPos).getBlock();
// double chest support
if (targetInv != null && targetInv instanceof TileEntityChest && targetBlock instanceof BlockChest) {
targetInv = ((BlockChest) targetBlock).getContainer(worldObj, targetPos, true);
}
// make sure the inventory exists
if (targetInv != null) {
// now spit the items into the above inventory
List<ItemGroup> inventoryList = core.inventory.inventory;
if (inventoryList != null && inventoryList.size() > 0) {
ItemGroup group = inventoryList.get(0);
if (group != null) {
ItemStack stack = group.itemStack.copy(); // wasn't a copy before....
// WEIRD STUFF HAPPENED.
stack.stackSize = (int) Math.min(stack.getMaxStackSize(), group.count);
int stackSize = stack.stackSize;
ItemStack leftOver = TileEntityHopper.putStackInInventoryAllSlots(targetInv, stack, EnumFacing.DOWN);
if (leftOver != null) {
int remaining = stackSize - leftOver.stackSize;
if (remaining > 0) {
group.count -= remaining;
updateCore = true;
}
} else {
group.count -= stackSize;
updateCore = true;
}
if (group.count <= 0) {
core.inventory.inventory.remove(0);
}
}
}
}
}
// make sure to sort the inventory on change
if (updateCore) {
core.sortInventory();
}
}
}