use of me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom 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.AmadronOfferCustom 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.AmadronOfferCustom in project pnc-repressurized by TeamPneumatic.
the class PacketAmadronTradeAdd method handleServerSide.
@Override
public void handleServerSide(PacketAmadronTradeAdd message, EntityPlayer player) {
AmadronOfferCustom offer = message.getOffer();
offer.updatePlayerId();
if (AmadronOfferManager.getInstance().hasOffer(offer.copy().invert())) {
player.sendStatusMessage(new TextComponentTranslation("message.amadron.duplicateReversedOffer"), false);
} else if (AmadronOfferManager.getInstance().addStaticOffer(offer)) {
if (AmadronOfferSettings.notifyOfTradeAddition)
NetworkHandler.sendToAll(message);
try {
AmadronOfferStaticConfig.INSTANCE.writeToFile();
} catch (IOException e) {
e.printStackTrace();
}
} else {
player.sendStatusMessage(new TextComponentTranslation("message.amadron.duplicateOffer"), false);
}
}
use of me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom in project pnc-repressurized by TeamPneumatic.
the class GuiAmadronAddTrade method actionPerformed.
@Override
public void actionPerformed(GuiButton button) {
EntityPlayer player = FMLClientHandler.instance().getClient().player;
ContainerAmadronAddTrade container = (ContainerAmadronAddTrade) inventorySlots;
if (button.id < 6 && button.id >= 0) {
isSettingInput = button.id < 3;
if (button.id % 3 == 0) {
searchGui = new GuiSearcher(player);
searchGui.setSearchStack(container.getStack(isSettingInput ? 0 : 1));
FMLClientHandler.instance().showGuiScreen(searchGui);
} else if (button.id % 3 == 1) {
invSearchGui = new GuiInventorySearcher(player);
invSearchGui.setSearchStack(container.getStack(isSettingInput ? 0 : 1));
FMLClientHandler.instance().showGuiScreen(invSearchGui);
} else if (button.id % 3 == 2) {
fluidGui = new GuiLogisticsLiquidFilter(this);
fluidGui.setFilter(isSettingInput ? inputFluid.getFluid() : outputFluid.getFluid());
FMLClientHandler.instance().showGuiScreen(fluidGui);
}
} else if (button.id == 8) {
Object input;
if (!container.getStack(0).isEmpty()) {
input = container.getStack(0).copy();
((ItemStack) input).setCount(inputNumber.getValue());
} else {
input = new FluidStack(inputFluid.getFluid(), inputNumber.getValue());
}
Object output;
if (!container.getStack(1).isEmpty()) {
output = container.getStack(1).copy();
((ItemStack) output).setCount(outputNumber.getValue());
} else {
output = new FluidStack(outputFluid.getFluid(), outputNumber.getValue());
}
AmadronOfferCustom trade = new AmadronOfferCustom(input, output, player);
BlockPos pos = getInputPosition();
int dimensionId = getInputDimension();
trade.setProvidingPosition(pos, dimensionId);
pos = getOutputPosition();
dimensionId = getOutputDimension();
trade.setReturningPosition(pos, dimensionId);
NetworkHandler.sendToServer(new PacketAmadronTradeAdd(trade.invert()));
player.closeScreen();
}
super.actionPerformed(button);
}
use of me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom in project pnc-repressurized by TeamPneumatic.
the class EntityDrone method writeEntityToNBT.
@Override
public void writeEntityToNBT(NBTTagCompound tag) {
super.writeEntityToNBT(tag);
TileEntityProgrammer.setWidgetsToNBT(progWidgets, tag);
tag.setBoolean("naturallySpawned", naturallySpawned);
tag.setFloat("currentAir", currentAir);
tag.setFloat("propSpeed", propSpeed);
tag.setBoolean("disabledByHacking", disabledByHacking);
tag.setBoolean("hackedByOwner", gotoOwnerAI != null);
tag.setInteger("color", getDroneColor());
tag.setBoolean("standby", standby);
tag.setFloat("volume", volume);
NBTTagCompound variableTag = new NBTTagCompound();
aiManager.writeToNBT(variableTag);
tag.setTag("variables", variableTag);
tag.setTag("Inventory", inventory.serializeNBT());
tag.setTag(ChargeableItemHandler.NBT_UPGRADE_TAG, upgradeInventory.serializeNBT());
tank.writeToNBT(tag);
if (handlingOffer != null) {
NBTTagCompound subTag = new NBTTagCompound();
subTag.setBoolean("isCustom", handlingOffer instanceof AmadronOfferCustom);
handlingOffer.writeToNBT(subTag);
tag.setTag("amadronOffer", subTag);
tag.setInteger("offerTimes", offerTimes);
if (usedTablet != null)
usedTablet.writeToNBT(subTag);
tag.setString("buyingPlayer", buyingPlayer);
}
}
Aggregations