本文整理匯總了Java中net.minecraftforge.items.ItemHandlerHelper類的典型用法代碼示例。如果您正苦於以下問題:Java ItemHandlerHelper類的具體用法?Java ItemHandlerHelper怎麽用?Java ItemHandlerHelper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ItemHandlerHelper類屬於net.minecraftforge.items包,在下文中一共展示了ItemHandlerHelper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transferOneItem
import net.minecraftforge.items.ItemHandlerHelper; //導入依賴的package包/類
/**
* Returns true if succeeded
* @param input
* @param output
* @return
*/
public static boolean transferOneItem(IItemHandler input, IItemHandler output){
if(input == null || output == null) return false;
for(int i = 0; i < input.getSlots(); i++){
ItemStack extracted = input.extractItem(i, 1, true);
if(!extracted.isEmpty()){
if(ItemHandlerHelper.insertItemStacked(output, extracted, false).isEmpty()){
input.extractItem(i, 1, false);
return true;
}
}
}
return false;
}
示例2: inventoryCanCarry
import net.minecraftforge.items.ItemHandlerHelper; //導入依賴的package包/類
private boolean inventoryCanCarry() {
insertingInventoryHasSpace = true;
if (lastInsertingInventory == null)
return true;
if (inventory.getStackInSlot(CANNON_SLOT).isEmpty())
return true;
TileEntity te = getWorld().getTileEntity(lastInsertingInventory);
IItemHandler inv = IOHelper.getInventoryForTE(te, lastInsertingInventorySide);
if (inv != null) {
ItemStack remainder = ItemHandlerHelper.insertItem(inv, inventory.getStackInSlot(CANNON_SLOT).copy(), true);
insertingInventoryHasSpace = remainder.isEmpty();
return insertingInventoryHasSpace;
} else {
lastInsertingInventory = null;
lastInsertingInventorySide = null;
return true;
}
}
示例3: innerUpdate
import net.minecraftforge.items.ItemHandlerHelper; //導入依賴的package包/類
@Override
protected void innerUpdate() {
if (this.world.isRemote) return;
if (currentWork >= getMaxWork()) {
List<ItemStackWeightedItem> items = new ArrayList<>();
LaserDrillEntry.LASER_DRILL_ENTRIES.forEach(entry -> {
int increase = 0;
for (int i = 0; i < lensItems.getSlots(); ++i) {
if (!lensItems.getStackInSlot(i).isEmpty() && lensItems.getStackInSlot(i).getMetadata() == entry.getLaserMeta() && lensItems.getStackInSlot(i).getItem() instanceof LaserLensItem) {
if (((LaserLensItem) lensItems.getStackInSlot(i).getItem()).isInverted())
increase -= BlockRegistry.laserBaseBlock.getLenseChanceIncrease();
else increase += BlockRegistry.laserBaseBlock.getLenseChanceIncrease();
}
}
items.add(new ItemStackWeightedItem(entry.getStack(), entry.getWeight() + increase));
});
ItemStack stack = WeightedRandom.getRandomItem(this.world.rand, items).getStack().copy();
if (ItemHandlerHelper.insertItem(outItems, stack, true).isEmpty()) {
ItemHandlerHelper.insertItem(outItems, stack, false);
}
currentWork = 0;
}
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: extractItem
import net.minecraftforge.items.ItemHandlerHelper; //導入依賴的package包/類
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (storage.getStackInSlot(slot).isEmpty() || amount == 0) return ItemStack.EMPTY;
ItemStack existing = blackHoleUnitBlock.getItemStack(storage.getStackInSlot(slot)).copy();
if (existing.isEmpty()) return ItemStack.EMPTY;
int visualAmount = blackHoleUnitBlock.getAmount(storage.getStackInSlot(slot)) + output.getStackInSlot(slot).getCount();
if (visualAmount <= amount) {
if (!simulate) {
blackHoleUnitBlock.setAmount(storage.getStackInSlot(slot), 0);
output.setStackInSlot(slot, ItemStack.EMPTY);
}
return ItemHandlerHelper.copyStackWithSize(existing, visualAmount);
} else {
if (!simulate) {
blackHoleUnitBlock.setAmount(storage.getStackInSlot(slot), Math.max(0, blackHoleUnitBlock.getAmount(storage.getStackInSlot(slot)) - amount));
output.setStackInSlot(slot, ItemHandlerHelper.copyStackWithSize(existing, Math.min(64, visualAmount - amount)));
}
return ItemHandlerHelper.copyStackWithSize(existing, amount);
}
}
示例8: extractItem
import net.minecraftforge.items.ItemHandlerHelper; //導入依賴的package包/類
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (amount == 0) return ItemStack.EMPTY;
ItemStack existing = tile.getItemStack().copy();
if (existing.isEmpty()) return ItemStack.EMPTY;
if (tile.getAmount() <= amount) {
int newAmount = tile.getAmount();
if (!simulate) {
tile.setAmount(0);
outItems.setStackInSlot(0, ItemStack.EMPTY);
}
return ItemHandlerHelper.copyStackWithSize(existing, newAmount);
} else {
if (!simulate) {
tile.setAmount(tile.amount - amount);
}
return ItemHandlerHelper.copyStackWithSize(existing, amount);
}
}
示例9: 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;
}
示例10: 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;
}
}
示例11: performWork
import net.minecraftforge.items.ItemHandlerHelper; //導入依賴的package包/類
@Override
protected float performWork() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
if (!hasBooks() || getItem().isEmpty()) return 0;
ItemStack enchantedItem = getItem();
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
if (ItemHandlerHelper.insertItem(outEnchanted, enchantedBook, true).isEmpty() && ItemHandlerHelper.insertItem(outItem, enchantedItem, true).isEmpty()) {
NBTTagCompound base = (NBTTagCompound) enchantedItem.getEnchantmentTagList().get(0);
((ItemEnchantedBook) Items.ENCHANTED_BOOK).addEnchantment(enchantedBook, new EnchantmentData(Enchantment.getEnchantmentByID(base.getShort("id")), base.getShort("lvl")));
enchantedItem.getEnchantmentTagList().removeTag(0);
ItemHandlerHelper.insertItem(outEnchanted, enchantedBook, false);
ItemHandlerHelper.insertItem(outItem, enchantedItem.copy(), false);
inBook.getStackInSlot(0).setCount(inBook.getStackInSlot(0).getCount() - 1);
enchantedItem.setCount(enchantedItem.getCount() - 1);
return 500;
}
return 0;
}
示例12: 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;
}
示例13: 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();
}
}
示例14: onItemUse
import net.minecraftforge.items.ItemHandlerHelper; //導入依賴的package包/類
@Override
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (!(stack.getItem() instanceof MooncakeMold))
return EnumActionResult.PASS;
if (!stack.hasTagCompound())
return EnumActionResult.PASS;
if (world.getBlockState(pos).getBlock() == Blocks.IRON_BLOCK) {
if (!stack.getTagCompound().hasKey("hitCount"))
stack.getTagCompound().setInteger("hitCount", 0);
stack.getTagCompound().setInteger("hitCount", stack.getTagCompound().getInteger("hitCount") + 1);
if (stack.getTagCompound().getInteger("hitCount") >= 5) {
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(MooncakeConstants.RAW_MOONCAKE_ITEM, 1, stack.getTagCompound().getInteger("meta")));
stack.setTagCompound(null);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
示例15: insertItem
import net.minecraftforge.items.ItemHandlerHelper; //導入依賴的package包/類
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if(stack.isEmpty()) return ItemStack.EMPTY;
if(!getKey().isPresent() || isEntangled(stack)) return stack;
ItemStack existing = getStackInSlot(slot);
int limit = stack.getMaxStackSize();
if(!existing.isEmpty()) {
if(!ItemHandlerHelper.canItemStacksStack(stack, existing)) {
return stack;
}
limit -= existing.getCount();
}
if(limit <= 0) return stack;
boolean reachedLimit = stack.getCount() > limit;
if(!simulate) {
if(existing.isEmpty()) {
setStackInSlot(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
setStackInSlot(slot, existing);
}
onChange(slot);
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
}