Caching and config

- Replace old uses of BlockEntity.clearCache appropriately
- Slightly improve handling of non-Forge config specs
- Minor cleanup
This commit is contained in:
PepperBell 2021-11-07 13:09:11 -08:00
parent bea8cea59d
commit acd932f65e
10 changed files with 20 additions and 21 deletions

View file

@ -113,7 +113,7 @@ public class SeatBlock extends Block {
BlockState newState = BlockHelper.copyProperties(state, AllBlocks.SEATS.get(color) BlockState newState = BlockHelper.copyProperties(state, AllBlocks.SEATS.get(color)
.getDefaultState()); .getDefaultState());
world.setBlockAndUpdate(pos, newState); world.setBlockAndUpdate(pos, newState);
return InteractionResult.sidedSuccess(world.isClientSide); return InteractionResult.SUCCESS;
} }
List<SeatEntity> seats = world.getEntitiesOfClass(SeatEntity.class, new AABB(pos)); List<SeatEntity> seats = world.getEntitiesOfClass(SeatEntity.class, new AABB(pos));

View file

@ -66,7 +66,6 @@ public class MountedStorage {
te.getLevel() te.getLevel()
.setBlockAndUpdate(te.getBlockPos(), te.getBlockState() .setBlockAndUpdate(te.getBlockPos(), te.getBlockState()
.setValue(ChestBlock.TYPE, ChestType.SINGLE)); .setValue(ChestBlock.TYPE, ChestType.SINGLE));
// te.clearCache();
} }
// Split double flexcrates // Split double flexcrates
@ -76,7 +75,6 @@ public class MountedStorage {
te.getLevel() te.getLevel()
.setBlockAndUpdate(te.getBlockPos(), te.getBlockState() .setBlockAndUpdate(te.getBlockPos(), te.getBlockState()
.setValue(AdjustableCrateBlock.DOUBLE, false)); .setValue(AdjustableCrateBlock.DOUBLE, false));
// te.clearCache();
} }
IItemHandler teHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) IItemHandler teHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)

View file

@ -36,8 +36,6 @@ public interface IWrenchable {
BlockEntity te = context.getLevel() BlockEntity te = context.getLevel()
.getBlockEntity(context.getClickedPos()); .getBlockEntity(context.getClickedPos());
// if (te != null)
// te.clearCache();
if (te instanceof GeneratingKineticTileEntity) { if (te instanceof GeneratingKineticTileEntity) {
((GeneratingKineticTileEntity) te).reActivateSource = true; ((GeneratingKineticTileEntity) te).reActivateSource = true;
} }

View file

@ -390,15 +390,10 @@ public class ToolboxTileEntity extends SmartTileEntity implements MenuProvider,
return customName; return customName;
} }
// @Override @SuppressWarnings("deprecation")
// public void clearCache() {
// super.clearCache();
// colorProvider.reset();
// }
@Override @Override
public void setChanged() { public void setBlockState(BlockState state) {
super.setChanged(); super.setBlockState(state);
colorProvider.reset(); colorProvider.reset();
} }

View file

@ -565,7 +565,7 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor
} }
public void onAdded() { public void onAdded() {
// clearCache(); refreshBlockState();
updatePull(); updatePull();
ChuteTileEntity targetChute = getTargetChute(getBlockState()); ChuteTileEntity targetChute = getTargetChute(getBlockState());
if (targetChute != null) if (targetChute != null)

View file

@ -95,7 +95,7 @@ public class BaseConfigScreen extends ConfigScreen {
* please use {@link #withSpecs(ForgeConfigSpec, ForgeConfigSpec, ForgeConfigSpec)} instead * please use {@link #withSpecs(ForgeConfigSpec, ForgeConfigSpec, ForgeConfigSpec)} instead
*/ */
public BaseConfigScreen searchForSpecsInModContainer() { public BaseConfigScreen searchForSpecsInModContainer() {
if (!ConfigHelper.hasAnyConfig(this.modID)){ if (!ConfigHelper.hasAnyForgeConfig(this.modID)){
return this; return this;
} }

View file

@ -71,6 +71,12 @@ public class ConfigHelper {
return true; 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 // Directly set a value
public static <T> void setConfigValue(ConfigPath path, String value) throws InvalidValueException { public static <T> void setConfigValue(ConfigPath path, String value) throws InvalidValueException {
ForgeConfigSpec spec = findForgeConfigSpecFor(path.getType(), path.getModID()); ForgeConfigSpec spec = findForgeConfigSpecFor(path.getType(), path.getModID());

View file

@ -115,7 +115,7 @@ public class ConfigModListScreen extends ConfigScreen {
.showingElement(AllIcons.I_CONFIG_OPEN.asStencil().at(10, 0)); .showingElement(AllIcons.I_CONFIG_OPEN.asStencil().at(10, 0));
button.modifyElement(e -> ((DelegatedStencilElement) e).withElementRenderer(BoxWidget.gradientFactory.apply(button))); 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))); button.withCallback(() -> ScreenOpener.open(new BaseConfigScreen(parent, id)));
} else { } else {
button.active = false; button.active = false;

View file

@ -30,10 +30,7 @@ public class UIRenderHelper {
public static void init() { public static void init() {
RenderSystem.recordRenderCall(() -> { RenderSystem.recordRenderCall(() -> {
Window mainWindow = Minecraft.getInstance().getWindow(); Window mainWindow = Minecraft.getInstance().getWindow();
framebuffer = new CustomRenderTarget(true); framebuffer = CustomRenderTarget.create(mainWindow);
framebuffer.resize(mainWindow.getWidth(), mainWindow.getHeight(), Minecraft.ON_OSX);
framebuffer.setClearColor(0, 0, 0, 0);
framebuffer.enableStencil();
}); });
} }
@ -262,7 +259,7 @@ public class UIRenderHelper {
} }
public static CustomRenderTarget create(Window mainWindow) { 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.resize(mainWindow.getWidth(), mainWindow.getHeight(), Minecraft.ON_OSX);
framebuffer.setClearColor(0, 0, 0, 0); framebuffer.setClearColor(0, 0, 0, 0);
framebuffer.enableStencil(); framebuffer.enableStencil();

View file

@ -223,6 +223,11 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements IParti
buffer.writeNbt(getUpdateTag()); buffer.writeNbt(getUpdateTag());
} }
@SuppressWarnings("deprecation")
public void refreshBlockState() {
setBlockState(getLevel().getBlockState(getBlockPos()));
}
public Level getWorld() { public Level getWorld() {
return getLevel(); return getLevel();
} }