Skip to content

Commit

Permalink
Cleanup and remove some CCL library code usage (#2656)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 authored Nov 9, 2024
1 parent cbb9118 commit c2a0f25
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 279 deletions.
6 changes: 3 additions & 3 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import gregtech.api.util.Mods;
import gregtech.client.renderer.texture.Textures;
import gregtech.client.utils.BloomEffectUtil;
import gregtech.client.utils.RenderUtil;
import gregtech.client.utils.TooltipHelper;
import gregtech.common.ConfigHolder;
import gregtech.common.creativetab.GTCreativeTabs;
Expand Down Expand Up @@ -88,7 +89,6 @@
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.ColourMultiplier;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.texture.TextureUtils;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.IGuiHolder;
Expand Down Expand Up @@ -270,7 +270,7 @@ public boolean showToolUsages() {

@SideOnly(Side.CLIENT)
public Pair<TextureAtlasSprite, Integer> getParticleTexture() {
return Pair.of(TextureUtils.getMissingSprite(), 0xFFFFFF);
return Pair.of(RenderUtil.getMissingSprite(), 0xFFFFFF);
}

/**
Expand All @@ -296,7 +296,7 @@ public void setRenderContextStack(ItemStack itemStack) {
*/
@SideOnly(Side.CLIENT)
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
TextureAtlasSprite atlasSprite = TextureUtils.getMissingSprite();
TextureAtlasSprite atlasSprite = RenderUtil.getMissingSprite();
IVertexOperation[] renderPipeline = ArrayUtils.add(pipeline,
new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering())));
for (EnumFacing face : EnumFacing.VALUES) {
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/gregtech/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import gregtech.client.renderer.pipe.LaserPipeRenderer;
import gregtech.client.renderer.pipe.OpticalPipeRenderer;
import gregtech.client.renderer.pipe.PipeRenderer;
import gregtech.client.renderer.texture.Textures;
import gregtech.client.utils.ItemRenderCompat;
import gregtech.client.utils.TooltipHelper;
import gregtech.common.CommonProxy;
Expand All @@ -33,6 +34,7 @@

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.SimpleReloadableResourceManager;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -46,6 +48,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
Expand All @@ -59,7 +62,6 @@
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;

import codechicken.lib.texture.TextureUtils;
import org.jetbrains.annotations.NotNull;
import paulscode.sound.SoundSystemConfig;

Expand Down Expand Up @@ -91,8 +93,6 @@ public void onPreLoad() {
OpticalPipeRenderer.INSTANCE.preInit();
LaserPipeRenderer.INSTANCE.preInit();
MetaEntities.initRenderers();
TextureUtils.addIconRegister(GTFluidRegistration.INSTANCE::registerSprites);
TextureUtils.addIconRegister(PipeRenderer::initializeRestrictor);
}

@Override
Expand All @@ -114,6 +114,19 @@ public static void registerColors() {
ToolItems.registerColors();
}

@SubscribeEvent
public static void textureStitchPre(@NotNull TextureStitchEvent.Pre event) {
TextureMap map = event.getMap();
GTFluidRegistration.INSTANCE.registerSprites(map);
PipeRenderer.initializeRestrictor(map);
Textures.register(map);
CableRenderer.INSTANCE.registerIcons(map);
FluidPipeRenderer.INSTANCE.registerIcons(map);
ItemPipeRenderer.INSTANCE.registerIcons(map);
OpticalPipeRenderer.INSTANCE.registerIcons(map);
LaserPipeRenderer.INSTANCE.registerIcons(map);
}

@SubscribeEvent
public static void registerModels(ModelRegistryEvent event) {
MetaBlocks.registerStateMappers();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,26 @@
package gregtech.client.model.modelfactories;

import gregtech.client.utils.RenderUtil;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Tuple;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.model.ModelFluid;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.PerspectiveMapWrapper;
import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import codechicken.lib.render.item.CCRenderItem;
import codechicken.lib.texture.TextureUtils;
import codechicken.lib.util.TransformUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.vecmath.Matrix4f;

@SideOnly(Side.CLIENT)
public class BakedModelHandler {

Expand All @@ -49,25 +31,13 @@ protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return getSimpleModelLocation(state.getBlock());
}
};
private static final ItemMeshDefinition SIMPLE_MESH_DEFINITION = (stack) -> getSimpleModelLocation(
Block.getBlockFromItem(stack.getItem()));

private static ModelResourceLocation getSimpleModelLocation(Block block) {
return new ModelResourceLocation(Block.REGISTRY.getNameForObject(block), "");
}

private final List<Tuple<Block, String>> builtInBlocks = new ArrayList<>();
private final List<BlockFluidBase> fluidBlocks = new ArrayList<>();

public void addBuiltInBlock(Block block, String particleTexture) {
this.builtInBlocks.add(new Tuple<>(block, particleTexture));
ModelLoader.setCustomStateMapper(block, SIMPLE_STATE_MAPPER);
Item itemFromBlock = Item.getItemFromBlock(block);
if (itemFromBlock != Items.AIR) {
ModelLoader.setCustomMeshDefinition(itemFromBlock, SIMPLE_MESH_DEFINITION);
}
}

public void addFluidBlock(BlockFluidBase fluidBase) {
this.fluidBlocks.add(fluidBase);
ModelLoader.setCustomStateMapper(fluidBase, SIMPLE_STATE_MAPPER);
Expand All @@ -79,63 +49,9 @@ public void onModelsBake(ModelBakeEvent event) {
Fluid fluid = ObfuscationReflectionHelper.getPrivateValue(BlockFluidBase.class, fluidBlock, "definedFluid");
ModelFluid modelFluid = new ModelFluid(fluid);
IBakedModel bakedModel = modelFluid.bake(modelFluid.getDefaultState(), DefaultVertexFormats.ITEM,
TextureUtils::getTexture);
RenderUtil::getTexture);
ModelResourceLocation resourceLocation = getSimpleModelLocation(fluidBlock);
event.getModelRegistry().putObject(resourceLocation, bakedModel);
}
for (Tuple<Block, String> tuple : builtInBlocks) {
ModelResourceLocation resourceLocation = getSimpleModelLocation(tuple.getFirst());
ModelBuiltInRenderer bakedModel = new ModelBuiltInRenderer(tuple.getSecond());
event.getModelRegistry().putObject(resourceLocation, bakedModel);
}
}

