Skip to content

Commit

Permalink
fixed keyring and pouch containers
Browse files Browse the repository at this point in the history
if offhand is holding keyring or pouch don't use NoSlot in container.
  • Loading branch information
gottsch committed Aug 29, 2021
1 parent 60f212e commit d0498a8
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package com.someguyssoftware.treasure2.inventory;

import com.someguyssoftware.treasure2.item.KeyRingItem;
import com.someguyssoftware.treasure2.item.TreasureItems;

import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Inventory;
Expand Down Expand Up @@ -75,7 +78,8 @@ public KeyRingContainer(int windowID, ContainerType<?> containerType, PlayerInve
public void buildHotbar(PlayerInventory player) {
for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) {
int slotNumber = x;
if (slotNumber == player.selected) {
// TODO determine if the item is in left hand
if (slotNumber == player.selected && player.offhand.get(0).getItem() != TreasureItems.KEY_RING) {
addSlot(new NoSlot(player, slotNumber, getHotbarXPos() + getSlotXSpacing() * x, getHotbarYPos()));
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package com.someguyssoftware.treasure2.inventory;

import com.someguyssoftware.treasure2.item.TreasureItems;

import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Inventory;
Expand Down Expand Up @@ -79,7 +81,7 @@ public PouchContainer(int windowID, ContainerType<?> containerType, PlayerInvent
public void buildHotbar(PlayerInventory player) {
for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) {
int slotNumber = x;
if (slotNumber == player.selected) {
if (slotNumber == player.selected && player.offhand.get(0).getItem() != TreasureItems.POUCH) {
addSlot(new NoSlot(player, slotNumber, getHotbarXPos() + getSlotXSpacing() * x, getHotbarYPos()));
}
else {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/someguyssoftware/treasure2/item/CoinItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.someguyssoftware.gottschcore.spatial.Coords;
import com.someguyssoftware.gottschcore.spatial.ICoords;
import com.someguyssoftware.gottschcore.world.WorldInfo;
import com.someguyssoftware.treasure2.Treasure;
import com.someguyssoftware.treasure2.block.IWishingWellBlock;
import com.someguyssoftware.treasure2.capability.CharmableCapabilityProvider;
import com.someguyssoftware.treasure2.capability.ICharmableCapability;
Expand Down Expand Up @@ -246,7 +247,14 @@ else if (getCoin() == Coins.GOLD) {
LootPool lootPool = table.getPool(pool.getName());

// geneate loot from pools
lootPool.addRandomItems(itemStacks::add, lootContext);
// TODO https://github.com/gottsch/gottsch-minecraft-Treasure/issues/242
// lootPool is null.
if (lootPool != null) {
lootPool.addRandomItems(itemStacks::add, lootContext);
}
else {
Treasure.LOGGER.warn("loot pool -> {} is null", pool.getName());
}
}

// get effective rarity
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/someguyssoftware/treasure2/item/PouchItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,26 @@
*/
package com.someguyssoftware.treasure2.item;

import static com.someguyssoftware.treasure2.capability.TreasureCapabilities.*;

import java.util.List;
import java.util.Optional;

import javax.annotation.Nullable;

import com.someguyssoftware.gottschcore.item.ModItem;
import com.someguyssoftware.gottschcore.world.WorldInfo;
import com.someguyssoftware.treasure2.Treasure;
import com.someguyssoftware.treasure2.capability.ICharmableCapability;
import com.someguyssoftware.treasure2.capability.PouchCapabilityProvider;
import com.someguyssoftware.treasure2.capability.CharmableCapability.InventoryType;
import com.someguyssoftware.treasure2.charm.Charm;
import com.someguyssoftware.treasure2.charm.ICharm;
import com.someguyssoftware.treasure2.charm.ICharmEntity;
import com.someguyssoftware.treasure2.inventory.PouchContainer;
import com.someguyssoftware.treasure2.inventory.PouchInventory;
import com.someguyssoftware.treasure2.inventory.TreasureContainers;
import com.someguyssoftware.treasure2.util.ModUtils;

import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -38,6 +49,7 @@
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
Expand All @@ -47,6 +59,7 @@
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.IItemHandler;

/**
* @author Mark Gottschling on May 13, 2020
Expand Down Expand Up @@ -110,4 +123,35 @@ public Container createMenu(int windowID, PlayerInventory inventory, PlayerEntit
public ITextComponent getDisplayName() {
return new TranslationTextComponent("item.treasure2.pouch");
}

////////////////////////
/**
* NOTE getShareTag() and readShareTag() are required to sync item capabilities server -> client. I needed this when holding charms in hands and then swapping hands.
*/
@Override
public CompoundNBT getShareTag(ItemStack stack) {
CompoundNBT nbt = stack.getOrCreateTag();
IItemHandler cap = stack.getCapability(POUCH_CAPABILITY).orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!"));

try {

} catch (Exception e) {
Treasure.LOGGER.error("Unable to write state to NBT:", e);
}
return nbt;
}

@Override
public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) {
super.readShareTag(stack, nbt);

if (nbt instanceof CompoundNBT) {
IItemHandler cap = stack.getCapability(POUCH_CAPABILITY).orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!"));

CompoundNBT tag = (CompoundNBT) nbt;

}
}
}


2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Base API for all my mods.
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[1.3,)" #mandatory
versionRange="[1.4,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="BEFORE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
Expand Down
2 changes: 1 addition & 1 deletion update.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"1.0.1": "Fixed Ticking block entity on Bound Soul crash.\nFixed missing Loot Table error (for test.json).",
"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",
"1.5.1": "Fixed java.lang.NullPointerException: Initializing game at net.minecraft.item.Item.handler$zpo000$getDisplayName(Item.java:526) ~[?:?]",
"1.6.0": "Charms"
"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"
}
}

0 comments on commit d0498a8

Please sign in to comment.