use of net.minecraft.util.NonNullList in project BuildCraft by BuildCraft.
the class GuiList method initGui.
@Override
public void initGui() {
super.initGui();
for (int line = 0; line < container.slots.length; line++) {
WidgetListSlot[] arr = container.slots[line];
for (int slot = 0; slot < arr.length; slot++) {
final WidgetListSlot listSlot = arr[slot];
GuiRectangle rectangle = new GuiRectangle(8 + slot * 18, 32 + line * 34, 16, 16);
IGuiArea phantomSlotArea = rectangle.offset(mainGui.rootElement);
mainGui.shownElements.add(listSlot.new GuiElementPhantomSlot(mainGui, phantomSlotArea) {
@Override
protected boolean shouldDrawHighlight() {
if (listSlot.slotIndex == 0) {
return true;
}
return !GuiList.this.container.lines[listSlot.lineIndex].isOneStackMode();
}
@Override
public void drawBackground(float partialTicks) {
if (!shouldDrawHighlight()) {
ICON_HIGHLIGHT.drawAt(this);
}
}
@Nonnull
@Override
public ItemStack getStack() {
if (shouldDrawHighlight()) {
return super.getStack();
} else {
NonNullList<ItemStack> data = GuiList.this.getExamplesList(listSlot.lineIndex, container.lines[listSlot.lineIndex].getSortingType());
if (data.size() >= listSlot.slotIndex) {
return data.get(listSlot.slotIndex - 1);
} else {
return StackUtil.EMPTY;
}
}
}
@Override
public void onMouseClicked(int button) {
super.onMouseClicked(button);
if (contains(gui.mouse)) {
clearExamplesCache(listSlot.lineIndex);
}
}
});
}
}
buttonList.clear();
for (int sy = 0; sy < ListHandler.HEIGHT; sy++) {
int bOff = sy * BUTTON_COUNT;
int bOffX = this.guiLeft + 8 + ListHandler.WIDTH * 18 - BUTTON_COUNT * 11;
int bOffY = this.guiTop + 32 + sy * 34 + 18;
GuiImageButton buttonPrecise = new GuiImageButton(mainGui, bOff + 0, bOffX, bOffY, 11, TEXTURE_BASE, 176, 16, 176, 28);
buttonPrecise.setToolTip(ToolTip.createLocalized("gui.list.nbt"));
buttonPrecise.setBehaviour(IButtonBehaviour.TOGGLE);
mainGui.shownElements.add(buttonPrecise);
GuiImageButton buttonType = new GuiImageButton(mainGui, bOff + 1, bOffX + 11, bOffY, 11, TEXTURE_BASE, 176, 16, 185, 28);
buttonType.setToolTip(ToolTip.createLocalized("gui.list.metadata"));
buttonType.setBehaviour(IButtonBehaviour.TOGGLE);
mainGui.shownElements.add(buttonType);
GuiImageButton buttonMaterial = new GuiImageButton(mainGui, bOff + 2, bOffX + 22, bOffY, 11, TEXTURE_BASE, 176, 16, 194, 28);
buttonMaterial.setToolTip(ToolTip.createLocalized("gui.list.oredict"));
buttonMaterial.setBehaviour(IButtonBehaviour.TOGGLE);
mainGui.shownElements.add(buttonMaterial);
}
for (IGuiElement elem : mainGui.shownElements) {
if (elem instanceof GuiImageButton) {
GuiImageButton b = (GuiImageButton) elem;
int id = Integer.parseInt(b.id);
int lineId = id / BUTTON_COUNT;
int buttonId = id % BUTTON_COUNT;
if (container.lines[lineId].getOption(buttonId)) {
b.activate();
}
b.registerListener(this);
}
}
textField = new GuiTextField(6, this.fontRenderer, guiLeft + 10, guiTop + 10, 156, 12);
textField.setMaxStringLength(32);
textField.setText(BCCoreItems.list.getName(container.getListItemStack()));
textField.setFocused(false);
}
use of net.minecraft.util.NonNullList in project BuildCraft by BuildCraft.
the class ListMatchHandlerFluid method getClientExamples.
@Override
public NonNullList<ItemStack> getClientExamples(Type type, @Nonnull ItemStack stack) {
buildClientExampleList();
if (type == Type.MATERIAL) {
FluidStack fStack = FluidUtil.getFluidContained(stack);
if (fStack != null) {
NonNullList<ItemStack> examples = NonNullList.create();
for (ItemStack potentialHolder : clientExampleHolders) {
potentialHolder = potentialHolder.copy();
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(potentialHolder);
if (fluidHandler != null && (fluidHandler.fill(fStack, true) > 0 || fluidHandler.drain(fStack, false) != null)) {
examples.add(fluidHandler.getContainer());
}
}
return examples;
}
} else if (type == Type.TYPE) {
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(stack.copy());
if (fluidHandler != null) {
NonNullList<ItemStack> examples = NonNullList.create();
examples.add(stack);
FluidStack contained = fluidHandler.drain(Integer.MAX_VALUE, true);
if (contained != null) {
examples.add(fluidHandler.getContainer());
for (ItemStack potential : clientExampleHolders) {
IFluidHandlerItem potentialHolder = FluidUtil.getFluidHandler(potential);
if (potentialHolder.fill(contained, true) > 0) {
examples.add(potentialHolder.getContainer());
}
}
}
return examples;
}
}
return null;
}
use of net.minecraft.util.NonNullList in project BaseMetals by MinecraftModDevelopmentMods.
the class ShieldUpgradeRecipe method matchAndFind.
private Pair<Map<Enchantment, Integer>, ItemStack> matchAndFind(final ItemStack curItem, final Map<String, NonNullList<ItemStack>> plates) {
final ItemStack comp = new ItemStack(curItem.getItem(), 1, curItem.getMetadata());
Map<Enchantment, Integer> enchants = Collections.emptyMap();
ItemStack plateMatched = null;
final ItemStack matcher = new ItemStack(Materials.getMaterialByName(materialName).getItem(Names.SHIELD), 1, 0);
for (final Entry<String, NonNullList<ItemStack>> ent : plates.entrySet()) {
if (OreDictionary.containsMatch(false, ent.getValue(), comp)) {
plateMatched = new ItemStack(Materials.getMaterialByName(ent.getKey().toLowerCase()).getItem(Names.SHIELD), 1, 0);
}
}
if (OreDictionary.itemMatches(matcher, comp, false)) {
enchants = EnchantmentHelper.getEnchantments(curItem);
}
return Pair.of(enchants, plateMatched);
}
use of net.minecraft.util.NonNullList in project Skree by Skelril.
the class ZoneMasterOrb method onBlockInteract.
@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<org.spongepowered.api.item.inventory.ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = tf(optItemStack.get());
if (!isZoneMasterItem(itemStack)) {
return;
}
if (isAttuned(itemStack)) {
if (isInInstanceWorld(player)) {
player.sendMessage(Text.of(TextColors.RED, "You cannot start an instance from within an instance."));
event.setCancelled(true);
return;
}
Optional<ZoneService> optService = Sponge.getServiceManager().provide(ZoneService.class);
if (optService.isPresent()) {
Task.builder().execute(() -> {
ZoneService service = optService.get();
List<Player> group = new ArrayList<>();
group.add(player);
for (Player aPlayer : Sponge.getServer().getOnlinePlayers()) {
NonNullList<ItemStack> itemStacks = tf(aPlayer).inventory.mainInventory;
for (ItemStack aStack : itemStacks) {
if (!hasSameZoneID(itemStack, aStack)) {
continue;
}
if (isAttuned(aStack) && isZoneSlaveItem(aStack)) {
Optional<Player> optZoneOwner = getGroupOwner(aStack);
if (optZoneOwner.isPresent()) {
group.add(aPlayer);
break;
}
}
}
}
for (int i = group.size() - 1; i >= 0; --i) {
purgeZoneItems(group.get(i), itemStack);
// createLightningStrike(group.get(i)); SpongeCommon/420
saveLocation(group.get(i));
getMainWorldWrapper().getLobby().add(group.get(i));
}
service.requestZone(getZone(itemStack).get(), group, () -> {
getMainWorldWrapper().getLobby().remove(group);
}, result -> {
if (result.isPresent()) {
result.get().stream().filter(entry -> entry.getValue() != ZoneStatus.ADDED).forEach(entry -> {
player.setLocation(getRespawnLocation(player));
player.sendMessage(Text.of(TextColors.RED, "You could not be added to the zone."));
});
}
});
}).delayTicks(1).submit(SkreePlugin.inst());
}
}
event.setUseBlockResult(Tristate.FALSE);
}
use of net.minecraft.util.NonNullList in project Metalworks by canitzp.
the class Metalworks method postInit.
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
SimpleSteelRecipeHandler.addBlastFurnaceRecipe(new RecipeBlastFurnace(new OreDictStack("ingotIron").setStacksize(2), new OreDictStack(Items.COAL).setStacksize(3), OreDictStack.EMPTY, new ItemStack(Registry.steelIngot), ItemStack.EMPTY, 0, 400, -1));
SimpleSteelRecipeHandler.addBlastFurnaceRecipe(new RecipeBlastFurnace(new OreDictStack("ingotIron").setStacksize(3), new OreDictStack("gemDiamond"), OreDictStack.EMPTY, new ItemStack(Registry.metalShielding, 4), new ItemStack(Items.IRON_NUGGET), 25, 250, -1));
// Generic Crusher
for (String name : OreDictionary.getOreNames()) {
if (name.startsWith("ore")) {
String dustName = name.replaceFirst("ore", "dust");
NonNullList<ItemStack> oreEntries = OreDictionary.getOres(dustName);
if (!oreEntries.isEmpty()) {
ItemStack dust = oreEntries.get(0).copy();
dust.setCount(2);
MACHINE_RECIPE_REGISTRY.register(new RecipeCrusher(name + "_" + dustName, new OreDictStack(name), dust, ItemStack.EMPTY, 0, 200, 0));
}
} else if (name.startsWith("ingot")) {
String dustName = name.replaceFirst("ingot", "dust");
NonNullList<ItemStack> oreEntries = OreDictionary.getOres(dustName);
if (!oreEntries.isEmpty()) {
ItemStack dust = oreEntries.get(0).copy();
dust.setCount(1);
MACHINE_RECIPE_REGISTRY.register(new RecipeCrusher(name + "_" + dustName, new OreDictStack(name), dust, ItemStack.EMPTY, 0, 150, 0));
}
}
}
}
Aggregations