use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeForge by SpongePowered.
the class MixinInvWrapper method init.
private void init() {
if (!initalized) {
initalized = true;
this.fabric = new IItemHandlerFabric(((InvWrapper) (Object) this));
this.slots = new SlotCollection.Builder().add(this.fabric.getSize()).build();
this.lens = new OrderedInventoryLensImpl(0, this.fabric.getSize(), 1, slots);
}
}
use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeCommon by SpongePowered.
the class MixinEntityVillager method onConstructed.
@Inject(method = "<init>", at = @At("RETURN"))
public void onConstructed(CallbackInfo ci) {
this.fabric = new IInventoryFabric(this.villagerInventory);
this.slots = new SlotCollection.Builder().add(8).build();
this.lens = new OrderedInventoryLensImpl(0, 8, 1, this.slots);
}
use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeCommon by SpongePowered.
the class MixinInventoryPlayer method onConstructed.
@Inject(method = "<init>*", at = @At("RETURN"), remap = false)
private void onConstructed(EntityPlayer playerIn, CallbackInfo ci) {
// Find offhand slot
for (NonNullList<ItemStack> inventory : this.allInventories) {
if (inventory == this.offHandInventory) {
break;
}
this.offhandIndex += inventory.size();
}
// Set Carrier if we got a real Player
if (playerIn instanceof EntityPlayerMP) {
this.carrier = (Player) playerIn;
this.inventory = new IInventoryFabric((IInventory) this);
Class clazz = this.getClass();
if (clazz == InventoryPlayer.class) {
// Build Player Lens
// We only care about Server inventories
this.slots = new SlotCollection.Builder().add(this.mainInventory.size()).add(this.offHandInventory.size()).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.BOOTS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.LEGGINGS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.CHESTPLATE)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.HEADWEAR)).add(this.armorInventory.size() - 4, EquipmentSlotAdapter.class).add(this.getSizeInventory() - this.mainInventory.size() - this.offHandInventory.size() - this.armorInventory.size()).build();
this.lens = new PlayerInventoryLens(this, this.slots);
} else if (this.getSizeInventory() != 0) {
// Fallback OrderedLens when not 0 sized inventory
this.slots = new SlotCollection.Builder().add(this.getSizeInventory()).build();
this.lens = new OrderedInventoryLensImpl(0, this.getSizeInventory(), 1, slots);
}
}
}
use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeCommon by SpongePowered.
the class MixinTraitAdapter method getReusableLens.
@SuppressWarnings("unchecked")
private ReusableLens<?> getReusableLens() {
if (this.reusableLens != null) {
return this.reusableLens;
}
if (this instanceof ReusableLensProvider) {
return ((ReusableLensProvider<IInventory, ItemStack>) this).generateLens(this.getFabric(), this);
}
if (this instanceof LensProvider) {
this.slots = ((LensProvider) this).slotProvider(this.getFabric(), this);
Lens lens = ((LensProvider) this).rootLens(this.getFabric(), this);
return new ReusableLens<>(this.slots, lens);
}
SlotCollection slots = new SlotCollection.Builder().add(this.getFabric().getSize()).build();
Lens<IInventory, ItemStack> lens;
if (this.getFabric().getSize() == 0) {
lens = new DefaultEmptyLens<>(this);
} else {
lens = new OrderedInventoryLensImpl(0, this.getFabric().getSize(), 1, slots);
}
return new ReusableLens<>(slots, lens);
}
use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeCommon by SpongePowered.
the class BrewingStandInventoryLens method init.
@Override
protected void init(SlotProvider<IInventory, ItemStack> slots) {
this.potions = new OrderedInventoryLensImpl(0, 3, 1, OutputSlot.class, slots);
// TODO filter PotionIngredients
this.ingredient = new InputSlotLensImpl(3, (i) -> true, (i) -> true);
this.fuel = new FuelSlotLensImpl(4, (i) -> BLAZE_POWDER.equals(i.getType()), BLAZE_POWDER::equals);
this.addSpanningChild(this.potions);
this.addSpanningChild(this.ingredient);
this.addSpanningChild(this.fuel);
}
Aggregations