diff --git a/gradle.properties b/gradle.properties index 0cc7f0d19..fb28e21b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ loader_version_range=[4,) mod_id=sophisticatedstorage mod_name=Sophisticated Storage mod_license=GNU General Public License v3.0 -mod_version=1.0.2 +mod_version=1.0.3 mod_group_id=sophisticatedstorage mod_authors=P3pp3rF1y, Ridanisaurus mod_description=Fancy and functional storage containers. @@ -35,7 +35,7 @@ jade_cf_file_id=5109393 chipped_cf_file_id=5506938 resourcefullib_cf_file_id=5483169 athena_cf_file_id=5431579 -sc_version=[1.21.1-1.0.0,1.22) +sc_version=[1.21.1-1.0.4,1.22) sb_version=[1.21,1.22) #publish diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/BarrelBlockEntity.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/BarrelBlockEntity.java index aaad57631..a8df529a8 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/BarrelBlockEntity.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/BarrelBlockEntity.java @@ -68,6 +68,10 @@ protected BarrelBlockEntity(BlockPos pos, BlockState state, BlockEntityType { - be.getStorageWrapper().load(level.registryAccess(), mainBe.getStorageWrapper().save(new CompoundTag())); + be.getStorageWrapper().load(mainBe.getStorageWrapper().save(new CompoundTag())); //remove main chest contents CompoundTag contentsTag = new CompoundTag(); contentsTag.put(StorageWrapper.CONTENTS_TAG, new CompoundTag()); - mainBe.getStorageWrapper().load(level.registryAccess(), contentsTag); + mainBe.getStorageWrapper().load(contentsTag); }); } }); diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/LimitedBarrelBlock.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/LimitedBarrelBlock.java index 2aa7df5c0..b638779de 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/LimitedBarrelBlock.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/LimitedBarrelBlock.java @@ -26,6 +26,7 @@ import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; +import net.p3pp3rf1y.sophisticatedcore.api.IStorageWrapper; import net.p3pp3rf1y.sophisticatedcore.renderdata.RenderInfo; import net.p3pp3rf1y.sophisticatedcore.settings.SettingsHandler; import net.p3pp3rf1y.sophisticatedcore.settings.itemdisplay.ItemDisplaySettingsCategory; @@ -256,13 +257,14 @@ public boolean isLookingAtFront(Player player, BlockPos pos, BlockState state) { public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { super.setPlacedBy(level, pos, state, placer, stack); - WorldHelper.getBlockEntity(level, pos, LimitedBarrelBlockEntity.class).ifPresent(be -> { - StorageWrapper storageWrapper = be.getStorageWrapper(); - SettingsHandler settingsHandler = storageWrapper.getSettingsHandler(); - settingsHandler.getTypeCategory(ItemDisplaySettingsCategory.class).selectSlots(0, storageWrapper.getNumberOfInventorySlots()); - settingsHandler.getTypeCategory(NoSortSettingsCategory.class).selectSlots(0, storageWrapper.getNumberOfInventorySlots()); - settingsHandler.getTypeCategory(MemorySettingsCategory.class).setIgnoreNbt(false); - }); + WorldHelper.getBlockEntity(level, pos, LimitedBarrelBlockEntity.class).ifPresent(be -> setupDefaultSettings(be.getStorageWrapper(), be.getStorageWrapper().getNumberOfInventorySlots())); + } + + public static void setupDefaultSettings(IStorageWrapper storageWrapper, int numberOfInventorySlots) { + SettingsHandler settingsHandler = storageWrapper.getSettingsHandler(); + settingsHandler.getTypeCategory(ItemDisplaySettingsCategory.class).selectSlots(0, numberOfInventorySlots); + settingsHandler.getTypeCategory(NoSortSettingsCategory.class).selectSlots(0, numberOfInventorySlots); + settingsHandler.getTypeCategory(MemorySettingsCategory.class).setIgnoreNbt(false); } @Override diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/LimitedBarrelBlockEntity.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/LimitedBarrelBlockEntity.java index 70c933a97..92602d573 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/LimitedBarrelBlockEntity.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/LimitedBarrelBlockEntity.java @@ -24,7 +24,7 @@ public class LimitedBarrelBlockEntity extends BarrelBlockEntity implements ICountDisplay, IFillLevelDisplay { private static final String SLOT_COUNTS_TAG = "slotCounts"; private static final String SLOT_FILL_LEVELS_TAG = "slotFillLevels"; - private static final Consumer VOID_UPGRADE_VOIDING_OVERFLOW_OF_EVERYTHING_BY_DEFAULT = voidUpgrade -> { + public static final Consumer VOID_UPGRADE_VOIDING_OVERFLOW_OF_EVERYTHING_BY_DEFAULT = voidUpgrade -> { voidUpgrade.getFilterLogic().setAllowByDefault(false); voidUpgrade.setShouldVoidOverflowDefaultOrLoadFromNbt(true); }; diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageBlockEntity.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageBlockEntity.java index dc82ad97d..f454b6f75 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageBlockEntity.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageBlockEntity.java @@ -259,7 +259,7 @@ public void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) { } private void loadStorageWrapper(CompoundTag tag, HolderLookup.Provider registries) { - NBTHelper.getCompound(tag, STORAGE_WRAPPER_TAG).ifPresent(wrapperTag -> storageWrapper.load(registries, wrapperTag)); + NBTHelper.getCompound(tag, STORAGE_WRAPPER_TAG).ifPresent(storageWrapper::load); } @Override @@ -308,7 +308,7 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() { @Override public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider registries) { CompoundTag tag = pkt.getTag(); - if (tag == null) { + if (tag.isEmpty()) { return; } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageWrapper.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageWrapper.java index f78894c9e..cdee798be 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageWrapper.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageWrapper.java @@ -1,6 +1,5 @@ package net.p3pp3rf1y.sophisticatedstorage.block; -import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; @@ -53,20 +52,21 @@ public abstract class StorageWrapper implements IStorageWrapper { private CompoundTag settingsNbt = new CompoundTag(); private final SettingsHandler settingsHandler; private final RenderInfo renderInfo; + private CompoundTag renderInfoNbt = new CompoundTag(); @Nullable protected UUID contentsUuid = null; private int openTabId = -1; - protected int numberOfInventorySlots = 0; + protected int numberOfInventorySlots = 0; protected int numberOfUpgradeSlots = -1; + private SortBy sortBy = SortBy.NAME; private int columnsTaken = 0; private int mainColor = -1; private int accentColor = -1; - private Runnable upgradeCachesInvalidatedHandler = () -> { }; @@ -191,9 +191,9 @@ CompoundTag saveData(CompoundTag tag) { return tag; } - public void load(HolderLookup.Provider registries, CompoundTag tag) { + public void load(CompoundTag tag) { loadContents(tag); - loadData(registries, tag); + loadData(tag); initInventoryHandler(); getUpgradeHandler().refreshUpgradeWrappers(); @@ -202,11 +202,11 @@ public void load(HolderLookup.Provider registries, CompoundTag tag) { } } - private void loadData(HolderLookup.Provider registries, CompoundTag tag) { + private void loadData(CompoundTag tag) { settingsNbt = tag.getCompound("settings"); settingsHandler.reloadFrom(settingsNbt); renderInfoNbt = tag.getCompound("renderInfo"); - renderInfo.deserializeFrom(registries, renderInfoNbt); + renderInfo.deserializeFrom(renderInfoNbt); contentsUuid = NBTHelper.getTagValue(tag, UUID_TAG, CompoundTag::get).map(NbtUtils::loadUUID).orElse(null); openTabId = NBTHelper.getInt(tag, OPEN_TAB_ID_TAG).orElse(-1); sortBy = NBTHelper.getString(tag, "sortBy").map(SortBy::fromName).orElse(SortBy.NAME); @@ -229,7 +229,7 @@ private void loadContents(CompoundTag tag) { } @Override - public void setSaveHandler(Runnable saveHandler) { + public void setContentsChangeHandler(Runnable contentsChangeHandler) { //noop } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/gui/LimitedBarrelScreen.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/gui/LimitedBarrelScreen.java index 9900a746f..b55a0978f 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/gui/LimitedBarrelScreen.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/gui/LimitedBarrelScreen.java @@ -1,5 +1,6 @@ package net.p3pp3rf1y.sophisticatedstorage.client.gui; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; @@ -11,9 +12,12 @@ import net.p3pp3rf1y.sophisticatedcore.client.gui.utils.GuiHelper; import net.p3pp3rf1y.sophisticatedcore.client.gui.utils.TextureBlitData; import net.p3pp3rf1y.sophisticatedcore.client.gui.utils.UV; +import net.p3pp3rf1y.sophisticatedcore.common.gui.StorageContainerMenuBase; import net.p3pp3rf1y.sophisticatedstorage.SophisticatedStorage; import net.p3pp3rf1y.sophisticatedstorage.common.gui.StorageContainerMenu; +import java.util.function.IntFunction; + public class LimitedBarrelScreen extends StorageScreen { public static final ResourceLocation GUI_BACKGROUNDS = SophisticatedStorage.getRL("textures/gui/limited_barrels.png"); public static final TextureBlitData LIMITED_I_BACKGROUND = new TextureBlitData(GUI_BACKGROUNDS, Dimension.SQUARE_256, new UV(0, 0), new Dimension(84, 82)); @@ -42,22 +46,27 @@ public static void drawSlotBg(AbstractContainerScreen screen, GuiGraphics gui @Override protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderLabels(guiGraphics, mouseX, mouseY); - switch (getMenu().getNumberOfStorageInventorySlots()) { - case 1 -> renderBar(guiGraphics, imageWidth / 2 + 37, 18 + 6, getMenu().getSlotFillPercentage(0), LARGE_BAR_FILL, false); + renderBars(font, imageWidth, getMenu(), guiGraphics, getMenu()::getSlotFillPercentage); + } + + public static void renderBars(Font font, int imageWidth, StorageContainerMenuBase menu, GuiGraphics guiGraphics, IntFunction getSlotFillPercentage) { + switch (menu.getNumberOfStorageInventorySlots()) { + case 1 -> + renderBar(font, guiGraphics, imageWidth / 2 + 37, 18 + 6, getSlotFillPercentage.apply(0), LARGE_BAR_FILL, false); case 2 -> { - renderBar(guiGraphics, imageWidth / 2 + 37, 18 + 6, getMenu().getSlotFillPercentage(0), SMALL_BAR_FILL, false); - renderBar(guiGraphics, imageWidth / 2 + 37, 18 + 6 + 40, getMenu().getSlotFillPercentage(1), SMALL_BAR_FILL, false); + renderBar(font, guiGraphics, imageWidth / 2 + 37, 18 + 6, getSlotFillPercentage.apply(0), SMALL_BAR_FILL, false); + renderBar(font, guiGraphics, imageWidth / 2 + 37, 18 + 6 + 40, getSlotFillPercentage.apply(1), SMALL_BAR_FILL, false); } case 3 -> { - renderBar(guiGraphics, imageWidth / 2 + 37, 18 + 6, getMenu().getSlotFillPercentage(0), SMALL_BAR_FILL, false); - renderBar(guiGraphics, imageWidth / 2 - 37 - 5, 18 + 6 + 40, getMenu().getSlotFillPercentage(1), SMALL_BAR_FILL, true); - renderBar(guiGraphics, imageWidth / 2 + 37, 18 + 6 + 40, getMenu().getSlotFillPercentage(2), SMALL_BAR_FILL, false); + renderBar(font, guiGraphics, imageWidth / 2 + 37, 18 + 6, getSlotFillPercentage.apply(0), SMALL_BAR_FILL, false); + renderBar(font, guiGraphics, imageWidth / 2 - 37 - 5, 18 + 6 + 40, getSlotFillPercentage.apply(1), SMALL_BAR_FILL, true); + renderBar(font, guiGraphics, imageWidth / 2 + 37, 18 + 6 + 40, getSlotFillPercentage.apply(2), SMALL_BAR_FILL, false); } case 4 -> { - renderBar(guiGraphics, imageWidth / 2 - 37 - 5, 18 + 6, getMenu().getSlotFillPercentage(0), SMALL_BAR_FILL, true); - renderBar(guiGraphics, imageWidth / 2 + 37, 18 + 6, getMenu().getSlotFillPercentage(1), SMALL_BAR_FILL, false); - renderBar(guiGraphics, imageWidth / 2 - 37 - 5, 18 + 6 + 40, getMenu().getSlotFillPercentage(2), SMALL_BAR_FILL, true); - renderBar(guiGraphics, imageWidth / 2 + 37, 18 + 6 + 40, getMenu().getSlotFillPercentage(3), SMALL_BAR_FILL, false); + renderBar(font, guiGraphics, imageWidth / 2 - 37 - 5, 18 + 6, getSlotFillPercentage.apply(0), SMALL_BAR_FILL, true); + renderBar(font, guiGraphics, imageWidth / 2 + 37, 18 + 6, getSlotFillPercentage.apply(1), SMALL_BAR_FILL, false); + renderBar(font, guiGraphics, imageWidth / 2 - 37 - 5, 18 + 6 + 40, getSlotFillPercentage.apply(2), SMALL_BAR_FILL, true); + renderBar(font, guiGraphics, imageWidth / 2 + 37, 18 + 6 + 40, getSlotFillPercentage.apply(3), SMALL_BAR_FILL, false); } } } @@ -127,7 +136,7 @@ public static void updateSlotPositions(AbstractContainerMenu menu, int slotNumbe } } - private void renderBar(GuiGraphics guiGraphics, int x, int y, float percentage, TextureBlitData barTexture, boolean left) { + private static void renderBar(Font font, GuiGraphics guiGraphics, int x, int y, float percentage, TextureBlitData barTexture, boolean left) { int barHeight = (int) (barTexture.getHeight() * percentage); int yOffset = barTexture.getHeight() - barHeight; @@ -136,7 +145,7 @@ private void renderBar(GuiGraphics guiGraphics, int x, int y, float percentage, String text = (int) (percentage * 100) + "%"; int percentageX = x; if (left) { - percentageX -= 2 + minecraft.font.width(text); + percentageX -= 2 + font.width(text); } else { percentageX += 6; } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/BarrelBakedModelBase.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/BarrelBakedModelBase.java index 3c3629c5c..0fd372992 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/BarrelBakedModelBase.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/BarrelBakedModelBase.java @@ -29,8 +29,6 @@ import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.item.*; import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.WoodType; import net.neoforged.neoforge.client.ChunkRenderTypeSet; @@ -337,8 +335,7 @@ private BakedModel getDynamicModel(@Nullable String woodName, Map getMaterials(ModelData extraData) { @@ -716,31 +713,32 @@ public TextureAtlasSprite getParticleIcon(ModelData data) { @Override public ModelData getModelData(BlockAndTintGetter world, BlockPos pos, BlockState state, ModelData tileData) { return WorldHelper.getBlockEntity(world, pos, BarrelBlockEntity.class) - .map(be -> { - - ModelData.Builder builder = ModelData.builder(); - boolean hasMainColor = be.getStorageWrapper().hasMainColor(); - builder.with(HAS_MAIN_COLOR, hasMainColor); - boolean hasAccentColor = be.getStorageWrapper().hasAccentColor(); - builder.with(HAS_ACCENT_COLOR, hasAccentColor); - if (!be.hasFullyDynamicRenderer()) { - builder.with(DISPLAY_ITEMS, be.getStorageWrapper().getRenderInfo().getItemDisplayRenderInfo().getDisplayItems()); - builder.with(INACCESSIBLE_SLOTS, be.getStorageWrapper().getRenderInfo().getItemDisplayRenderInfo().getInaccessibleSlots()); - } - builder.with(IS_PACKED, be.isPacked()); - builder.with(SHOWS_LOCK, be.isLocked() && be.shouldShowLock()); - builder.with(SHOWS_TIER, be.shouldShowTier()); - Optional woodType = be.getWoodType(); - if (woodType.isPresent() || !(hasMainColor && hasAccentColor)) { - builder.with(WOOD_NAME, woodType.orElse(WoodType.ACACIA).name()); - } + .map(BarrelBakedModelBase::getModelDataFromBlockEntity).orElse(ModelData.EMPTY); + } - Map materials = be.getMaterials(); - if (!materials.isEmpty()) { - builder.with(MATERIALS, materials); - } - return builder.build(); - }).orElse(ModelData.EMPTY); + public static ModelData getModelDataFromBlockEntity(BarrelBlockEntity be) { + ModelData.Builder builder = ModelData.builder(); + boolean hasMainColor = be.getStorageWrapper().hasMainColor(); + builder.with(HAS_MAIN_COLOR, hasMainColor); + boolean hasAccentColor = be.getStorageWrapper().hasAccentColor(); + builder.with(HAS_ACCENT_COLOR, hasAccentColor); + if (!be.hasFullyDynamicRenderer()) { + builder.with(DISPLAY_ITEMS, be.getStorageWrapper().getRenderInfo().getItemDisplayRenderInfo().getDisplayItems()); + builder.with(INACCESSIBLE_SLOTS, be.getStorageWrapper().getRenderInfo().getItemDisplayRenderInfo().getInaccessibleSlots()); + } + builder.with(IS_PACKED, be.isPacked()); + builder.with(SHOWS_LOCK, be.isLocked() && be.shouldShowLock()); + builder.with(SHOWS_TIER, be.shouldShowTier()); + Optional woodType = be.getWoodType(); + if (woodType.isPresent() || !(hasMainColor && hasAccentColor)) { + builder.with(WOOD_NAME, woodType.orElse(WoodType.ACACIA).name()); + } + + Map materials = be.getMaterials(); + if (!materials.isEmpty()) { + builder.with(MATERIALS, materials); + } + return builder.build(); } @Override @@ -763,7 +761,7 @@ private static class BarrelItemOverrides extends ItemOverrides { private final BarrelBakedModelBase barrelBakedModel; @Nullable private final BakedModel flatTopModel; - private Cache resolvedModels = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES).build(); + private final Cache resolvedModels = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES).build(); public BarrelItemOverrides(BarrelBakedModelBase barrelBakedModel, @Nullable BakedModel flatTopModel) { this.barrelBakedModel = barrelBakedModel; diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/BarrelRenderer.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/BarrelRenderer.java index 9dd7fa740..cb8b1fc75 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/BarrelRenderer.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/BarrelRenderer.java @@ -30,7 +30,9 @@ public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiB return; } - packedLight = LevelRenderer.getLightColor(blockEntity.getLevel(), blockEntity.getBlockPos().relative(storageBlock.getFacing(blockState))); + if (blockEntity.getLevel() != null) { + packedLight = LevelRenderer.getLightColor(blockEntity.getLevel(), blockEntity.getBlockPos().relative(storageBlock.getFacing(blockState))); + } renderFrontFace(blockEntity, poseStack, bufferSource, packedLight, packedOverlay, flatTop, blockState); renderHiddenTier(blockEntity, poseStack, bufferSource, packedLight, packedOverlay); diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ChestRenderer.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ChestRenderer.java index 0d4ae455f..32046101c 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ChestRenderer.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ChestRenderer.java @@ -131,7 +131,7 @@ public void render(ChestBlockEntity chestEntity, float partialTick, PoseStack po poseStack.scale(1.01f, 1.01f, 1.01f); subRenderer.renderBottomAndLid(poseStack, bufferSource, lidAngle, packedLight, packedOverlay, StorageTextureManager.ChestMaterial.PACKED); poseStack.popPose(); - } else if (shouldRenderFrontFace(chestEntity.getBlockPos())) { + } else if (chestEntity.getBlockPos() == BlockPos.ZERO || shouldRenderFrontFace(chestEntity.getBlockPos())) { //special condition for chests that are not in the world poseStack.pushPose(); poseStack.translate(0.5, 0.5, 0.5); poseStack.mulPose(Axis.YP.rotationDegrees(180)); diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/LimitedBarrelRenderer.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/LimitedBarrelRenderer.java index 8b162a13f..790a7924c 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/LimitedBarrelRenderer.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/LimitedBarrelRenderer.java @@ -44,9 +44,11 @@ public void render(LimitedBarrelBlockEntity blockEntity, float partialTick, Pose boolean flatTop = blockState.getValue(BarrelBlock.FLAT_TOP); Direction horizontalFacing = blockState.getValue(LimitedBarrelBlock.HORIZONTAL_FACING); - renderItemCounts(blockEntity, poseStack, bufferSource, flatTop, horizontalFacing, blockState.getValue(LimitedBarrelBlock.VERTICAL_FACING)); + renderItemCounts(blockEntity, poseStack, bufferSource, flatTop, horizontalFacing, blockState.getValue(LimitedBarrelBlock.VERTICAL_FACING), packedLight); - packedLight = LevelRenderer.getLightColor(blockEntity.getLevel(), blockEntity.getBlockPos().relative(storageBlock.getFacing(blockState))); + if (blockEntity.getLevel() != null) { + packedLight = LevelRenderer.getLightColor(blockEntity.getLevel(), blockEntity.getBlockPos().relative(storageBlock.getFacing(blockState))); + } renderFrontFace(blockEntity, poseStack, bufferSource, packedLight, packedOverlay, blockState, flatTop, horizontalFacing); renderHiddenTier(blockEntity, poseStack, bufferSource, packedLight, packedOverlay); @@ -94,7 +96,10 @@ private void renderFillLevels(LimitedBarrelBlockEntity blockEntity, PoseStack po poseStack.pushPose(); poseStack.translate(0, 0, -0.001); - List slotFillLevels = blockEntity.getSlotFillLevels(); + List slotFillLevels = blockEntity.getStorageWrapper().getRenderInfo().getItemDisplayRenderInfo().getSlotFillRatios(); + if (slotFillLevels.isEmpty()) { + slotFillLevels = blockEntity.getSlotFillLevels(); + } int slots = slotFillLevels.size(); boolean translucentRender = !blockEntity.shouldShowFillLevels() && holdsToolInToggleFillLevelDisplay(); @@ -128,12 +133,14 @@ private void renderDisplayItems(LimitedBarrelBlockEntity blockEntity, PoseStack } } - private void renderItemCounts(LimitedBarrelBlockEntity blockEntity, PoseStack poseStack, MultiBufferSource bufferSource, boolean flatTop, Direction horizontalFacing, VerticalFacing verticalFacing) { + private void renderItemCounts(LimitedBarrelBlockEntity blockEntity, PoseStack poseStack, MultiBufferSource bufferSource, boolean flatTop, Direction horizontalFacing, VerticalFacing verticalFacing, int packedLight) { if (!blockEntity.shouldShowCounts()) { return; } - int packedLight = LevelRenderer.getLightColor(blockEntity.getLevel(), blockEntity.getBlockPos().relative(verticalFacing != VerticalFacing.NO ? verticalFacing.getDirection() : horizontalFacing)); + if (blockEntity.getLevel() != null) { + packedLight = LevelRenderer.getLightColor(blockEntity.getLevel(), blockEntity.getBlockPos().relative(verticalFacing != VerticalFacing.NO ? verticalFacing.getDirection() : horizontalFacing)); + } poseStack.pushPose(); @@ -144,7 +151,10 @@ private void renderItemCounts(LimitedBarrelBlockEntity blockEntity, PoseStack po } poseStack.translate(0.5, -0.5, 0.5); - List slotCounts = blockEntity.getSlotCounts(); + List slotCounts = blockEntity.getStorageWrapper().getRenderInfo().getItemDisplayRenderInfo().getSlotCounts(); + if (slotCounts.isEmpty()) { + slotCounts = blockEntity.getSlotCounts(); + } float countDisplayYOffset = -(slotCounts.size() == 1 ? 0.25f : 0.11f); for (int displayItemIndex = 0; displayItemIndex < slotCounts.size(); displayItemIndex++) { int count = slotCounts.get(displayItemIndex); diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StackStorageWrapper.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StackStorageWrapper.java index fd9114e4a..377fde2df 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StackStorageWrapper.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StackStorageWrapper.java @@ -29,7 +29,7 @@ public static StackStorageWrapper fromStack(HolderLookup.Provider registries, It UUID uuid = stack.get(ModCoreDataComponents.STORAGE_UUID); if (uuid != null) { CompoundTag compoundtag = ItemContentsStorage.get().getOrCreateStorageContents(uuid).getCompound(StorageBlockEntity.STORAGE_WRAPPER_TAG); - stackStorageWrapper.load(registries, compoundtag); + stackStorageWrapper.load(compoundtag); stackStorageWrapper.setContentsUuid(uuid); //setting here because client side the uuid isn't in contentsnbt before this data is synced from server and it would create a new one otherwise } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/upgrades/compression/CompressionInventoryPart.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/upgrades/compression/CompressionInventoryPart.java index c27404ad5..3f89419b5 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/upgrades/compression/CompressionInventoryPart.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/upgrades/compression/CompressionInventoryPart.java @@ -307,8 +307,8 @@ private ItemStack extractItem(int slot, int amount, boolean simulate, ToIntFunct extractFromInternal(slot, toExtract); } else { slotStack.shrink(toExtract); - parent.setSlotStack(slot, slotStack); calculatedStacks.put(slot, slotStack.copy()); + parent.setSlotStack(slot, slotStack); } removeDefinitionsIfEmpty(slot); } @@ -577,6 +577,7 @@ private void insertIntoInternalAndCalculated(int slotToStartFrom, long amountToI updateInternalStacksWithCounts(toUpdate); calculatedAdditions.forEach(this::addToCalculatedStack); + toUpdate.keySet().forEach(parent::triggerOnChangeListeners); } private void addToCalculatedStack(int slot, int countToAdd) { diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/upgrades/hopper/HopperUpgradeWrapper.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/upgrades/hopper/HopperUpgradeWrapper.java index 0a5732320..3b8fa1e2f 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/upgrades/hopper/HopperUpgradeWrapper.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/upgrades/hopper/HopperUpgradeWrapper.java @@ -3,7 +3,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Entity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -54,7 +54,7 @@ protected HopperUpgradeWrapper(IStorageWrapper storageWrapper, ItemStack upgrade } @Override - public void tick(@Nullable LivingEntity entity, Level level, BlockPos pos) { + public void tick(@Nullable Entity entity, Level level, BlockPos pos) { initDirections(level, pos); if (coolDownTime > level.getGameTime()) {