Skip to content

Commit

Permalink
Fix some camp tick issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ataranlen committed Dec 31, 2016
1 parent dcc74a8 commit 2ec7266
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 22 deletions.
Binary file modified civcraft/bin/com/avrgaming/civcraft/camp/Camp.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified civcraft/bin/com/avrgaming/civcraft/util/MultiInventory.class
Binary file not shown.
2 changes: 1 addition & 1 deletion civcraft/bin/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CivCraft
main: com.avrgaming.civcraft.main.CivCraft
softdepends: [TitleAPI]
version: 1.8.0-Beta3
version: 1.8.0-Beta4
depend: [CustomMobs]

commands:
Expand Down
6 changes: 3 additions & 3 deletions civcraft/src/com/avrgaming/civcraft/camp/Camp.java
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public void processFirepoints() {

if (mInv.contains(null, CivData.COAL, (short)0, coal_per_firepoint)) {
try {
mInv.removeItem(CivData.COAL, coal_per_firepoint);
mInv.removeItem(CivData.COAL, coal_per_firepoint, true);
} catch (CivException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -706,7 +706,7 @@ public void processLonghouse() {
}

this.consumeComponent.setSource(mInv);
Result result = this.consumeComponent.processConsumption();
Result result = this.consumeComponent.processConsumption(true);
this.consumeComponent.onSave();

switch (result) {
Expand Down Expand Up @@ -749,7 +749,7 @@ public void processLonghouse() {
attrs.addLore(CivColor.LightGray+res.getName());
token = attrs.getStack();

mInv.addItemStack(token);
mInv.addItems(token, true);
}

String stateMessage = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private boolean hasEnoughToConsume() {
return found;
}

private void consumeFromInventory() {
private void consumeFromInventory(Boolean sync) {
if (foundCounts == null) {
return;
}
Expand Down Expand Up @@ -349,35 +349,37 @@ private void consumeFromInventory() {
int totalBaseConsumed = totalBase - leftOverBase;

try {
source.removeItem(ee.altType, totalAltConsumed);
source.removeItem(ee.altType, totalAltConsumed, sync);
} catch (CivException e) {
e.printStackTrace();
}
if (totalBaseConsumed > 0) {
try {
source.removeItem(ee.baseType, totalBaseConsumed);
source.removeItem(ee.baseType, totalBaseConsumed, sync);
} catch (CivException e) {
e.printStackTrace();
}
} else {
if (totalBaseConsumed != 0) {
/* If the total amount consumed is negative, add it to the inventory. */
source.addItemStack(ItemManager.createItemStack(ee.baseType, (-1*totalBaseConsumed)));
source.addItems(ItemManager.createItemStack(ee.baseType, (-1*totalBaseConsumed)), sync);
}
}
}
} else {
/* We had enough of our base item, consume it. */
try {
source.removeItem(typeID, getConsumedAmount(amount));
source.removeItem(typeID, getConsumedAmount(amount), sync);
} catch (CivException e) {
e.printStackTrace();
}
}
}
}

public Result processConsumption() {
return processConsumption(false);
}
public Result processConsumption(Boolean sync) {

Integer currentCountMax = levelCounts.get(this.level);
if (currentCountMax == null) {
Expand All @@ -387,7 +389,7 @@ public Result processConsumption() {
}

if (hasEnoughToConsume()) {
consumeFromInventory();
consumeFromInventory(sync);

if ((this.count+1) >= currentCountMax) {
// Level up?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ public void onPlayerFish (PlayerFishEvent event) {
CivMessage.send(event.getPlayer(), CivColor.LightGreen+CivSettings.localize.localizedString("var_fishing_success",CivColor.LightPurple+craftMat.getName()));
}
}

HashMap<Integer, ItemStack> leftovers = player.getInventory().addItem(stack);
for (ItemStack is : leftovers.values()) {
player.getWorld().dropItem(player.getLocation(), is);
if (stack != null) {
HashMap<Integer, ItemStack> leftovers = player.getInventory().addItem(stack);
for (ItemStack is : leftovers.values()) {
player.getWorld().dropItem(player.getLocation(), is);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void run() {
if (breadCount > 0) {
/* bread seed */
try {
source_inv.removeItem(CivData.BREAD_SEED, 1);
source_inv.removeItem(CivData.BREAD_SEED, 1, true);
} catch (CivException e) {
e.printStackTrace();
}
Expand All @@ -73,7 +73,7 @@ public void run() {
if (carrotCount > 0) {
/* carrots */
try {
source_inv.removeItem(CivData.CARROT_ITEM, 1);
source_inv.removeItem(CivData.CARROT_ITEM, 1, true);
} catch (CivException e) {
e.printStackTrace();
}
Expand All @@ -88,7 +88,7 @@ public void run() {
if (potatoCount > 0) {
/* potatoes */
try {
source_inv.removeItem(CivData.POTATO_ITEM, 1);
source_inv.removeItem(CivData.POTATO_ITEM, 1, true);
} catch (CivException e) {
e.printStackTrace();
}
Expand All @@ -104,7 +104,7 @@ public void run() {
if (breadCount > 0) {
/* bread seed */
try {
source_inv.removeItem(CivData.BREAD_SEED, 1);
source_inv.removeItem(CivData.BREAD_SEED, 1, true);
} catch (CivException e) {
e.printStackTrace();
}
Expand All @@ -117,7 +117,7 @@ public void run() {
if (carrotCount > 0) {
/* carrots */
try {
source_inv.removeItem(CivData.CARROT_ITEM, 1);
source_inv.removeItem(CivData.CARROT_ITEM, 1, true);
} catch (CivException e) {
e.printStackTrace();
}
Expand All @@ -130,7 +130,7 @@ public void run() {
if (potatoCount > 0) {
/* potatoes */
try {
source_inv.removeItem(CivData.POTATO_ITEM, 1);
source_inv.removeItem(CivData.POTATO_ITEM, 1, true);
} catch (CivException e) {
e.printStackTrace();
}
Expand Down
12 changes: 12 additions & 0 deletions civcraft/src/com/avrgaming/civcraft/util/MultiInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ public void addInventory (DoubleChestInventory inv) {
invs.add(inv.getRightSide());
}

public void addItems(ItemStack items, Boolean sync) {
if (sync) {
addItem(items);
} else {
addItemStack(items);
}
}

public void addItemStack(ItemStack items) {
this.updateInventory(items, Action.ADD);
}
Expand Down Expand Up @@ -273,6 +281,10 @@ public boolean removeItem(ItemStack item, Boolean direct) throws CivException {
}
}

public boolean removeItem(int typeid, int amount, Boolean sync) throws CivException {
return removeItem(null, typeid, (short)0, amount, sync);
}

public boolean removeItem(int typeid, int amount) throws CivException {
return removeItem(null, typeid, (short)0, amount, false);
}
Expand Down
2 changes: 1 addition & 1 deletion civcraft/src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CivCraft
main: com.avrgaming.civcraft.main.CivCraft
softdepends: [TitleAPI]
version: 1.8.0-Beta3
version: 1.8.0-Beta4
depend: [CustomMobs]

commands:
Expand Down

0 comments on commit 2ec7266

Please sign in to comment.