Better client init.

This commit is contained in:
raoulvdberge
2019-09-18 22:37:45 +02:00
parent b848c40d9e
commit 0a7d552429
8 changed files with 143 additions and 73 deletions

View File

@@ -0,0 +1,53 @@
package com.raoulvdberge.refinedstorage;
import com.raoulvdberge.refinedstorage.render.BakedModelOverrideRegistry;
import com.raoulvdberge.refinedstorage.render.model.baked.FullbrightBakedModel;
import com.raoulvdberge.refinedstorage.screen.FilterScreen;
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import java.util.function.Function;
public class ClientSetup {
private BakedModelOverrideRegistry bakedModelOverrideRegistry = new BakedModelOverrideRegistry();
public ClientSetup() {
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "controller"), base -> new FullbrightBakedModel(
base,
new ResourceLocation(RS.ID, "block/controller/cutouts/nearly_off"),
new ResourceLocation(RS.ID, "block/controller/cutouts/nearly_on"),
new ResourceLocation(RS.ID, "block/controller/cutouts/on")
));
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "creative_controller"), base -> new FullbrightBakedModel(
base,
new ResourceLocation(RS.ID, "block/controller/cutouts/nearly_off"),
new ResourceLocation(RS.ID, "block/controller/cutouts/nearly_on"),
new ResourceLocation(RS.ID, "block/controller/cutouts/on")
));
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onModelBake);
}
@SubscribeEvent
public void onClientSetup(FMLClientSetupEvent e) {
ScreenManager.registerFactory(RSContainers.FILTER, FilterScreen::new);
}
@SubscribeEvent
public void onModelBake(ModelBakeEvent e) {
for (ResourceLocation id : e.getModelRegistry().keySet()) {
Function<IBakedModel, IBakedModel> factory = this.bakedModelOverrideRegistry.get(new ResourceLocation(id.getNamespace(), id.getPath()));
if (factory != null) {
e.getModelRegistry().put(id, factory.apply(e.getModelRegistry().get(id)));
}
}
}
}

View File

