use of pneumaticCraft.common.recipes.AmadronOfferCustom in project PneumaticCraft by MineMaarten.
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);
NBTTagCompound inv = new NBTTagCompound();
// Write the ItemStacks in the inventory to NBT
NBTTagList tagList = new NBTTagList();
for (int currentIndex = 0; currentIndex < inventory.getSizeInventory(); ++currentIndex) {
if (inventory.getStackInSlot(currentIndex) != null) {
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte) currentIndex);
inventory.getStackInSlot(currentIndex).writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
inv.setTag("Inv", tagList);
NBTTagList upgradeList = new NBTTagList();
for (int i = 0; i < 9; i++) {
if (upgradeInventory[i] != null) {
NBTTagCompound slotEntry = new NBTTagCompound();
slotEntry.setByte("Slot", (byte) i);
upgradeInventory[i].writeToNBT(slotEntry);
upgradeList.appendTag(slotEntry);
}
}
// save content in Inventory->Items
inv.setTag("Items", upgradeList);
tag.setTag("Inventory", inv);
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);
}
}
use of pneumaticCraft.common.recipes.AmadronOfferCustom 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.AmadronOfferCustom in project PneumaticCraft by MineMaarten.
the class GuiAmadronAddTrade method actionPerformed.
@Override
public void actionPerformed(GuiButton button) {
EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
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) != null) {
input = container.getStack(0).copy();
((ItemStack) input).stackSize = inputNumber.getValue();
} else {
input = new FluidStack(inputFluid.getFluid(), inputNumber.getValue());
}
Object output;
if (container.getStack(1) != null) {
output = container.getStack(1).copy();
((ItemStack) output).stackSize = outputNumber.getValue();
} else {
output = new FluidStack(outputFluid.getFluid(), outputNumber.getValue());
}
AmadronOfferCustom trade = new AmadronOfferCustom(input, output, player);
ChunkPosition 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 pneumaticCraft.common.recipes.AmadronOfferCustom in project PneumaticCraft by MineMaarten.
the class WidgetAmadronOffer method render.
@Override
public void render(int mouseX, int mouseY, float partialTick) {
GL11.glDisable(GL11.GL_LIGHTING);
if (renderBackground) {
Minecraft.getMinecraft().getTextureManager().bindTexture(Textures.WIDGET_AMADRON_OFFER);
GL11.glColor4d(1, canBuy ? 1 : 0.4, canBuy ? 1 : 0.4, 1);
Gui.func_146110_a(x, y, 0, 0, getBounds().width, getBounds().height, 256, 256);
}
for (IGuiWidget widget : widgets) {
widget.render(mouseX, mouseY, partialTick);
}
Minecraft.getMinecraft().fontRenderer.drawString(offer.getVendor(), x + 2, y + 2, 0xFF000000);
boolean customOffer = offer instanceof AmadronOfferCustom;
if (shoppingAmount > 0) {
Minecraft.getMinecraft().fontRenderer.drawString(shoppingAmount + "", x + 36 - Minecraft.getMinecraft().fontRenderer.getStringWidth("" + shoppingAmount) / 2, y + (customOffer ? 15 : 20), 0xFF000000);
}
if (customOffer) {
AmadronOfferCustom custom = (AmadronOfferCustom) offer;
Minecraft.getMinecraft().fontRenderer.drawString(EnumChatFormatting.DARK_BLUE.toString() + custom.getStock() + "", x + 36 - Minecraft.getMinecraft().fontRenderer.getStringWidth("" + custom.getStock()) / 2, y + 25, 0xFF000000);
}
}
use of pneumaticCraft.common.recipes.AmadronOfferCustom in project PneumaticCraft by MineMaarten.
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.stackSize * drone.getOfferTimes();
List<ItemStack> stacks = new ArrayList<ItemStack>();
while (producedItems > 0) {
ItemStack stack = offeringItems.copy();
stack.stackSize = Math.min(producedItems, stack.getMaxStackSize());
stacks.add(stack);
producedItems -= stack.stackSize;
}
ChunkPosition pos = ItemAmadronTablet.getItemProvidingLocation(usedTablet);
if (pos != null) {
World world = PneumaticCraftUtils.getWorldForDimension(ItemAmadronTablet.getItemProvidingDimension(usedTablet));
PneumaticRegistry.getInstance().deliverItemsAmazonStyle(world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, stacks.toArray(new ItemStack[stacks.size()]));
}
} else {
FluidStack offeringFluid = ((FluidStack) offer.getOutput()).copy();
offeringFluid.amount *= drone.getOfferTimes();
ChunkPosition pos = ItemAmadronTablet.getLiquidProvidingLocation(usedTablet);
if (pos != null) {
World world = PneumaticCraftUtils.getWorldForDimension(ItemAmadronTablet.getLiquidProvidingDimension(usedTablet));
PneumaticRegistry.getInstance().deliverFluidAmazonStyle(world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, offeringFluid);
}
}
}
}
Aggregations