Skip to content

Commit

Permalink
Fixed Tackle Box inventory not saving
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Dec 2, 2021
1 parent 3884790 commit a40fbed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Hook(String name, String modID, ChatFormatting color, int minCatchable,
this.texture = new ResourceLocation(modID, "textures/entity/rod/hook/" + name + "_hook" + ".png");
if (name != null) {
this.hookItem = new HookItem(this).setRegistryName(new ResourceLocation(modID, name + "_hook"));
ForgeRegistries.ITEMS.register(this.hookItem); //TODO Move to DeferredRegistry in 1.18
ForgeRegistries.ITEMS.register(this.hookItem);
HOOKS.put(name, hookItem);
} else {
this.hookItem = Items.AIR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public abstract class IItemHandlerTEBase extends BlockEntity implements Nameable {
private Component customName;
private final LazyOptional<IItemHandler> handler = LazyOptional.of(this::createItemHandler);
private LazyOptional<IItemHandler> handler = LazyOptional.of(this::createItemHandler);

public IItemHandlerTEBase(BlockEntityType<?> tileEntityType, BlockPos pos, BlockState state) {
super(tileEntityType, pos, state);
Expand All @@ -31,7 +31,6 @@ public IItemHandlerTEBase(BlockEntityType<?> tileEntityType, BlockPos pos, Block

@Override
public void load(@Nonnull CompoundTag tag) {
System.out.println("Load");
CompoundTag invTag = tag.getCompound("inv");
this.handler.ifPresent(stack -> ((INBTSerializable<CompoundTag>) stack).deserializeNBT(invTag));
if (tag.contains("CustomName", 8)) {
Expand Down Expand Up @@ -61,6 +60,18 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
return super.getCapability(cap, side);
}

@Override
public void invalidateCaps() {
super.invalidateCaps();
this.handler.invalidate();
}

@Override
public void reviveCaps() {
super.reviveCaps();
this.handler = LazyOptional.of(this::createItemHandler);
}

@Override
@Nonnull
public Component getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public TackleBoxTileEntity(BlockPos pos, BlockState state) {
@Override
@Nonnull
protected IItemHandler createItemHandler() {
return new ItemStackHandler(17);
return new ItemStackHandler(17) {
@Override
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
setChanged();
}
};
}

@Nullable
Expand Down

0 comments on commit a40fbed

Please sign in to comment.