use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.
the class ItemAmadronTablet method setShoppingCart.
public static void setShoppingCart(ItemStack tablet, Map<AmadronOffer, Integer> cart) {
NBTTagList list = new NBTTagList();
for (Map.Entry<AmadronOffer, Integer> entry : cart.entrySet()) {
NBTTagCompound tag = new NBTTagCompound();
entry.getKey().writeToNBT(tag);
tag.setInteger("amount", entry.getValue());
list.appendTag(tag);
}
NBTUtil.setCompoundTag(tablet, "shoppingCart", list);
}
use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.
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 me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.
the class ContainerAmadron method handleGUIButtonPress.
@Override
public void handleGUIButtonPress(int guiID, EntityPlayer player) {
super.handleGUIButtonPress(guiID, player);
if (guiID == 1) {
for (int i = 0; i < shoppingItems.length; i++) {
if (shoppingItems[i] >= 0) {
AmadronOffer offer = offers.get(shoppingItems[i]);
BlockPos itemPos = ItemAmadronTablet.getItemProvidingLocation(player.getHeldItemMainhand());
World itemWorld;
if (itemPos == null) {
itemPos = new BlockPos((int) player.posX, (int) player.posY, (int) player.posZ);
itemWorld = player.world;
} else {
itemWorld = DimensionManager.getWorld(ItemAmadronTablet.getItemProvidingDimension(player.getHeldItemMainhand()));
}
BlockPos liquidPos = ItemAmadronTablet.getLiquidProvidingLocation(player.getHeldItemMainhand());
World liquidWorld = null;
if (liquidPos != null) {
liquidWorld = DimensionManager.getWorld(ItemAmadronTablet.getLiquidProvidingDimension(player.getHeldItemMainhand()));
}
EntityDrone drone = retrieveOrderItems(offer, shoppingAmounts[i], itemWorld, itemPos, liquidWorld, liquidPos);
if (drone != null)
drone.setHandlingOffer(offer, shoppingAmounts[i], player.getHeldItemMainhand(), player.getName());
}
}
Arrays.fill(shoppingAmounts, 0);
Arrays.fill(shoppingItems, -1);
} else if (guiID == 2) {
player.openGui(PneumaticCraftRepressurized.instance, CommonProxy.EnumGuiId.AMADRON_ADD_TRADE.ordinal(), player.world, 0, 0, 0);
}
}
use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.
the class EventHandlerPneumaticCraft method onAmadronSuccess.
@SubscribeEvent
public void onAmadronSuccess(AmadronRetrievalEvent event) {
EntityDrone drone = (EntityDrone) event.drone;
AmadronOffer offer = drone.getHandlingOffer();
boolean shouldDeliver = false;
if (offer instanceof AmadronOfferCustom) {
AmadronOffer realOffer = AmadronOfferManager.getInstance().get(offer);
if (realOffer != null) {
// If we find the non-inverted offer, that means the Drone just has completed trading with a different player.
((AmadronOfferCustom) realOffer).addPayment(drone.getOfferTimes());
((AmadronOfferCustom) realOffer).addStock(-drone.getOfferTimes());
realOffer.onTrade(drone.getOfferTimes(), drone.getBuyingPlayer());
shouldDeliver = true;
}
realOffer = AmadronOfferManager.getInstance().get(((AmadronOfferCustom) offer).copy().invert());
if (realOffer != null) {
// If we find the inverted offer, that means the Drone has just restocked.
((AmadronOfferCustom) realOffer).addStock(drone.getOfferTimes());
}
} else {
shouldDeliver = true;
}
if (shouldDeliver) {
ItemStack usedTablet = drone.getUsedTablet();
if (offer.getOutput() instanceof ItemStack) {
ItemStack offeringItems = (ItemStack) offer.getOutput();
int producedItems = offeringItems.getCount() * drone.getOfferTimes();
List<ItemStack> stacks = new ArrayList<ItemStack>();
while (producedItems > 0) {
ItemStack stack = offeringItems.copy();
stack.setCount(Math.min(producedItems, stack.getMaxStackSize()));
stacks.add(stack);
producedItems -= stack.getCount();
}
BlockPos pos = ItemAmadronTablet.getItemProvidingLocation(usedTablet);
if (pos != null) {
World world = DimensionManager.getWorld(ItemAmadronTablet.getItemProvidingDimension(usedTablet));
DroneRegistry.getInstance().deliverItemsAmazonStyle(world, pos, stacks.toArray(new ItemStack[stacks.size()]));
}
} else {
FluidStack offeringFluid = ((FluidStack) offer.getOutput()).copy();
offeringFluid.amount *= drone.getOfferTimes();
BlockPos pos = ItemAmadronTablet.getLiquidProvidingLocation(usedTablet);
if (pos != null) {
World world = DimensionManager.getWorld(ItemAmadronTablet.getLiquidProvidingDimension(usedTablet));
DroneRegistry.getInstance().deliverFluidAmazonStyle(world, pos, offeringFluid);
}
}
}
}
use of me.desht.pneumaticcraft.common.recipes.AmadronOffer in project pnc-repressurized by TeamPneumatic.
the class AmadronOfferConfig method readFromJson.
@Override
protected final void readFromJson(JsonObject json) {
readFromJsonCustom(json);
JsonArray array = (JsonArray) json.get("offers");
Collection<AmadronOffer> offers = getOffers();
offers.clear();
for (JsonElement element : array) {
AmadronOffer offer = ((JsonObject) element).has("inStock") ? AmadronOfferCustom.fromJson((JsonObject) element) : AmadronOffer.fromJson((JsonObject) element);
if (offer != null) {
offers.add(offer);
}
}
}
Aggregations