use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.
the class GuiAmadron method updateVisibleOffers.
public void updateVisibleOffers() {
needsRefreshing = false;
final ContainerAmadron container = (ContainerAmadron) inventorySlots;
int invSize = ContainerAmadron.ROWS * 2;
container.clearStacks();
List<AmadronOffer> offers = container.offers;
List<AmadronOffer> visibleOffers = new ArrayList<AmadronOffer>();
int skippedOffers = 0;
int applicableOffers = 0;
for (AmadronOffer offer : offers) {
if (offer.passesQuery(searchBar.getText())) {
applicableOffers++;
if (skippedOffers < page * invSize) {
skippedOffers++;
} else if (visibleOffers.size() < invSize) {
visibleOffers.add(offer);
}
}
}
scrollbar.setStates(Math.max(1, (applicableOffers + invSize - 1) / invSize - 1));
widgets.removeAll(widgetOffers);
for (int i = 0; i < visibleOffers.size(); i++) {
AmadronOffer offer = visibleOffers.get(i);
if (offer.getInput() instanceof ItemStack)
container.setStack(i * 2, (ItemStack) offer.getInput());
if (offer.getOutput() instanceof ItemStack)
container.setStack(i * 2 + 1, (ItemStack) offer.getOutput());
WidgetAmadronOffer widget = new WidgetAmadronOffer(i, guiLeft + 6 + 73 * (i % 2), guiTop + 55 + 35 * (i / 2), offer) {
@Override
public void onMouseClicked(int mouseX, int mouseY, int button) {
NetworkHandler.sendToServer(new PacketAmadronOrderUpdate(container.offers.indexOf(getOffer()), button, PneumaticCraft.proxy.isSneakingInGui()));
}
};
addWidget(widget);
widgetOffers.add(widget);
}
}
use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.
the class AmadronOfferConfig method writeToJson.
@Override
protected final void writeToJson(JsonObject json) {
JsonArray array = new JsonArray();
for (AmadronOffer offer : getOffers()) {
array.add(offer.toJson());
}
json.addProperty("description", getComment());
writeToJsonCustom(json);
json.add("offers", array);
}
use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.
the class ContainerAmadron method clickOffer.
public void clickOffer(int offerId, int mouseButton, boolean sneaking, EntityPlayer player) {
problemState = EnumProblemState.NO_PROBLEMS;
int cartSlot = getCartSlot(offerId);
if (cartSlot >= 0) {
if (mouseButton == 2) {
shoppingAmounts[cartSlot] = 0;
} else if (sneaking) {
if (mouseButton == 0)
shoppingAmounts[cartSlot] /= 2;
else {
AmadronOffer offer = offers.get(offerId);
if (offer instanceof AmadronOfferCustom) {
AmadronOfferCustom custom = (AmadronOfferCustom) offer;
if (custom.getPlayerId().equals(player.getGameProfile().getId().toString())) {
if (AmadronOfferManager.getInstance().removeStaticOffer(custom)) {
if (AmadronOfferSettings.notifyOfTradeRemoval)
NetworkHandler.sendToAll(new PacketAmadronTradeRemoved(custom));
custom.returnStock();
try {
AmadronOfferStaticConfig.INSTANCE.writeToFile();
} catch (IOException e) {
e.printStackTrace();
}
player.closeScreen();
}
}
}
shoppingAmounts[cartSlot] *= 2;
if (shoppingAmounts[cartSlot] == 0)
shoppingAmounts[cartSlot] = 1;
}
} else {
if (mouseButton == 0)
shoppingAmounts[cartSlot]--;
else
shoppingAmounts[cartSlot]++;
}
if (shoppingAmounts[cartSlot] <= 0) {
shoppingAmounts[cartSlot] = 0;
shoppingItems[cartSlot] = -1;
} else {
shoppingAmounts[cartSlot] = capShoppingAmount(offerId, shoppingAmounts[cartSlot], player);
if (shoppingAmounts[cartSlot] > 0)
shoppingItems[cartSlot] = offerId;
else
shoppingItems[cartSlot] = -1;
}
}
}
use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.
the class ItemAmadronTablet method getShoppingCart.
public static Map<AmadronOffer, Integer> getShoppingCart(ItemStack tablet) {
Map<AmadronOffer, Integer> offers = new HashMap<AmadronOffer, Integer>();
if (tablet.hasTagCompound() && tablet.getTagCompound().hasKey("shoppingCart")) {
NBTTagList list = tablet.getTagCompound().getTagList("shoppingCart", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound tag = list.getCompoundTagAt(i);
offers.put(tag.hasKey("inStock") ? AmadronOfferCustom.loadFromNBT(tag) : AmadronOffer.loadFromNBT(tag), tag.getInteger("amount"));
}
}
return offers;
}
use of pneumaticCraft.common.recipes.AmadronOffer in project PneumaticCraft by MineMaarten.
the class EventHandlerPneumaticCraft method onDroneSuicide.
@SubscribeEvent
public void onDroneSuicide(DroneSuicideEvent event) {
if (event.drone instanceof EntityDrone) {
EntityDrone drone = (EntityDrone) event.drone;
AmadronOffer offer = drone.getHandlingOffer();
if (offer != null) {
int times = drone.getOfferTimes();
if (offer.getInput() instanceof ItemStack) {
int requiredCount = ((ItemStack) offer.getInput()).stackSize * times;
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
if (drone.getInventory().getStackInSlot(i) != null) {
requiredCount -= drone.getInventory().getStackInSlot(i).stackSize;
}
}
if (requiredCount <= 0) {
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
drone.getInventory().setInventorySlotContents(i, null);
}
MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
}
} else {
int requiredCount = ((FluidStack) offer.getInput()).amount * times;
if (drone.getTank().getFluidAmount() >= requiredCount) {
MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
}
}
}
}
}
Aggregations