private static class ModelBuiltInRenderer implements IBakedModel {

private final String particleTexture;

public ModelBuiltInRenderer(String particleTexture) {
this.particleTexture = particleTexture;
}

@NotNull
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
return Collections.emptyList();
}

@Override
public boolean isAmbientOcclusion() {
return true;
}

@Override
public boolean isGui3d() {
return true;
}

@Override
public boolean isBuiltInRenderer() {
return true;
}

@NotNull
@Override
public TextureAtlasSprite getParticleTexture() {
return TextureUtils.getBlockTexture(particleTexture);
}

@NotNull
@Override
public ItemOverrideList getOverrides() {
return ItemOverrideList.NONE;
}

@NotNull
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(@NotNull TransformType cameraTransformType) {
CCRenderItem.notifyTransform(cameraTransformType);
return PerspectiveMapWrapper.handlePerspective(this, TransformUtils.DEFAULT_BLOCK, cameraTransformType);
}
}
}
19 changes: 0 additions & 19 deletions src/main/java/gregtech/client/renderer/ICCLBlockRenderer.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/gregtech/client/renderer/ICubeRenderer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.client.renderer;

import gregtech.api.gui.resources.ResourceHelper;
import gregtech.client.texture.IconRegistrar;

import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
Expand All @@ -11,13 +12,12 @@

import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.texture.TextureUtils.IIconRegister;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface ICubeRenderer extends IIconRegister {
public interface ICubeRenderer extends IconRegistrar {

String EMISSIVE = "_emissive";

Expand Down
122 changes: 0 additions & 122 deletions src/main/java/gregtech/client/renderer/handler/CCLBlockRenderer.java

This file was deleted.

Loading

0 comments on commit c2a0f25

Please sign in to comment.