use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.
the class InventoryCraftingStation method craft.
/** Called when an item is removed from the output slot while it doesn't
* store any real items. Returns if the recipe can be crafted again.*/
private boolean craft(EntityPlayer player, boolean simulate) {
ItemStack[] contents = (simulate ? this.contents.clone() : this.contents);
ItemStack[] crafting = (simulate ? this.crafting.clone() : this.crafting);
if (simulate)
for (int i = 0; i < crafting.length; i++) crafting[i] = ItemStack.copyItemStack(crafting[i]);
if (currentCrafting instanceof VanillaStationCrafting) {
boolean unset = false;
if (player == null) {
player = FakePlayer.get(entity);
unset = true;
}
ItemStack craftOutput = (simulate ? output[4].copy() : output[4]);
IInventory craftMatrix = new InventoryStacks(crafting);
FMLCommonHandler.instance().firePlayerCraftingEvent(player, craftOutput, craftMatrix);
new CustomSlotCrafting(player, craftOutput);
if (unset) {
FakePlayer.unset();
player = null;
}
}
ICraftingSource source = new CraftingSourceTileEntity(entity, player);
currentCrafting.craft(source);
IRecipeInput[] requiredInput = currentCrafting.getCraftRequirements();
for (int i = 0; i < crafting.length; i++) if (crafting[i] != null)
crafting[i] = craftSlot(crafting[i], requiredInput[i], player, simulate);
boolean pulled = pullRequired(contents, crafting, requiredInput);
if (!simulate) {
int requiredExperience = currentCrafting.getRequiredExperience();
if ((requiredExperience != 0) && (player != null) && !player.capabilities.isCreativeMode)
player.experienceLevel -= requiredExperience;
outputIsReal = !outputEmpty();
progress = 0;
inputChanged();
checkHasRequirements = true;
}
return pulled;
}
use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.
the class ItemBackpack method openBackpack.
/** Opens the carrier's equipped backpack for the player.
* Returns if it was successfully opened. */
public static boolean openBackpack(EntityPlayer player, EntityLivingBase carrier) {
ItemStack backpack = ItemBackpack.getBackpack(carrier);
if (backpack == null)
return false;
ItemBackpack backpackType = (ItemBackpack) backpack.getItem();
IInventory inventory = ItemBackpack.getBackpackItems(carrier, player);
inventory = new InventoryBackpackEquipped(carrier, player, inventory);
if (!inventory.isUseableByPlayer(player))
return false;
int columns = backpackType.getBackpackColumns();
int rows = backpackType.getBackpackRows();
Container container = new ContainerBetterStorage(player, inventory, columns, rows);
String title = StackUtils.get(backpack, "", "display", "Name");
PlayerUtils.openGui(player, inventory.getInventoryName(), columns, rows, title, container);
return true;
}
use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.
the class WorldUtils method syncPlayersUsing.
/** Counts and returns the number of players who're accessing a tile entity. */
public static int syncPlayersUsing(TileEntity te, int playersUsing, IInventory playerInventory) {
if (!te.getWorldObj().isRemote && (playersUsing != 0)) {
playersUsing = 0;
List<EntityPlayer> players = te.getWorldObj().getEntitiesWithinAABB(EntityPlayer.class, getAABB(te, 5));
for (EntityPlayer player : players) {
if (player.openContainer instanceof ContainerBetterStorage) {
IInventory inventory = ((ContainerBetterStorage) player.openContainer).inventory;
if (inventory == playerInventory)
playersUsing++;
else if (inventory instanceof InventoryTileEntity)
if (((InventoryTileEntity) inventory).mainTileEntity == te)
playersUsing++;
}
}
}
return playersUsing;
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class GuiPneumaticContainerBase method drawGuiContainerForegroundLayer.
@Override
protected void drawGuiContainerForegroundLayer(int x, int y) {
if (getInvNameOffset() != null && te instanceof IInventory) {
IInventory inv = (IInventory) te;
String containerName = inv.hasCustomInventoryName() ? inv.getInventoryName() : StatCollector.translateToLocal(inv.getInventoryName() + ".name");
fontRendererObj.drawString(containerName, xSize / 2 - fontRendererObj.getStringWidth(containerName) / 2 + getInvNameOffset().x, 6 + getInvNameOffset().y, 4210752);
}
if (getInvTextOffset() != null)
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8 + getInvTextOffset().x, ySize - 94 + getInvTextOffset().y, 4210752);
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class GuiPneumaticContainerBase method initGui.
@Override
public void initGui() {
super.initGui();
lastLeftStat = lastRightStat = null;
if (shouldAddPressureTab() && te instanceof TileEntityPneumaticBase) {
pressureStat = this.addAnimatedStat("gui.tab.pressure", new ItemStack(Blockss.pressureTube), 0xFF00AA00, false);
}
if (shouldAddProblemTab()) {
problemTab = addAnimatedStat("gui.tab.problems", Textures.GUI_PROBLEMS_TEXTURE, 0xFFFF0000, false);
}
if (shouldAddRedstoneTab() && te instanceof IRedstoneControl) {
redstoneTab = addAnimatedStat("gui.tab.redstoneBehaviour", new ItemStack(Items.redstone), 0xFFCC0000, true);
List<String> curInfo = new ArrayList<String>();
curInfo.add(I18n.format(getRedstoneString()));
for (int i = 0; i < 3; i++) // create some space for the button
curInfo.add(" ");
redstoneTab.setTextWithoutCuttingString(curInfo);
Rectangle buttonRect = redstoneTab.getButtonScaledRectangle(-170, 24, 170, 20);
//getButtonFromRectangle(0, buttonRect, "-");
redstoneButton = new GuiButtonSpecial(0, buttonRect.x, buttonRect.y, buttonRect.width, buttonRect.height, "-");
redstoneTab.addWidget(redstoneButton);
}
if (te instanceof IInventory) {
if (shouldAddInfoTab()) {
String info = "gui.tab.info." + ((IInventory) te).getInventoryName();
String translatedInfo = I18n.format(info);
if (!translatedInfo.equals(info)) {
addInfoTab(translatedInfo);
}
}
if (te instanceof IHeatExchanger) {
addAnimatedStat("gui.tab.info.heat.title", new ItemStack(Blocks.fire), 0xFFFF5500, false).setText("gui.tab.info.heat");
}
if (shouldAddUpgradeTab()) {
String upgrades = "gui.tab.upgrades." + ((IInventory) te).getInventoryName();
String translatedUpgrades = I18n.format(upgrades);
List<String> upgradeText = new ArrayList<String>();
if (te instanceof TileEntityPneumaticBase) {
upgradeText.add("gui.tab.upgrades.volume");
upgradeText.add("gui.tab.upgrades.security");
}
if (te instanceof IHeatExchanger) {
upgradeText.add("gui.tab.upgrades.volumeCapacity");
}
if (!translatedUpgrades.equals(upgrades))
upgradeText.add(upgrades);
if (upgradeText.size() > 0)
addAnimatedStat("gui.tab.upgrades", Textures.GUI_UPGRADES_LOCATION, 0xFF0000FF, true).setText(upgradeText);
}
}
}
Aggregations