use of mods.railcraft.common.util.inventory.InventoryComposite in project Railcraft by Railcraft.
the class PrototypeRecipe method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting grid) {
if (!matches(grid, null))
return InvTools.emptyStack();
InventoryComposite inv = InventoryComposite.of(grid);
ItemStack container = inv.findOne(PROTOTYPE_CONTAINER);
if (InvTools.isEmpty(container))
return InvTools.emptyStack();
ItemStack prototype = inv.findOne(validPrototype(container));
if (!InvTools.isEmpty(prototype))
return ((IPrototypedItem) container.getItem()).setPrototype(container, prototype);
return InvTools.emptyStack();
}
use of mods.railcraft.common.util.inventory.InventoryComposite in project Railcraft by Railcraft.
the class PrototypeRecipe method matches.
@Override
public boolean matches(InventoryCrafting grid, @Nullable World world) {
InventoryComposite inv = InventoryComposite.of(grid);
int containerStacks = inv.countStacks(PROTOTYPE_CONTAINER);
if (containerStacks != 1)
return false;
ItemStack container = inv.findOne(PROTOTYPE_CONTAINER);
return !InvTools.isEmpty(container) && inv.countStacks(validPrototype(container)) == 1;
}
use of mods.railcraft.common.util.inventory.InventoryComposite in project Railcraft by Railcraft.
the class IcemanBackpack method manageSnow.
private void manageSnow(IInventory backpackInventory) {
InventoryComposite inv = InventoryComposite.of(backpackInventory);
if (inv.hasItems()) {
int numSnowballs = inv.countItems(SNOWBALL_MATCHER);
while (numSnowballs > 16 && inv.canFit(SNOW_BLOCK) && inv.removeItems(4, SNOWBALL_MATCHER)) {
inv.addStack(new ItemStack(Blocks.SNOW));
numSnowballs -= 4;
}
while (numSnowballs < 8 && inv.canFit(new ItemStack(Items.SNOWBALL, 4)) && inv.removeItems(1, SNOW_BLOCK_MATCHER)) {
inv.addStack(new ItemStack(Items.SNOWBALL, 4));
numSnowballs += 4;
}
}
}
use of mods.railcraft.common.util.inventory.InventoryComposite in project Railcraft by Railcraft.
the class InventoryTest method buildAdapters.
@Test
void buildAdapters() {
InventoryComposite invBasic = InventoryComposite.of(new InventoryBasic("Test", true, 4));
testComposite("InventoryBasic", invBasic);
InventoryComposite invAdvanced = InventoryComposite.of(new InventoryAdvanced(4));
testComposite("InventoryAdvanced", invAdvanced);
InventoryComposite invCap = InventoryComposite.of(new ICapabilityProvider() {
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return true;
}
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
// noinspection unchecked
return (T) new InvWrapper(new InventoryAdvanced(4));
}
});
testComposite("IItemHandler", invCap);
}
use of mods.railcraft.common.util.inventory.InventoryComposite in project Railcraft by Railcraft.
the class TileFeedStation method update.
@Override
public void update() {
super.update();
if (Game.isClient(getWorld())) {
return;
}
ItemStack feed = getStackInSlot(0);
if (clock % (MIN_FEED_INTERVAL / 4) == 0 && (feed.isEmpty() || sizeOf(feed) < feed.getMaxStackSize())) {
InventoryComposite chests = invCache.getAdjacentInventories();
chests.moveOneItemTo(this, StackFilters.FEED);
}
feed = getStackInSlot(0);
feedTime--;
if (!powered && !InvTools.isEmpty(feed) && feedTime <= 0) {
feedTime = MIN_FEED_INTERVAL + rand.nextInt(FEED_VARIANCE);
// TODO: test (maybe we can draw this somehow?)
AxisAlignedBB box = AABBFactory.start().createBoxForTileAt(getPos()).raiseFloor(-1).raiseCeiling(2).expandHorizontally(AREA).build();
List<EntityAnimal> animals = world.getEntitiesWithinAABB(EntityAnimal.class, box);
for (EntityAnimal target : animals) {
if (target.isBreedingItem(getStackInSlot(0)) && feedAnimal(target)) {
if (feedCounter <= 0) {
setInventorySlotContents(0, InvTools.depleteItem(feed));
feedCounter = ANIMALS_PER_FOOD;
}
feedCounter--;
sendFeedPacket(target);
break;
}
}
}
}
Aggregations