@@ -14,21 +14,20 @@ import com.raoulvdberge.refinedstorage.item.blockitem.ControllerBlockItem;
import com.raoulvdberge.refinedstorage.item.group.MainItemGroup; import com.raoulvdberge.refinedstorage.item.group.MainItemGroup;
import com.raoulvdberge.refinedstorage.network.NetworkHandler; import com.raoulvdberge.refinedstorage.network.NetworkHandler;
import com.raoulvdberge.refinedstorage.recipe.UpgradeWithEnchantedBookRecipeSerializer; import com.raoulvdberge.refinedstorage.recipe.UpgradeWithEnchantedBookRecipeSerializer;
import com.raoulvdberge.refinedstorage.screen.FilterScreen;
import com.raoulvdberge.refinedstorage.tile.ControllerTile; import com.raoulvdberge.refinedstorage.tile.ControllerTile;
import com.raoulvdberge.refinedstorage.util.BlockUtils; import com.raoulvdberge.refinedstorage.util.BlockUtils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.extensions.IForgeContainerType; import net.minecraftforge.common.extensions.IForgeContainerType;
import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -44,8 +43,9 @@ public final class RS {
public static final Config CONFIG = new Config(); public static final Config CONFIG = new Config();
public RS() { public RS() {
DistExecutor.runWhenOn(Dist.CLIENT, () -> ClientSetup::new);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup);
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Block.class, this::onRegisterBlocks); FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Block.class, this::onRegisterBlocks);
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(TileEntityType.class, this::onRegisterTiles); FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(TileEntityType.class, this::onRegisterTiles);
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Item.class, this::onRegisterItems); FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Item.class, this::onRegisterItems);
@@ -61,11 +61,6 @@ public final class RS {
API.instance().getStorageDiskRegistry().add(StorageDiskFactoryFluid.ID, new StorageDiskFactoryFluid()); API.instance().getStorageDiskRegistry().add(StorageDiskFactoryFluid.ID, new StorageDiskFactoryFluid());
} }
@SubscribeEvent
public void onClientSetup(FMLClientSetupEvent e) {
ScreenManager.registerFactory(RSContainers.FILTER, FilterScreen::new);
}
@SubscribeEvent @SubscribeEvent
public void onRegisterRecipeSerializers(RegistryEvent.Register<IRecipeSerializer<?>> e) { public void onRegisterRecipeSerializers(RegistryEvent.Register<IRecipeSerializer<?>> e) {
e.getRegistry().register(new UpgradeWithEnchantedBookRecipeSerializer().setRegistryName(RS.ID, "upgrade_with_enchanted_book")); e.getRegistry().register(new UpgradeWithEnchantedBookRecipeSerializer().setRegistryName(RS.ID, "upgrade_with_enchanted_book"));

View File

@@ -4,7 +4,7 @@ import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.block.info.BlockDirection; import com.raoulvdberge.refinedstorage.block.info.BlockDirection;
import com.raoulvdberge.refinedstorage.block.info.BlockInfoBuilder; import com.raoulvdberge.refinedstorage.block.info.BlockInfoBuilder;
import com.raoulvdberge.refinedstorage.render.IModelRegistration; import com.raoulvdberge.refinedstorage.render.IModelRegistration;
import com.raoulvdberge.refinedstorage.render.model.baked.BakedModelFullbright; import com.raoulvdberge.refinedstorage.render.model.baked.FullbrightBakedModel;
import com.raoulvdberge.refinedstorage.tile.TileCrafter; import com.raoulvdberge.refinedstorage.tile.TileCrafter;
import net.minecraft.client.renderer.model.ModelResourceLocation; import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.BlockRenderLayer;
@@ -24,7 +24,7 @@ public class BlockCrafter extends BlockNode {
public void registerModels(IModelRegistration modelRegistration) { public void registerModels(IModelRegistration modelRegistration) {
modelRegistration.setModel(this, 0, new ModelResourceLocation(info.getId(), "connected=false,direction=north")); modelRegistration.setModel(this, 0, new ModelResourceLocation(info.getId(), "connected=false,direction=north"));
modelRegistration.addBakedModelOverride(info.getId(), base -> new BakedModelFullbright( modelRegistration.addBakedModelOverride(info.getId(), base -> new FullbrightBakedModel(
base, base,
new ResourceLocation(RS.ID, "blocks/crafter/cutouts/side_connected"), new ResourceLocation(RS.ID, "blocks/crafter/cutouts/side_connected"),
new ResourceLocation(RS.ID, "blocks/crafter/cutouts/side_connected_90"), new ResourceLocation(RS.ID, "blocks/crafter/cutouts/side_connected_90"),

View File

@@ -19,8 +19,6 @@ import net.minecraftforge.energy.CapabilityEnergy;
import javax.annotation.Nullable; import javax.annotation.Nullable;
// TODO - Fullbright models
// TODO DROPS
public class ControllerBlock extends Block { public class ControllerBlock extends Block {
public enum Type { public enum Type {
NORMAL, NORMAL,
@@ -104,7 +102,7 @@ public class ControllerBlock extends Block {
} }
} }
/* /* TODO Controller
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) { public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) {
return openNetworkGui(RSGui.CONTROLLER, player, world, pos, side); return openNetworkGui(RSGui.CONTROLLER, player, world, pos, side);

View File

@@ -0,0 +1,22 @@
package com.raoulvdberge.refinedstorage.render;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
public class BakedModelOverrideRegistry {
private Map<ResourceLocation, Function<IBakedModel, IBakedModel>> registry = new HashMap<>();
public void add(ResourceLocation id, Function<IBakedModel, IBakedModel> factory) {
registry.put(id, factory);
}
@Nullable
public Function<IBakedModel, IBakedModel> get(ResourceLocation id) {
return registry.get(id);
}
}

View File

@@ -14,14 +14,15 @@ import javax.vecmath.Matrix4f;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class BakedModelDelegate implements IBakedModel { public class DelegateBakedModel implements IBakedModel {
protected final IBakedModel base; protected final IBakedModel base;
public BakedModelDelegate(IBakedModel base) { public DelegateBakedModel(IBakedModel base) {
this.base = base; this.base = base;
} }
@Override @Override
@SuppressWarnings("deprecation")
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
return base.getQuads(state, side, rand); return base.getQuads(state, side, rand);
} }
@@ -31,11 +32,6 @@ public class BakedModelDelegate implements IBakedModel {
return base.isAmbientOcclusion(); return base.isAmbientOcclusion();
} }
@Override
public boolean isAmbientOcclusion(BlockState state) {
return base.isAmbientOcclusion(state);
}
@Override @Override
public boolean isGui3d() { public boolean isGui3d() {
return base.isGui3d(); return base.isGui3d();
@@ -47,6 +43,7 @@ public class BakedModelDelegate implements IBakedModel {
} }
@Override @Override
@SuppressWarnings("deprecation")
public TextureAtlasSprite getParticleTexture() { public TextureAtlasSprite getParticleTexture() {
return base.getParticleTexture(); return base.getParticleTexture();
} }
@@ -63,6 +60,7 @@ public class BakedModelDelegate implements IBakedModel {
} }
@Override @Override
@SuppressWarnings("deprecation")
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) { public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
return base.handlePerspective(cameraTransformType); return base.handlePerspective(cameraTransformType);
} }

View File

@@ -11,88 +11,48 @@ import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.client.model.pipeline.VertexLighterFlat; import net.minecraftforge.client.model.pipeline.VertexLighterFlat;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.*; import java.util.*;
public class BakedModelFullbright extends BakedModelDelegate { public class FullbrightBakedModel extends DelegateBakedModel {
private class CacheKey {
private IBakedModel base;
private Set<ResourceLocation> textures;
private BlockState state;
private Direction side;
public CacheKey(IBakedModel base, Set<ResourceLocation> textures, BlockState state, Direction side) {
this.base = base;
this.textures = textures;
this.state = state;
this.side = side;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CacheKey cacheKey = (CacheKey) o;
if (cacheKey.side != side) {
return false;
}
if (!state.equals(cacheKey.state)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return state.hashCode() + (31 * (side != null ? side.hashCode() : 0));
}
}
private static final LoadingCache<CacheKey, List<BakedQuad>> CACHE = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<BakedQuad>>() { private static final LoadingCache<CacheKey, List<BakedQuad>> CACHE = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<BakedQuad>>() {
@Override @Override
public List<BakedQuad> load(CacheKey key) { public List<BakedQuad> load(CacheKey key) {
return transformQuads(key.base.getQuads(key.state, key.side, new Random()), key.textures); return transformQuads(key.base.getQuads(key.state, key.side, key.random, EmptyModelData.INSTANCE), key.textures);
} }
}); });
private Set<ResourceLocation> textures; private Set<ResourceLocation> textures;
private boolean cacheDisabled = false; private boolean cacheDisabled = false;
public BakedModelFullbright(IBakedModel base, ResourceLocation... textures) { public FullbrightBakedModel(IBakedModel base, ResourceLocation... textures) {
super(base); super(base);
this.textures = new HashSet<>(Arrays.asList(textures)); this.textures = new HashSet<>(Arrays.asList(textures));
} }
public BakedModelFullbright setCacheDisabled() { public FullbrightBakedModel disableCache() {
this.cacheDisabled = true; this.cacheDisabled = true;
return this; return this;
} }
@Override @Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData data) {
if (state == null) { if (state == null) {
return base.getQuads(state, side, rand); return base.getQuads(state, side, rand, data);
} }
if (cacheDisabled) { if (cacheDisabled) {
return transformQuads(base.getQuads(state, side, rand), textures); return transformQuads(base.getQuads(state, side, rand, data), textures);
} }
return CACHE.getUnchecked(new CacheKey(base, textures, state, side)); return CACHE.getUnchecked(new CacheKey(base, textures, rand, state, side));
} }
private static List<BakedQuad> transformQuads(List<BakedQuad> oldQuads, Set<ResourceLocation> textures) { private static List<BakedQuad> transformQuads(List<BakedQuad> oldQuads, Set<ResourceLocation> textures) {
@@ -142,4 +102,48 @@ public class BakedModelFullbright extends BakedModelDelegate {
return builder.build(); return builder.build();
} }
private class CacheKey {
private IBakedModel base;
private Set<ResourceLocation> textures;
private Random random;
private BlockState state;
private Direction side;
public CacheKey(IBakedModel base, Set<ResourceLocation> textures, Random random, BlockState state, Direction side) {
this.base = base;
this.textures = textures;
this.random = random;
this.state = state;
this.side = side;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CacheKey cacheKey = (CacheKey) o;
if (cacheKey.side != side) {
return false;
}
if (!state.equals(cacheKey.state)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return state.hashCode() + (31 * (side != null ? side.hashCode() : 0));
}
}
} }

View File

@@ -28,6 +28,7 @@ import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.event.RenderTooltipEvent; import net.minecraftforge.client.event.RenderTooltipEvent;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.model.TRSRTransformation; import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
@@ -311,8 +312,7 @@ public final class RenderUtils {
} }
public static boolean isLightMapDisabled() { public static boolean isLightMapDisabled() {
return false; return !ForgeMod.forgeLightPipelineEnabled;
// TODO return FMLClientHandler.instance().hasOptifine() || !ForgeModContainer.forgeLightPipelineEnabled;
} }
public static VertexFormat getFormatWithLightMap(VertexFormat format) { public static VertexFormat getFormatWithLightMap(VertexFormat format) {