Skip to content

Commit

Permalink
Fixed Tackle Box main inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Dec 17, 2023
1 parent 9304ea1 commit 2bf43c4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void addItemsToTabs(BuildCreativeModeTabContentsEvent event) {
}

public void registerCapabilities(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, AquaBlockEntities.TACKLE_BOX.get(), (blockEntity, side) -> TackleBoxBlockEntity.createItemHandler(blockEntity));
event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, AquaBlockEntities.TACKLE_BOX.get(), (blockEntity, side) -> blockEntity.handler);
//event.registerItem(Capabilities.ItemHandler.ITEM, (stack, context) -> AquaFishingRodItem.getHandler(stack), AquaItems.IRON_FISHING_ROD, AquaItems.GOLD_FISHING_ROD, AquaItems.DIAMOND_FISHING_ROD, AquaItems.NEPTUNIUM_FISHING_ROD);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class AquacultureAPI {
* Reference to Aquaculture's materials
**/
public static AquaMats MATS = new AquaMats();

/**
* Reference to setting weight for fish
**/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package com.teammetallurgy.aquaculture.block.blockentity;

import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Nameable;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.common.util.INBTSerializable;
import net.neoforged.neoforge.items.IItemHandler;

import javax.annotation.Nonnull;

public abstract class IItemHandlerBEBase extends BlockEntity implements Nameable { //TODO Reimplement Capabilities
public abstract class IItemHandlerBEBase extends BlockEntity implements Nameable {
private Component customName;
public final IItemHandler handler = createItemHandler();

public IItemHandlerBEBase(BlockEntityType<?> tileEntityType, BlockPos pos, BlockState state) {
super(tileEntityType, pos, state);
}

@Nonnull
protected abstract IItemHandler createItemHandler();

@Override
public void load(@Nonnull CompoundTag tag) {
CompoundTag invTag = tag.getCompound("inv");
((INBTSerializable<CompoundTag>) handler).deserializeNBT(invTag);
if (tag.contains("CustomName", 8)) {
this.customName = Component.Serializer.fromJson(tag.getString("CustomName"));
}
Expand All @@ -28,6 +35,10 @@ public void load(@Nonnull CompoundTag tag) {

@Override
public void saveAdditional(@Nonnull CompoundTag tag) {
CompoundTag compound = ((INBTSerializable<CompoundTag>) handler).serializeNBT();
if (compound != null) {
tag.put("inv", compound);
}
if (this.customName != null) {
tag.putString("CustomName", Component.Serializer.toJson(this.customName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,19 @@ protected boolean isOwnContainer(Player player) {
}
};
private final ChestLidController lidController = new ChestLidController();
public static final BlockCapability<IItemHandler, Direction> ITEM_HANDLER_BLOCK =
BlockCapability.createSided(new ResourceLocation(Aquaculture.MOD_ID, "tackle_box_item_handler"), IItemHandler.class);

public TackleBoxBlockEntity(BlockPos pos, BlockState state) {
super(AquaBlockEntities.TACKLE_BOX.get(), pos, state);
}

@Override
@Nonnull
public static IItemHandler createItemHandler(BlockEntity blockEntity) {
protected IItemHandler createItemHandler() {
return new ItemStackHandler(17) {
@Override
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
blockEntity.setChanged();
TackleBoxBlockEntity.this.setChanged();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ public TackleBoxScreen(TackleBoxContainer tackleBoxContainer, Inventory playerIn
@Override
public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.render(guiGraphics, mouseX, mouseY, partialTicks);
this.renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
this.renderTooltip(guiGraphics, mouseX, mouseY);
}

@Override
protected void renderLabels(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY) {
guiGraphics.drawString(this.font, this.title, 100, 6, 4210752);
guiGraphics.drawString(this.font, this.playerInventoryTitle, 8, (this.imageHeight - 96 + 4), 4210752);
guiGraphics.drawString(this.font, this.title, 100, 6, 4210752, false);
guiGraphics.drawString(this.font, this.playerInventoryTitle, 8, (this.imageHeight - 96 + 4), 4210752, false);
}

@Override
protected void renderBg(@Nonnull GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

int x = (this.width - this.imageWidth) / 2;
int y = (this.height - this.imageHeight) / 2;
guiGraphics.blit(TACKLE_BOX_GUI, x, y, 0, 0, this.imageWidth, this.imageHeight);
Expand Down

0 comments on commit 2bf43c4

Please sign in to comment.