Skip to content

Commit d0498a8

Browse files
committed
fixed keyring and pouch containers
if offhand is holding keyring or pouch don't use NoSlot in container.
1 parent 60f212e commit d0498a8

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed

src/main/java/com/someguyssoftware/treasure2/inventory/KeyRingContainer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020
package com.someguyssoftware.treasure2.inventory;
2121

22+
import com.someguyssoftware.treasure2.item.KeyRingItem;
23+
import com.someguyssoftware.treasure2.item.TreasureItems;
24+
2225
import net.minecraft.entity.player.PlayerInventory;
2326
import net.minecraft.inventory.IInventory;
2427
import net.minecraft.inventory.Inventory;
@@ -75,7 +78,8 @@ public KeyRingContainer(int windowID, ContainerType<?> containerType, PlayerInve
7578
public void buildHotbar(PlayerInventory player) {
7679
for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) {
7780
int slotNumber = x;
78-
if (slotNumber == player.selected) {
81+
// TODO determine if the item is in left hand
82+
if (slotNumber == player.selected && player.offhand.get(0).getItem() != TreasureItems.KEY_RING) {
7983
addSlot(new NoSlot(player, slotNumber, getHotbarXPos() + getSlotXSpacing() * x, getHotbarYPos()));
8084
}
8185
else {

src/main/java/com/someguyssoftware/treasure2/inventory/PouchContainer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package com.someguyssoftware.treasure2.inventory;
2121

22+
import com.someguyssoftware.treasure2.item.TreasureItems;
23+
2224
import net.minecraft.entity.player.PlayerInventory;
2325
import net.minecraft.inventory.IInventory;
2426
import net.minecraft.inventory.Inventory;
@@ -79,7 +81,7 @@ public PouchContainer(int windowID, ContainerType<?> containerType, PlayerInvent
7981
public void buildHotbar(PlayerInventory player) {
8082
for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) {
8183
int slotNumber = x;
82-
if (slotNumber == player.selected) {
84+
if (slotNumber == player.selected && player.offhand.get(0).getItem() != TreasureItems.POUCH) {
8385
addSlot(new NoSlot(player, slotNumber, getHotbarXPos() + getSlotXSpacing() * x, getHotbarYPos()));
8486
}
8587
else {

src/main/java/com/someguyssoftware/treasure2/item/CoinItem.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.someguyssoftware.gottschcore.spatial.Coords;
1919
import com.someguyssoftware.gottschcore.spatial.ICoords;
2020
import com.someguyssoftware.gottschcore.world.WorldInfo;
21+
import com.someguyssoftware.treasure2.Treasure;
2122
import com.someguyssoftware.treasure2.block.IWishingWellBlock;
2223
import com.someguyssoftware.treasure2.capability.CharmableCapabilityProvider;
2324
import com.someguyssoftware.treasure2.capability.ICharmableCapability;
@@ -246,7 +247,14 @@ else if (getCoin() == Coins.GOLD) {
246247
LootPool lootPool = table.getPool(pool.getName());
247248

248249
// geneate loot from pools
249-
lootPool.addRandomItems(itemStacks::add, lootContext);
250+
// TODO https://github.com/gottsch/gottsch-minecraft-Treasure/issues/242
251+
// lootPool is null.
252+
if (lootPool != null) {
253+
lootPool.addRandomItems(itemStacks::add, lootContext);
254+
}
255+
else {
256+
Treasure.LOGGER.warn("loot pool -> {} is null", pool.getName());
257+
}
250258
}
251259

252260
// get effective rarity

src/main/java/com/someguyssoftware/treasure2/item/PouchItem.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,26 @@
1919
*/
2020
package com.someguyssoftware.treasure2.item;
2121

22+
import static com.someguyssoftware.treasure2.capability.TreasureCapabilities.*;
23+
2224
import java.util.List;
25+
import java.util.Optional;
26+
27+
import javax.annotation.Nullable;
2328

2429
import com.someguyssoftware.gottschcore.item.ModItem;
2530
import com.someguyssoftware.gottschcore.world.WorldInfo;
2631
import com.someguyssoftware.treasure2.Treasure;
32+
import com.someguyssoftware.treasure2.capability.ICharmableCapability;
2733
import com.someguyssoftware.treasure2.capability.PouchCapabilityProvider;
34+
import com.someguyssoftware.treasure2.capability.CharmableCapability.InventoryType;
35+
import com.someguyssoftware.treasure2.charm.Charm;
36+
import com.someguyssoftware.treasure2.charm.ICharm;
37+
import com.someguyssoftware.treasure2.charm.ICharmEntity;
2838
import com.someguyssoftware.treasure2.inventory.PouchContainer;
2939
import com.someguyssoftware.treasure2.inventory.PouchInventory;
3040
import com.someguyssoftware.treasure2.inventory.TreasureContainers;
41+
import com.someguyssoftware.treasure2.util.ModUtils;
3142

3243
import net.minecraft.client.util.ITooltipFlag;
3344
import net.minecraft.entity.player.PlayerEntity;
@@ -38,6 +49,7 @@
3849
import net.minecraft.inventory.container.INamedContainerProvider;
3950
import net.minecraft.item.ItemStack;
4051
import net.minecraft.nbt.CompoundNBT;
52+
import net.minecraft.nbt.ListNBT;
4153
import net.minecraft.util.ActionResult;
4254
import net.minecraft.util.ActionResultType;
4355
import net.minecraft.util.Hand;
@@ -47,6 +59,7 @@
4759
import net.minecraft.world.World;
4860
import net.minecraftforge.common.capabilities.ICapabilityProvider;
4961
import net.minecraftforge.fml.network.NetworkHooks;
62+
import net.minecraftforge.items.IItemHandler;
5063

5164
/**
5265
* @author Mark Gottschling on May 13, 2020
@@ -110,4 +123,35 @@ public Container createMenu(int windowID, PlayerInventory inventory, PlayerEntit
110123
public ITextComponent getDisplayName() {
111124
return new TranslationTextComponent("item.treasure2.pouch");
112125
}
126+
127+
////////////////////////
128+
/**
129+
* NOTE getShareTag() and readShareTag() are required to sync item capabilities server -> client. I needed this when holding charms in hands and then swapping hands.
130+
*/
131+
@Override
132+
public CompoundNBT getShareTag(ItemStack stack) {
133+
CompoundNBT nbt = stack.getOrCreateTag();
134+
IItemHandler cap = stack.getCapability(POUCH_CAPABILITY).orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!"));
135+
136+
try {
137+
138+
} catch (Exception e) {
139+
Treasure.LOGGER.error("Unable to write state to NBT:", e);
140+
}
141+
return nbt;
142+
}
143+
144+
@Override
145+
public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) {
146+
super.readShareTag(stack, nbt);
147+
148+
if (nbt instanceof CompoundNBT) {
149+
IItemHandler cap = stack.getCapability(POUCH_CAPABILITY).orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!"));
150+
151+
CompoundNBT tag = (CompoundNBT) nbt;
152+
153+
}
154+
}
113155
}
156+
157+

src/main/resources/META-INF/mods.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Base API for all my mods.
6868
# Does this dependency have to exist - if not, ordering below must be specified
6969
mandatory=true #mandatory
7070
# The version range of the dependency
71-
versionRange="[1.3,)" #mandatory
71+
versionRange="[1.4,)" #mandatory
7272
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
7373
ordering="BEFORE"
7474
# Side this dependency is applied on - BOTH, CLIENT or SERVER

update.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"1.0.1": "Fixed Ticking block entity on Bound Soul crash.\nFixed missing Loot Table error (for test.json).",
1010
"1.5.0": "Added mist - Gravestones, Bound Souls, and Wither Tree's poison and wither mist.\nAdded Key Ring.\nAdded key merging ability.\nAdded treasure maps to other Treasure chests.\nUpdated bounding boxes of gravestones.\nFixed Well and Wither Tree regitries.\nAttempt to fix LockItem.appendHoverText initialization crash with some performance mods.\nUses Forge-36.2.0",
1111
"1.5.1": "Fixed java.lang.NullPointerException: Initializing game at net.minecraft.item.Item.handler$zpo000$getDisplayName(Item.java:526) ~[?:?]",
12-
"1.6.0": "Charms"
12+
"1.6.0": "Added Charms (except Harvesting).\nAdded Pouch Item.(standard only, Lucks, Apprentice and Master will not be added).\nUses GottschCore 1.4.0 which fixes crash bug on mob spawn by ProximitySpawner.\nPrevent crashes when coins thrown in wells has an exception.\n"
1313
}
1414
}

0 commit comments

Comments
 (0)