Skip to content

Commit

Permalink
Improve fluid sprite registration, and fix BuildCraft#4328.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIIL committed Jan 21, 2019
1 parent ab401db commit 4e1e13b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion BuildCraftAPI
5 changes: 1 addition & 4 deletions common/buildcraft/lib/BCLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ public static void init(FMLInitializationEvent evt) {

@Mod.EventHandler
public static void postInit(FMLPostInitializationEvent evt) {
ReloadableRegistryManager.DATA_PACKS.reloadAll();
if (BuildCraftRegistryManager.managerResourcePacks != null) {
ReloadableRegistryManager.RESOURCE_PACKS.reloadAll();
}
ReloadableRegistryManager.loadAll();
BCLibProxy.getProxy().fmlPostInit();
BuildCraftObjectCaches.fmlPostInit();
VanillaListHandlers.fmlPostInit();
Expand Down
3 changes: 3 additions & 0 deletions common/buildcraft/lib/client/guide/GuideManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public void onRegistryReload(EventBuildCraftReload.FinishLoad event) {
// I feel like we shouldn't allow reloading everything by default?
return;
}
if (event.manager.isLoadingAll()) {
return;
}
if (event.reloadingRegistries.contains(GuideBookRegistry.INSTANCE)) {
reload();
}
Expand Down
19 changes: 15 additions & 4 deletions common/buildcraft/lib/client/render/fluid/FluidRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
import buildcraft.lib.misc.GuiUtil;
import buildcraft.lib.misc.MathUtil;
import buildcraft.lib.misc.RenderUtil;
import buildcraft.lib.misc.SpriteUtil;
import buildcraft.lib.misc.VecUtil;

/** Can render 3D fluid cuboid's, up to 1x1x1 in size. Note that they *must* be contained within the 1x1x1 block space -
* you can't use this to render off large multiblocks. Not thread safe -- this uses static variables so you should only
* call this from the main client thread. */
// TODO: thread safety (per thread context?)
// Perhaps move this into IModelRenderer? And that way we get the buffer, force shaders to cope with fluids (?!), etc
@SideOnly(Side.CLIENT)
public class FluidRenderer {

Expand Down Expand Up @@ -160,10 +162,7 @@ public static void renderFluid(FluidSpriteType type, FluidStack fluid, double am
if (type == null) {
type = FluidSpriteType.STILL;
}
sprite = fluidSprites.get(type).get(fluid.getFluid().getName());
if (sprite == null) {
sprite = Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
}
sprite = getFluidSprite(type, fluid);

final double xs = realMin.x;
final double ys = realMin.y;
Expand Down Expand Up @@ -257,6 +256,18 @@ public static void renderFluid(FluidSpriteType type, FluidStack fluid, double am
prof.endSection();
}

public static TextureAtlasSprite getFluidSprite(FluidSpriteType type, FluidStack fluid) {
return getFluidSprite(type, fluid.getFluid());
}

public static TextureAtlasSprite getFluidSprite(FluidSpriteType type, Fluid fluid) {
if (fluid == null) {
return SpriteUtil.missingSprite();
}
TextureAtlasSprite s = fluidSprites.get(type).get(fluid.getName());
return s != null ? s : SpriteUtil.missingSprite();
}

/** Helper function to add a vertex. */
private static void vertex(double x, double y, double z) {
vertex.positiond(x, y, z);
Expand Down
22 changes: 22 additions & 0 deletions common/buildcraft/lib/script/ReloadableRegistryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import net.minecraftforge.common.MinecraftForge;

import buildcraft.api.registry.BuildCraftRegistryManager;
import buildcraft.api.registry.EventBuildCraftReload;
import buildcraft.api.registry.IReloadableRegistry;
import buildcraft.api.registry.IReloadableRegistry.PackType;
Expand All @@ -25,6 +26,8 @@ public enum ReloadableRegistryManager implements IReloadableRegistryManager {
DATA_PACKS(PackType.DATA_PACK),
RESOURCE_PACKS(PackType.RESOURCE_PACK);

private static boolean isLoadingAll;

private final PackType sourceType;
private final BiMap<String, IReloadableRegistry<?>> registries = HashBiMap.create();
private boolean isReloading;
Expand All @@ -34,11 +37,30 @@ public enum ReloadableRegistryManager implements IReloadableRegistryManager {
this.sourceType = sourceType;
}

public static void loadAll() {
try {
isLoadingAll = true;

DATA_PACKS.reloadAll();
if (BuildCraftRegistryManager.managerResourcePacks != null) {
RESOURCE_PACKS.reloadAll();
}

} finally {
isLoadingAll = false;
}
}

@Override
public PackType getType() {
return sourceType;
}

@Override
public boolean isLoadingAll() {
return isLoadingAll;
}

/** Reloads every registry. Generally calling this is a very bad idea if you don't also call other reload events. */
public void reloadAll() {
reload(new HashSet<>(registries.values()));
Expand Down

0 comments on commit 4e1e13b

Please sign in to comment.