本文整理匯總了Java中net.minecraftforge.items.CapabilityItemHandler類的典型用法代碼示例。如果您正苦於以下問題:Java CapabilityItemHandler類的具體用法?Java CapabilityItemHandler怎麽用?Java CapabilityItemHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CapabilityItemHandler類屬於net.minecraftforge.items包,在下文中一共展示了CapabilityItemHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extract
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
public static ItemStack extract(TileEntity tile, EnumFacing from, boolean fullStack) {
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from)) {
IItemHandlerModifiable handler = (IItemHandlerModifiable) tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from);
if (handler != null) {
int invSize = handler.getSlots();
for (int i = 0; i < invSize; i++) {
ItemStack current = handler.getStackInSlot(i);
if (current != null && !current.isEmpty() && current.getItem() != Items.AIR) {
ItemStack stack = handler.extractItem(i, !fullStack ? 1 : current.getCount(), false);
return stack;
}
}
}
} // TODO: TileEntities that don't have capabilities - needs testing
return null;
}
示例2: getSearchedItemCount
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
private int getSearchedItemCount() {
TileEntity te = world.getTileEntity(pos);
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
// if (world.getTileEntity(pos) instanceof IInventory) {
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
int itemCount = 0;
// IInventory inventory = (IInventory) world.getTileEntity(pos);
ItemStack searchStack = ItemPneumaticArmor.getSearchedStack(FMLClientHandler.instance().getClient().player.getItemStackFromSlot(EntityEquipmentSlot.HEAD));
if (searchStack.isEmpty()) return 0;
for (int l = 0; l < handler.getSlots(); l++) {
if (!handler.getStackInSlot(l).isEmpty()) {
itemCount += getSearchedItemCount(handler.getStackInSlot(l), searchStack);
}
}
return itemCount;
}
return 0;
}
示例3: breakBlock
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tile = worldIn.getTileEntity(pos);
if (tile != null)
{
IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (itemHandler != null)
{
for (int i = 0; i < itemHandler.getSlots(); i++)
{
ItemStack stack = itemHandler.getStackInSlot(i);
if (!stack.isEmpty())
{
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
}
}
}
}
super.breakBlock(worldIn, pos, state);
}
示例4: getCapability
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Nullable
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
{
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
return (T) getItemHandlerCapability(facing);
}
for (TileEntityModule module : modules.values())
{
if (module.hasCapability(capability, facing))
return module.getCapability(capability, facing);
}
return super.getCapability(capability, facing);
}
示例5: getCapability
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Nullable
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
if (facing == null) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerMainInvHandler);
switch (facing) {
case UP:
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerArmorInvHandler);
case DOWN:
return super.getCapability(capability, facing);
default:
return dispenserUpgradeInserted ?
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerFoodHandler) :
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerMainInvHandler);
}
} else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && dispenserUpgradeInserted) {
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(playerExperienceHandler);
} else if (capability == CapabilityEnergy.ENERGY) {
return CapabilityEnergy.ENERGY.cast(energyRF);
}
return super.getCapability(capability, facing);
}
示例6: update
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Override
public void update() {
IItemHandler cap = this.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (cap == null) return;
if (!world.isRemote) {
timeSinceLastGrowth++;
if (timeSinceLastGrowth >= TIME_BETWEEN_GROWTH) {
ItemStack stack = cap.getStackInSlot(0);
if (stack.getItem() == GeneraItems.ItemGlassJar &&
stack.getMetadata() == 1 &&
stack.getCount() == 1) {
NBTTagCompound nbt = stack.getTagCompound();
if (nbt != null) {
nbt.setFloat("size", nbt.getFloat("size") + 0.02F);
nbt.setDouble("max_health", nbt.getDouble("max_health") + 0.5D);
nbt.setInteger("current_exp", nbt.getInteger("current_exp") + 25);
}
}
Genera.SIMPLEIMPL_INSTANCE.sendToAll(new MessageGlassJarUpdateStats(stack, getPos()));
timeSinceLastGrowth = 0;
}
}
}
示例7: onMessage
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Override
public IMessage onMessage(MessageGlassJarUpdateStats message, MessageContext ctx) {
ItemStack stack = message.stack;
BlockPos pos = message.pos;
WorldClient world = Minecraft.getMinecraft().world;
if (world.isBlockLoaded(pos) &&
world.getBlockState(pos).getBlock().hasTileEntity(world.getBlockState(pos))) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileFaerieHome) {
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (handler != null) {
handler.insertItem(0, stack, false);
}
}
}
return null;
}
示例8: getItemHandlerCapability
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Nullable
private IItemHandlerModifiable getItemHandlerCapability(@Nullable EnumFacing facing)
{
Capability<IItemHandler> capability = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
List<IItemHandlerModifiable> handlers = Lists.newLinkedList();
for (TileEntityModule module : modules.values())
{
if (module.hasCapability(capability, facing))
handlers.add((IItemHandlerModifiable) module.getCapability(capability, facing));
}
if (handlers.size() == 1)
return handlers.get(0);
else if (handlers.size() > 1)
return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[handlers.size()]));
else
return null;
}
示例9: readFromNBT
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
if (tag.hasKey("inputtank")) {
CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(inputTank, null, tag.getTag("inputtank"));
}
if (tag.hasKey("outputtank")) {
CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(outputTank, null, tag.getTag("outputtank"));
}
if (tag.hasKey("heatstorage")) {
Thermionics.CAPABILITY_HEATSTORAGE.readNBT(heat, null, tag.getTag("heatstorage"));
}
if (tag.hasKey("inventory")) {
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(itemStorage, null, tag.getTag("inventory"));
}
if (tag.hasKey("locked")) {
tanksLocked = tag.getByte("locked")!=0;
}
}
示例10: getCapability
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){
IItemHandler inventory = getInventory(facing);
if(inventory != null){
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inventory);
}
}
if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){
IFluidHandler tank = getTank(facing);
if(tank != null){
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank);
}
}
if(capability == CapabilityEnergy.ENERGY){
IEnergyStorage energy = getEnergy(facing);
if(energy != null){
return CapabilityEnergy.ENERGY.cast(energy);
}
}
return null;
}
示例11: deserializeNBT
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Override
public void deserializeNBT(NBTBase nbtIn) {
if (nbtIn instanceof NBTTagCompound) {
NBTTagCompound nbt = (NBTTagCompound) nbtIn;
setSize(nbt.hasKey("Size", Constants.NBT.TAG_INT) ? nbt.getInteger("Size") : stacks.size());
NBTTagList tagList = nbt.getTagList(getName(), Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
int slot = itemTags.getInteger("Slot");
if (slot >= 0 && slot < stacks.size()) {
stacks.set(slot, new ItemStack(itemTags));
stacks.get(slot).setCount(itemTags.getInteger("RealCount"));
}
}
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(this, null, tagList);
onLoad();
}
}
示例12: ContainerKiln
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
public ContainerKiln(EntityPlayer player, TileEntityKiln tileEntityKiln)
{
super(tileEntityKiln);
PlayerInvWrapper playerInv = (PlayerInvWrapper) player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
addSlotToContainer(new SlotItemHandler(itemHandler, TileEntityKiln.SLOT_INPUT, 56, 17));
addSlotToContainer(new SlotConfigurableAccess(itemHandler, TileEntityKiln.SLOT_FUEL, 56, 53));
addSlotToContainer(new SlotOutput(itemHandler, TileEntityKiln.SLOT_OUTPUT, 116, 35));
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
addSlotToContainer(new SlotItemHandler(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
addSlotToContainer(new SlotItemHandler(playerInv, i, 8 + i * 18, 142));
}
}
示例13: TileEntityOven
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
public TileEntityOven() {
heatStorage = new HeatStorage(600);
itemStorage = new ConcreteItemStorage(3)
.withName("tile.thermionics.machine.oven.name")
.withValidators(Validators.SMELTABLE, Validators.NOTHING, Validators.NOTHING)
.setCanExtract(0, false)
.setCanExtract(1, true)
.setCanExtract(2, false);
itemStorage.listen(this::markDirty);
heatStorage.listen(this::markDirty);
capabilities.registerForAllSides(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
()->new ValidatedItemHandlerView(itemStorage), ()->itemStorage);
capabilities.registerForAllSides(Thermionics.CAPABILITY_HEATSTORAGE,
()->HeatStorageView.insertOnlyOf(heatStorage), ()->heatStorage);
}
示例14: breakBlock
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
TileEntityArcaneTransfigurationTable te = (TileEntityArcaneTransfigurationTable) world.getTileEntity(pos);
IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for (int i = 0; i < cap.getSlots(); ++i)
{
ItemStack itemstack = cap.getStackInSlot(i);
if (!itemstack.isEmpty())
{
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
}
}
super.breakBlock(world, pos, state);
}
示例15: addSlotAmmo
import net.minecraftforge.items.CapabilityItemHandler; //導入依賴的package包/類
public void addSlotAmmo(){
IItemHandler handler=nullInv;
ammoBelt=false;
if(!this.wearables.getStackInSlot(3).isEmpty()&&this.wearables.getStackInSlot(3).hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
handler=this.wearables.getStackInSlot(3).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
ammoBelt=true;
}
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j){
Slot slot=new SlotItemHandler( handler,
j + i * 3, 98 + j * 18, 18 + i * 18) {
@Override
public boolean isItemValid(@Nullable ItemStack stack) {
return this.getItemHandler()!=nullInv&&!stack.isEmpty() && stack.getItem() instanceof ItemAmmo && super.isItemValid(stack);
}
};
this.inventorySlots.set(this.inventorySlots.size()-9+j + i * 3, slot);
slot.slotNumber=this.inventorySlots.size()-9+j + i * 3;
}
}