- 44
- 0
Решил сделать торговлю с электронной валютой(IEEP), вырезал торговый блок из universalcoins чтобы посмотреть что да как.
Сама валюта нормально работает с командами и предметами внутри основного мода, но когда торгую(торговля пока отдельным модом), то значение изменяется, но после перезахода в мир/смерти/добавления денег на баланс значение сбрасывается до такого которое было до торговли. При проверке "entity instanceof EntityPlayer"(это было решеним похожей проблемы) код перестаёт работать вообще.
Сама валюта нормально работает с командами и предметами внутри основного мода, но когда торгую(торговля пока отдельным модом), то значение изменяется, но после перезахода в мир/смерти/добавления денег на баланс значение сбрасывается до такого которое было до торговли. При проверке "entity instanceof EntityPlayer"(это было решеним похожей проблемы) код перестаёт работать вообще.
Код:
public class TileVendor extends TileEntity implements IInventory, ISidedInventory {
public void onBuyPressedNew(int amount) {
int totalSale = inventory[itemTradeSlot].stackSize * amount;
if (inventory[itemOutputSlot] != null
&& inventory[itemOutputSlot].stackSize + totalSale > inventory[itemTradeSlot].getMaxStackSize()) {
//buyButtonActive = false;
return;
}
if (infiniteMode) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ExtendedPlayer ep = ExtendedPlayer.get(player);
if (inventory[itemOutputSlot] == null) {
inventory[itemOutputSlot] = inventory[itemTradeSlot].copy();
inventory[itemOutputSlot].stackSize = totalSale;
if (ep.getCurrentMoney() > itemPrice) {
ep.consumeMoney(itemPrice * amount);
} else {
userCoinSum -= itemPrice * amount;
}
} else {
totalSale = Math.min(inventory[itemTradeSlot].stackSize * amount,
inventory[itemTradeSlot].getMaxStackSize() - inventory[itemOutputSlot].stackSize);
inventory[itemOutputSlot].stackSize += totalSale;
if (ep.getCurrentMoney() > itemPrice) {
ep.consumeMoney(itemPrice * amount);
} else {
userCoinSum -= itemPrice * amount;
}
}
if (infiniteMode) {
coinSum = 0;
} else {
if (ep.getCurrentMoney() > itemPrice) {
ep.consumeMoney(itemPrice * amount);
} else {
coinSum += itemPrice * amount;
}
}
} else {
// find matching item in inventory
// we need to match the item, damage, and tags to make sure the
// stacks are equal
for (int i = itemStorageSlot1; i <= itemStorageSlot9; i++) {
if (inventory[i] != null && inventory[i].getItem() == inventory[itemTradeSlot].getItem()
&& inventory[i].getItemDamage() == inventory[itemTradeSlot].getItemDamage()
&& ItemStack.areItemStackTagsEqual(inventory[i], inventory[itemTradeSlot]) && !worldObj.isRemote) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ExtendedPlayer ep = ExtendedPlayer.get(player);
// start.
if (inventory[itemOutputSlot] == null) {
inventory[itemOutputSlot] = inventory[i].copy();
inventory[itemOutputSlot].stackSize = 0;
}
int thisSale = Math.min(inventory[i].stackSize, totalSale);
inventory[itemOutputSlot].stackSize += thisSale;
inventory[i].stackSize -= thisSale;
totalSale -= thisSale;
if (ep.getCurrentMoney() > itemPrice) {
ep.consumeMoney(itemPrice * thisSale / inventory[itemTradeSlot].stackSize);
} else {
userCoinSum -= itemPrice * thisSale / inventory[itemTradeSlot].stackSize;
}
if (infiniteMode) {
coinSum = 0;
} else {
if (ep.getCurrentMoney() > itemPrice) {
ep.consumeMoney(itemPrice * thisSale / inventory[itemTradeSlot].stackSize);
} else {
coinSum += itemPrice * thisSale / inventory[itemTradeSlot].stackSize;
}
}
}
// cleanup empty stacks
if (inventory[i] == null || inventory[i].stackSize == 0) {
inventory[i] = null;
}
}
}
}
}