本文整理匯總了Java中net.minecraftforge.items.ItemHandlerHelper.insertItem方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemHandlerHelper.insertItem方法的具體用法?Java ItemHandlerHelper.insertItem怎麽用?Java ItemHandlerHelper.insertItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraftforge.items.ItemHandlerHelper
的用法示例。
在下文中一共展示了ItemHandlerHelper.insertItem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: putInventoryInChestWithMessage
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
private void putInventoryInChestWithMessage(BlockPos pos, String message, String... parameters) {
if (!InventoryTools.isInventory(entity.getEntityWorld(), pos)) {
// No longer an inventory here. Just drop the items on the ground here
if (message != null) {
showMessage("message.meecreeps.inventory_missing");
}
entity.dropInventory();
} else {
if (message != null) {
showMessage(message, parameters);
}
TileEntity te = entity.getEntityWorld().getTileEntity(pos);
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
for (ItemStack stack : entity.getInventory()) {
if (!stack.isEmpty()) {
ItemStack remaining = ItemHandlerHelper.insertItem(handler, stack, false);
if (!remaining.isEmpty()) {
entity.entityDropItem(remaining, 0.0f);
}
}
}
entity.getInventory().clear();
}
}
示例2: work
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public void work()
{
for(EnumFacing facing : checkFaces)
{
TileEntity tile = world.getTileEntity(pos.offset(facing));
if(tile != null)
{
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()))
{
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
ItemStack outStack = ItemStack.EMPTY;
for(int i = 0; i < handler.getSlots(); i++)
{
outStack = handler.extractItem(i, handler.getStackInSlot(i).getCount(), false);
if(!outStack.isEmpty())
{
break;
}
}
ItemStack remain = addItem(outStack);
ItemHandlerHelper.insertItem(handler, remain ,false);
}
}
}
}
示例3: performWork
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
protected float performWork() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
ItemStack stack = getFirstItem();
if (stack.isEmpty()) {
return 0;
}
ItemStack out = stack.copy();
out.setCount(1);
if (stack.isItemEnchanted() || stack.getItem().equals(Items.ENCHANTED_BOOK)) {
if (ItemHandlerHelper.insertItem(outputEnch, out, true).isEmpty()) {
ItemHandlerHelper.insertItem(outputEnch, out, false);
stack.setCount(stack.getCount() - 1);
return 500;
}
} else if (ItemHandlerHelper.insertItem(outputNoEnch, out, true).isEmpty()) {
ItemHandlerHelper.insertItem(outputNoEnch, out, false);
stack.setCount(stack.getCount() - 1);
return 500;
}
return 0;
}
示例4: innerUpdate
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
protected void innerUpdate() {
if (this.world.isRemote) return;
++tick;
if (crafting.getLocked() && tick >= 40 && hasOnlyOneFluid()) {
Fluid fluid = getRecipeFluid();
if (fluid == null) return;
int bucketAmount = getFluidAmount(fluid);
FluidStack stack = tank.drain(bucketAmount * 1000, false);
if (stack != null && stack.getFluid().equals(fluid) && stack.amount == bucketAmount * 1000) {
IRecipe recipe = CraftingUtils.findRecipe(world, simulateRecipeEntries(fluid));
if (recipe == null || recipe.getRecipeOutput().isEmpty()) return;
if (ItemHandlerHelper.insertItem(this.output, recipe.getRecipeOutput().copy(), true).isEmpty() && areAllSolidsPresent(fluid)) {
NonNullList<ItemStack> remaining = recipe.getRemainingItems(CraftingUtils.genCraftingInventory(world, simulateRecipeEntries(fluid)));
for (int i = 0; i < crafting.getSlots(); ++i) {
if (isStackCurrentFluid(fluid, crafting.getFilterStack(i))) continue;
if (remaining.get(i).isEmpty()) crafting.getStackInSlot(i).shrink(1);
else crafting.setStackInSlot(i, remaining.get(i).copy());
}
tank.drain(bucketAmount * 1000, true);
ItemHandlerHelper.insertItem(this.output, recipe.getRecipeOutput().copy(), false);
}
}
tick = 0;
}
}
示例5: work
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public float work() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
AxisAlignedBB area = getWorkingArea();
List<EntityLiving> mobs = this.getWorld().getEntitiesWithinAABB(EntityLiving.class, area);
if (mobs.size() == 0) return 0;
FakePlayer player = IndustrialForegoing.getFakePlayer(world);
AtomicBoolean hasWorked = new AtomicBoolean(false);
mobs.stream().filter(entityLiving -> !hasAddon() || (!(entityLiving instanceof EntityAgeable) || !entityLiving.isChild())).forEach(entityLiving -> {
entityLiving.attackEntityFrom(DamageSource.causePlayerDamage(player), Integer.MAX_VALUE);
hasWorked.set(true);
});
List<EntityItem> items = this.getWorld().getEntitiesWithinAABB(EntityItem.class, area);
for (EntityItem item : items) {
if (!item.getItem().isEmpty()) {
ItemHandlerHelper.insertItem(outItems, item.getItem(), false);
item.setDead();
}
}
return hasWorked.get() ? 1 : 0;
}
示例6: performWork
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
protected float performWork() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
ItemStack stack = lens.getStackInSlot(0);
if (!stack.isEmpty()) {
ColorUsage usage = colorUsages[stack.getMetadata() - 1];
if (r >= usage.getR() && g >= usage.getG() && b >= usage.getB()) {
ItemStack out = new ItemStack(Items.DYE, 1, 15 - stack.getMetadata());
if (ItemHandlerHelper.insertItem(output, out, true).isEmpty()) {
r -= usage.getR();
g -= usage.getG();
b -= usage.getB();
ItemHandlerHelper.insertItem(output, out, false);
partialSync("red", true);
partialSync("green", true);
partialSync("blue", true);
return 1;
}
}
}
return 0;
}
示例7: performWork
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
protected float performWork() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
if (tank.getFluid() != null && tank.getFluidAmount() >= 1000) {
SludgeRefinerBlock block = (SludgeRefinerBlock) this.getBlockType();
ItemStackWeightedItem itemStack = getRandomItem();
if (ItemHandlerHelper.insertItem(outItems, itemStack.getStack(), true).isEmpty()) {
tank.drain(1000, true);
ItemHandlerHelper.insertItem(outItems, itemStack.getStack().copy(), false);
return 1;
}
}
return 0;
}
示例8: work
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public float work() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
if (this.world.rand.nextBoolean() && this.world.rand.nextBoolean()) return 1;
List<BlockPos> blockPos = BlockUtils.getBlockPosInAABB(getWorkingArea());
boolean allWaterSources = true;
for (BlockPos pos : blockPos) {
IBlockState state = this.world.getBlockState(pos);
if (!(state.getBlock().equals(FluidRegistry.WATER.getBlock()) && state.getBlock().getMetaFromState(state) == 0))
allWaterSources = false;
}
if (allWaterSources) {
LootContext.Builder lootcontext = new LootContext.Builder((WorldServer) this.world);
List<ItemStack> items = this.world.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING).generateLootForPools(this.world.rand, lootcontext.build());
for (ItemStack stack : items) {
ItemHandlerHelper.insertItem(outFish, stack, false);
}
return 1;
}
return 1;
}
示例9: packageCurrent
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
private boolean packageCurrent() {
EntityAnimal ea = this.getCurrent();
if (ea == null) {
return false;
}
ItemStack remaining = ItemHandlerHelper.insertItem(this.outStackHandler,
AnimalFarmEntity.packageAnimal(null, ea),
false);
if (ItemStackUtil.isEmpty(remaining)) {
this.currentAnimal = null;
this.forceSync();
this.markDirty();
return true;
}
return false;
}
示例10: outputItems
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
public boolean outputItems(List<ItemStack> loot) {
if ((loot != null) && (loot.size() > 0)) {
for (ItemStack lootStack : loot) {
ItemStack remaining = (this.filteredInStackHandler == null)
? ItemStackUtil.insertItemInExistingStacks(this.inStackHandler, lootStack, false)
: ItemHandlerHelper.insertItemStacked(this.filteredInStackHandler, lootStack, false);
if (!ItemStackUtil.isEmpty(remaining)) {
remaining = ItemHandlerHelper.insertItem(this.outStackHandler, lootStack, false);
}
if (!ItemStackUtil.isEmpty(remaining)) {
return this.spawnOverloadedItem(remaining);
}
}
}
return true;
}
示例11: updateTask
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public void updateTask() {
super.updateTask();
if (!luggage.world.isRemote) {
if (targetItem != null && luggage.getDistance(targetItem) < 1.0) {
final ItemStack toConsume = targetItem.getItem();
final ItemStack leftovers = ItemHandlerHelper.insertItem(luggage.getChestInventory().getHandler(), toConsume, false);
if (leftovers.getCount() < toConsume.getCount()) {
if (luggage.lastSound > 15) {
boolean isFood = toConsume.getItemUseAction() == EnumAction.EAT;
luggage.playSound(isFood? OpenBlocks.Sounds.ENTITY_LUGGAGE_EAT_FOOD : OpenBlocks.Sounds.ENTITY_LUGGAGE_EAT_ITEM,
0.5f, 1.0f + (luggage.world.rand.nextFloat() * 0.2f));
luggage.lastSound = 0;
}
ItemUtils.setEntityItemStack(targetItem, leftovers);
}
}
}
}
示例12: doWork
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
protected void doWork(IBlockState targetState, BlockPos target, EnumFacing direction) {
final List<EntityItem> drops = FakePlayerPool.instance.executeOnPlayer((WorldServer)world, new BreakBlockAction(world, target).findEffectiveTool());
if (drops.isEmpty()) return;
final EnumFacing dropSide = direction.getOpposite();
final IItemHandler targetInventory = InventoryUtils.tryGetHandler(world, pos.offset(dropSide), direction);
if (targetInventory == null) return;
for (EntityItem drop : drops) {
ItemStack stack = drop.getItem();
final ItemStack leftovers = ItemHandlerHelper.insertItem(targetInventory, stack, false);
ItemUtils.setEntityItemStack(drop, leftovers);
}
}
示例13: onEntityCollidedWithBlock
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
public boolean onEntityCollidedWithBlock(Entity entity) {
if (!world.isRemote) {
if (entity instanceof EntityItem && !entity.isDead) {
final EntityItem item = (EntityItem)entity;
final ItemStack toConsume = item.getItem().copy();
final ItemStack leftover = ItemHandlerHelper.insertItem(inventory.getHandler(), toConsume, false);
ItemUtils.setEntityItemStack(item, leftover);
return true;
} else if (entity instanceof EntityXPOrb) {
if (tank.getSpace() > 0) {
EntityXPOrb orb = (EntityXPOrb)entity;
int xpAmount = LiquidXpUtils.xpToLiquidRatio(orb.getXpValue());
FluidStack newFluid = new FluidStack(OpenBlocks.Fluids.xpJuice, xpAmount);
tank.fill(newFluid, true);
entity.setDead();
return true;
}
}
}
return false;
}
示例14: exportStackToInventory
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Nonnull
public static ItemStack exportStackToInventory(ICapabilityProvider provider, ItemStack stack, EnumFacing side) {
if (provider.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
IItemHandler handler = provider.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
return ItemHandlerHelper.insertItem(handler, stack, false);
}
return stack;
}
示例15: addItem
import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack addItem(ItemStack stack)
{
ItemStack insert = stack;
for(int i = 0; i < items.getSlots(); i++)
{
insert = ItemHandlerHelper.insertItem(items, insert, false);
}
return insert;
}