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)
.getDefaultState());
world.setBlockAndUpdate(pos, newState);
return InteractionResult.sidedSuccess(world.isClientSide);
return InteractionResult.SUCCESS;
}
List<SeatEntity> seats = world.getEntitiesOfClass(SeatEntity.class, new AABB(pos));

View file

@ -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)

View file

@ -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;
}

View file

@ -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();
}

View file

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

View file

@ -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;
}

View file

@ -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 <T> void setConfigValue(ConfigPath path, String value) throws InvalidValueException {
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));
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;

View file

@ -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();

View file

@ -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();
}