From acd932f65e83e7ed852ed3607b7d6949f2bd9d1d Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Sun, 7 Nov 2021 13:09:11 -0800 Subject: [PATCH] Caching and config - Replace old uses of BlockEntity.clearCache appropriately - Slightly improve handling of non-Forge config specs - Minor cleanup --- .../contraptions/components/actors/SeatBlock.java | 2 +- .../components/structureMovement/MountedStorage.java | 2 -- .../content/contraptions/wrench/IWrenchable.java | 2 -- .../curiosities/toolbox/ToolboxTileEntity.java | 11 +++-------- .../logistics/block/chute/ChuteTileEntity.java | 2 +- .../create/foundation/config/ui/BaseConfigScreen.java | 2 +- .../create/foundation/config/ui/ConfigHelper.java | 6 ++++++ .../foundation/config/ui/ConfigModListScreen.java | 2 +- .../create/foundation/gui/UIRenderHelper.java | 7 ++----- .../create/foundation/tileEntity/SmartTileEntity.java | 5 +++++ 10 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java index 2abb60999..27eafc7a6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java @@ -113,7 +113,7 @@ public class SeatBlock extends Block { BlockState newState = BlockHelper.copyProperties(state, AllBlocks.SEATS.get(color) .getDefaultState()); world.setBlockAndUpdate(pos, newState); - return InteractionResult.sidedSuccess(world.isClientSide); + return InteractionResult.SUCCESS; } List seats = world.getEntitiesOfClass(SeatEntity.class, new AABB(pos)); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MountedStorage.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MountedStorage.java index 37f7841a7..68d82cf8b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MountedStorage.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MountedStorage.java @@ -66,7 +66,6 @@ public class MountedStorage { te.getLevel() .setBlockAndUpdate(te.getBlockPos(), te.getBlockState() .setValue(ChestBlock.TYPE, ChestType.SINGLE)); -// te.clearCache(); } // Split double flexcrates @@ -76,7 +75,6 @@ public class MountedStorage { te.getLevel() .setBlockAndUpdate(te.getBlockPos(), te.getBlockState() .setValue(AdjustableCrateBlock.DOUBLE, false)); -// te.clearCache(); } IItemHandler teHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) diff --git a/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java b/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java index d4b3a18ca..dc2a85735 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java +++ b/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java @@ -36,8 +36,6 @@ public interface IWrenchable { BlockEntity te = context.getLevel() .getBlockEntity(context.getClickedPos()); -// if (te != null) -// te.clearCache(); if (te instanceof GeneratingKineticTileEntity) { ((GeneratingKineticTileEntity) te).reActivateSource = true; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java index ea54ccf5e..7712ca5ac 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java @@ -390,15 +390,10 @@ public class ToolboxTileEntity extends SmartTileEntity implements MenuProvider, return customName; } -// @Override -// public void clearCache() { -// super.clearCache(); -// colorProvider.reset(); -// } - + @SuppressWarnings("deprecation") @Override - public void setChanged() { - super.setChanged(); + public void setBlockState(BlockState state) { + super.setBlockState(state); colorProvider.reset(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java index df8cdb5db..65304587c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java @@ -565,7 +565,7 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor } public void onAdded() { -// clearCache(); + refreshBlockState(); updatePull(); ChuteTileEntity targetChute = getTargetChute(getBlockState()); if (targetChute != null) diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java index e0330e898..60c936aa7 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java @@ -95,7 +95,7 @@ public class BaseConfigScreen extends ConfigScreen { * please use {@link #withSpecs(ForgeConfigSpec, ForgeConfigSpec, ForgeConfigSpec)} instead */ public BaseConfigScreen searchForSpecsInModContainer() { - if (!ConfigHelper.hasAnyConfig(this.modID)){ + if (!ConfigHelper.hasAnyForgeConfig(this.modID)){ return this; } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigHelper.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigHelper.java index 575fc884c..6d4cf2713 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigHelper.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigHelper.java @@ -71,6 +71,12 @@ public class ConfigHelper { return true; } + public static boolean hasAnyForgeConfig(String modID) { + if (!modID.equals(Create.ID)) + return configCache.getUnchecked(modID).values().stream().anyMatch(config -> config.getSpec() instanceof ForgeConfigSpec); + return true; + } + // Directly set a value public static void setConfigValue(ConfigPath path, String value) throws InvalidValueException { ForgeConfigSpec spec = findForgeConfigSpecFor(path.getType(), path.getModID()); diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigModListScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigModListScreen.java index e1eda11fd..3e0e52e5a 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigModListScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigModListScreen.java @@ -115,7 +115,7 @@ public class ConfigModListScreen extends ConfigScreen { .showingElement(AllIcons.I_CONFIG_OPEN.asStencil().at(10, 0)); button.modifyElement(e -> ((DelegatedStencilElement) e).withElementRenderer(BoxWidget.gradientFactory.apply(button))); - if (ConfigHelper.hasAnyConfig(id)) { + if (ConfigHelper.hasAnyForgeConfig(id)) { button.withCallback(() -> ScreenOpener.open(new BaseConfigScreen(parent, id))); } else { button.active = false; diff --git a/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java b/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java index db2e21ab2..66365f1ef 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java @@ -30,10 +30,7 @@ public class UIRenderHelper { public static void init() { RenderSystem.recordRenderCall(() -> { Window mainWindow = Minecraft.getInstance().getWindow(); - framebuffer = new CustomRenderTarget(true); - framebuffer.resize(mainWindow.getWidth(), mainWindow.getHeight(), Minecraft.ON_OSX); - framebuffer.setClearColor(0, 0, 0, 0); - framebuffer.enableStencil(); + framebuffer = CustomRenderTarget.create(mainWindow); }); } @@ -262,7 +259,7 @@ public class UIRenderHelper { } public static CustomRenderTarget create(Window mainWindow) { - CustomRenderTarget framebuffer = new CustomRenderTarget(false); + CustomRenderTarget framebuffer = new CustomRenderTarget(true); framebuffer.resize(mainWindow.getWidth(), mainWindow.getHeight(), Minecraft.ON_OSX); framebuffer.setClearColor(0, 0, 0, 0); framebuffer.enableStencil(); diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java index cf768e640..294e91205 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java @@ -223,6 +223,11 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements IParti buffer.writeNbt(getUpdateTag()); } + @SuppressWarnings("deprecation") + public void refreshBlockState() { + setBlockState(getLevel().getBlockState(getBlockPos())); + } + public Level getWorld() { return getLevel(); }