use of net.minecraft.util.NonNullList 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 net.minecraft.util.NonNullList in project Charset by CharsetMC.
the class RecipeReplacement method process.
public void process(Collection<IRecipe> registry) {
for (IRecipe recipe : registry) {
ResourceLocation recipeName = recipe.getRegistryName();
boolean dirty = false;
if (recipe instanceof ShapedRecipes || recipe instanceof ShapelessRecipes || recipe instanceof ShapedOreRecipe || recipe instanceof ShapelessOreRecipe) {
NonNullList<Ingredient> ingredients = recipe.getIngredients();
for (int i = 0; i < ingredients.size(); i++) {
Ingredient ing = ingredients.get(i);
Ingredient ingNew = replaceIngredient(ing);
if (ingNew != null) {
ingredients.set(i, ingNew);
dirty = true;
}
}
} else if (recipe instanceof RecipeCharset) {
TCharObjectMap<Ingredient> charToIngredient = ((RecipeCharset) recipe).charToIngredient;
NonNullList<Ingredient> ingredients = recipe.getIngredients();
for (int i = 0; i < ingredients.size(); i++) {
Ingredient ing = ingredients.get(i);
Ingredient ingNew = replaceIngredient(ing);
if (ingNew != null) {
ingredients.set(i, ingNew);
TCharIterator iterator = charToIngredient.keySet().iterator();
while (iterator.hasNext()) {
char c = iterator.next();
if (charToIngredient.get(c) == ing) {
charToIngredient.put(c, ing);
}
}
dirty = true;
}
}
}
if (dirty) {
ModCharset.logger.info("Successfully edited " + recipeName + "!");
}
}
}
use of net.minecraft.util.NonNullList in project ConvenientAdditions by Necr0.
the class ShapelessNBTOreRecipe method matches.
@SuppressWarnings("unchecked")
@Override
public boolean matches(InventoryCrafting var1, World world) {
NonNullList<Object> required = NonNullList.create();
required.addAll(input);
for (int x = 0; x < var1.getSizeInventory(); x++) {
ItemStack slot = var1.getStackInSlot(x);
if (!slot.isEmpty()) {
boolean inRecipe = false;
Iterator<Object> req = required.iterator();
while (req.hasNext()) {
boolean match = false;
Object next = req.next();
if (next instanceof ItemStack) {
match = OreDictionary.itemMatches((ItemStack) next, slot, false) && (!((ItemStack) next).hasTagCompound() || ItemStack.areItemStackTagsEqual((ItemStack) next, slot));
} else if (next instanceof List) {
Iterator<ItemStack> itr = ((List<ItemStack>) next).iterator();
while (itr.hasNext() && !match) {
ItemStack nxt = itr.next();
match = OreDictionary.itemMatches(nxt, slot, false) && (!nxt.hasTagCompound() || ItemStack.areItemStackTagsEqual(nxt, slot));
}
}
if (match) {
inRecipe = true;
required.remove(next);
break;
}
}
if (!inRecipe) {
return false;
}
}
}
return required.isEmpty();
}
use of net.minecraft.util.NonNullList in project BuildCraft by BuildCraft.
the class GuidePageContents method loadMainGui.
public void loadMainGui() {
TypeOrder order = GuiGuide.SORTING_TYPES[gui.sortingOrderIndex];
contents.clear();
quickSearcher = new SuffixArray<>();
lastSearchText = "";
Set<Item> itemsAdded = new HashSet<>();
final String underline = TextFormatting.UNDERLINE.toString();
for (PageEntry<?> entry : GuideManager.INSTANCE.getAllEntries()) {
GuidePageFactory entryFactory = GuideManager.INSTANCE.getFactoryFor(entry);
String[] ordered = entry.typeTags.getOrdered(order);
String header = underline + LocaleUtil.localize(ordered[0]);
String subHeader = underline + LocaleUtil.localize(ordered[1]);
String translatedTitle = LocaleUtil.localize(entry.title);
ISimpleDrawable icon = entry.createDrawable();
PageLine line = new PageLine(icon, icon, 2, translatedTitle, true);
GuideText text = new GuideText(gui, line);
SubHeader pageHolder = contents.getOrAddSubHeader(header, subHeader);
if (entryFactory == null) {
if (entry.value instanceof ItemStackValueFilter) {
ItemStack stack = ((ItemStackValueFilter) entry.value).stack.baseStack;
itemsAdded.add(stack.getItem());
PageLinkGenerated pageLink = pageHolder.addKnownPage(text, stack);
if (pageLink != null) {
quickSearcher.add(pageLink, pageLink.joinedTooltip.toLowerCase(Locale.ROOT));
}
}
} else {
if (entry.value instanceof ItemStackValueFilter) {
ItemStack stack = ((ItemStackValueFilter) entry.value).stack.baseStack;
itemsAdded.add(stack.getItem());
}
PageLinkNormal pageLink = pageHolder.addNormalPage(text, entryFactory);
quickSearcher.add(pageLink, pageLink.getName().toLowerCase(Locale.ROOT));
}
}
String localizedGroup = underline + "\u0379" + LocaleUtil.localize("buildcraft.guide.contents.all_group");
String localizedItems = underline + LocaleUtil.localize("buildcraft.guide.contents.item_stacks");
Title allTitle = contents.getOrAddTitle(localizedGroup);
SubHeader allHolder = allTitle.getOrAddSubHeader(localizedItems);
for (Item item : ForgeRegistries.ITEMS) {
if (itemsAdded.contains(item)) {
continue;
}
NonNullList<ItemStack> stacks = NonNullList.create();
item.getSubItems(CreativeTabs.SEARCH, stacks);
for (int i = 0; i < stacks.size(); i++) {
ItemStack stack = stacks.get(i);
PageLinkGenerated pageLink = allHolder.addUnknownStack(stack);
if (pageLink != null) {
quickSearcher.add(pageLink, pageLink.joinedTooltip.toLowerCase(Locale.ROOT));
}
if (i > 50) {
// most likely the same item
break;
}
}
}
String localizedTriggers = underline + LocaleUtil.localize("buildcraft.guide.contents.triggers");
String localizedActions = underline + LocaleUtil.localize("buildcraft.guide.contents.actions");
SubHeader triggers = allTitle.getOrAddSubHeader(localizedTriggers);
SubHeader actions = allTitle.getOrAddSubHeader(localizedActions);
Set<IStatement> added = new HashSet<>();
for (IStatement statement : new TreeMap<>(StatementManager.statements).values()) {
if (!added.add(statement)) {
continue;
}
if (GuideManager.INSTANCE.getEntryFor(statement) != null) {
continue;
}
ISimpleDrawable icon = (x, y) -> GuiElementStatementSource.drawGuiSlot(statement, x, y);
List<String> tooltip = statement.getTooltip();
String title = tooltip.isEmpty() ? statement.getUniqueTag() : tooltip.get(0);
GuideText text = new GuideText(gui, new PageLine(icon, icon, 2, title, true));
final PageLinkNormal pageLink;
if (statement instanceof ITrigger) {
pageLink = triggers.addUnknownPage(text, g -> new GuidePage(gui, ImmutableList.of(), title));
} else if (statement instanceof IAction) {
pageLink = actions.addUnknownPage(text, g -> new GuidePage(gui, ImmutableList.of(), title));
} else {
pageLink = null;
}
if (pageLink != null) {
String joinedTooltip = tooltip.stream().collect(Collectors.joining(" ", "", ""));
String searchSr = statement.getUniqueTag() + " " + joinedTooltip;
quickSearcher.add(pageLink, searchSr.toLowerCase(Locale.ROOT));
}
}
quickSearcher.generate();
contents.sortAll();
}
use of net.minecraft.util.NonNullList in project BuildCraft by BuildCraft.
the class GuideCraftingFactory method oreConvert.
@Nonnull
private static ItemStack oreConvert(Object object) {
if (object == null) {
return StackUtil.EMPTY;
}
if (object instanceof ItemStack) {
return ((ItemStack) object).copy();
}
if (object instanceof String) {
NonNullList<ItemStack> stacks = OreDictionary.getOres((String) object);
// It will be sorted out below
object = stacks;
}
if (object instanceof List<?>) {
List<?> list = (List<?>) object;
if (list.isEmpty()) {
return StackUtil.EMPTY;
}
Object first = list.get(0);
if (first == null) {
return StackUtil.EMPTY;
}
if (first instanceof ItemStack) {
ItemStack best = (ItemStack) first;
for (Object obj : list) {
if (!(obj instanceof ItemStack)) {
continue;
}
ItemStack stack = (ItemStack) obj;
// The lower the ID of an item, the closer it is to minecraft. Hmmm.
if (Item.getIdFromItem(stack.getItem()) < Item.getIdFromItem(best.getItem())) {
best = stack;
}
}
return best.copy();
}
BCLog.logger.warn("Found a list with unknown contents! " + first.getClass());
}
BCLog.logger.warn("Found an ore with an unknown " + object.getClass());
return StackUtil.EMPTY;
}
Aggregations