mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 06:42:56 +00:00
Loads of work on CTM, work on fixing multi blocks
This commit is contained in:
1 parent
07a7391dfc
commit
3b75d9ff1e
111 files changed
+526
-312
No files matched your search
@@ -1,5 +1,13 @@
|
||||
package mekanism.client.render.ctm;
|
||||
|
||||
import static mekanism.client.render.ctm.Dir.BOTTOM;
|
||||
import static mekanism.client.render.ctm.Dir.BOTTOM_LEFT;
|
||||
import static mekanism.client.render.ctm.Dir.BOTTOM_RIGHT;
|
||||
import static mekanism.client.render.ctm.Dir.LEFT;
|
||||
import static mekanism.client.render.ctm.Dir.RIGHT;
|
||||
import static mekanism.client.render.ctm.Dir.TOP;
|
||||
import static mekanism.client.render.ctm.Dir.TOP_LEFT;
|
||||
import static mekanism.client.render.ctm.Dir.TOP_RIGHT;
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
|
||||
@@ -8,13 +16,12 @@ import java.util.EnumMap;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import static mekanism.client.render.ctm.Dir.*;
|
||||
|
||||
// @formatter:off
|
||||
/**
|
||||
* The CTM renderer will draw the block's FACE using by assembling 4 quadrants from the 5 available block
|
||||
@@ -254,26 +261,30 @@ public class CTM {
|
||||
* The state to check against for connection.
|
||||
* @return True if the given block can connect to the given location on the given side.
|
||||
*/
|
||||
public boolean isConnected(IBlockAccess world, BlockPos current, BlockPos connection, EnumFacing dir, IBlockState state) {
|
||||
|
||||
// if (CTMLib.chiselLoaded() && connectionBlocked(world, x, y, z, dir.ordinal())) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public boolean isConnected(IBlockAccess world, BlockPos current, BlockPos connection, EnumFacing dir, IBlockState state)
|
||||
{
|
||||
BlockPos pos2 = connection.add(dir.getDirectionVec());
|
||||
|
||||
boolean disableObscured = disableObscuredFaceCheck.or(disableObscuredFaceCheckConfig);
|
||||
|
||||
IBlockState con = getBlockOrFacade(world, connection, dir);
|
||||
IBlockState obscuring = disableObscured ? null : getBlockOrFacade(world, pos2, dir);
|
||||
|
||||
CTMData data = ((ICTMBlock)state.getBlock()).getCTMData(state);
|
||||
|
||||
// no block or a bad API user
|
||||
if (con == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO VERY TEMPORARY
|
||||
boolean ret = con.getBlock() == state.getBlock();
|
||||
boolean ret = false;
|
||||
|
||||
if(con.getBlock() instanceof ICTMBlock)
|
||||
{
|
||||
String state2 = ((IStringSerializable)con.getValue(((ICTMBlock)con.getBlock()).getTypeProperty())).getName();
|
||||
|
||||
ret = data.acceptableBlockStates.contains(state2);
|
||||
}
|
||||
|
||||
// no block obscuring this face
|
||||
if (obscuring == null) {
|
||||
@@ -286,14 +297,6 @@ public class CTM {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// private boolean connectionBlocked(IBlockAccess world, int x, int y, int z, int side) {
|
||||
// Block block = world.getBlock(x, y, z);
|
||||
// if (block instanceof IConnectable) {
|
||||
// return !((IConnectable) block).canConnectCTM(world, x, y, z, side);
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public IBlockState getBlockOrFacade(IBlockAccess world, BlockPos pos, EnumFacing side) {
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
return state;
|
||||
|
||||
@@ -6,23 +6,27 @@ import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public class CTMBlockRenderContext {
|
||||
|
||||
public class CTMBlockRenderContext
|
||||
{
|
||||
private EnumMap<EnumFacing, CTM> ctmData = new EnumMap<>(EnumFacing.class);
|
||||
|
||||
public CTMBlockRenderContext(IBlockAccess world, BlockPos pos) {
|
||||
for (EnumFacing face : EnumFacing.VALUES) {
|
||||
public CTMBlockRenderContext(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
for(EnumFacing face : EnumFacing.VALUES)
|
||||
{
|
||||
CTM ctm = createCTM();
|
||||
ctm.createSubmapIndices(world, pos, face);
|
||||
ctmData.put(face, ctm);
|
||||
}
|
||||
}
|
||||
|
||||
protected CTM createCTM() {
|
||||
protected CTM createCTM()
|
||||
{
|
||||
return CTM.getInstance();
|
||||
}
|
||||
|
||||
public CTM getCTM(EnumFacing face) {
|
||||
public CTM getCTM(EnumFacing face)
|
||||
{
|
||||
return ctmData.get(face);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package mekanism.client.render.ctm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class CTMData
|
||||
{
|
||||
public List<String> acceptableBlockStates = new ArrayList<String>();
|
||||
|
||||
public boolean renderConvexConnections = false;
|
||||
|
||||
public String facingOverride;
|
||||
|
||||
public CTMData(IStringSerializable... states)
|
||||
{
|
||||
for(IStringSerializable state : states)
|
||||
{
|
||||
acceptableBlockStates.add(state.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public CTMData setRenderConvexConnections()
|
||||
{
|
||||
renderConvexConnections = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CTMData setFacingOverride(String s)
|
||||
{
|
||||
facingOverride= s;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean hasFacingOverride()
|
||||
{
|
||||
return facingOverride != null;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean shouldRenderSide(IBlockAccess world, BlockPos pos, EnumFacing side)
|
||||
{
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
||||
if(state.getBlock() instanceof ICTMBlock)
|
||||
{
|
||||
IStringSerializable serializable = (IStringSerializable)state.getValue(((ICTMBlock)state.getBlock()).getTypeProperty());
|
||||
return acceptableBlockStates.contains(serializable.getName());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+13
-17
@@ -19,18 +19,22 @@ import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.TRSRTransformation;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class TextureStitcher {
|
||||
|
||||
public class CTMRegistry
|
||||
{
|
||||
private static List<TextureSpriteCallback> textures = new ArrayList<TextureSpriteCallback>();
|
||||
|
||||
private IBakedModel baseModel;
|
||||
public static ResourceLocation baseResource = new ResourceLocation("mekanism:block/ctm_block");
|
||||
|
||||
public static String[] ctmTypes = new String[] {"dynamic_tank"};
|
||||
public static String[] ctmTypes = new String[] {"dynamic_tank", "structural_glass", "dynamic_valve", "teleporter", "teleporter_frame", "induction_casing", "induction_port_input", "induction_port_output",
|
||||
"induction_cell_basic", "induction_cell_advanced", "induction_cell_elite", "induction_cell_ultimate", "induction_provider_basic", "induction_provider_advanced", "induction_provider_elite",
|
||||
"induction_provider_ultimate", "thermal_evaporation_controller", "thermal_evaporation_controller_on", "thermal_evaporation_valve", "superheating_element", "superheating_element_on", "reactor_port",
|
||||
"reactor_neutron_capture", "reactor_logic_adapter", "reactor_laser_focus", "reactor_glass", "reactor_frame", "reactor_controller_on", "reactor_controller_off", "boiler_casing", "boiler_valve",
|
||||
"electromagnetic_coil", "thermal_evaporation_valve", "thermal_evaporation_block", "turbine_casing", "turbine_vent", "turbine_valve"};
|
||||
|
||||
public static Map<String, ChiselTextureCTM> textureCache = new HashMap<String, ChiselTextureCTM>();
|
||||
|
||||
public TextureStitcher()
|
||||
public CTMRegistry()
|
||||
{
|
||||
if(textureCache.isEmpty())
|
||||
{
|
||||
@@ -42,8 +46,10 @@ public class TextureStitcher {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTextureStitch(TextureStitchEvent.Pre event) {
|
||||
for (TextureSpriteCallback callback : textures) {
|
||||
public void onTextureStitch(TextureStitchEvent.Pre event)
|
||||
{
|
||||
for(TextureSpriteCallback callback : textures)
|
||||
{
|
||||
callback.stitch(event.map);
|
||||
}
|
||||
}
|
||||
@@ -54,7 +60,7 @@ public class TextureStitcher {
|
||||
IModel model = event.modelLoader.getModel(baseResource);
|
||||
baseModel = model.bake(new TRSRTransformation(ModelRotation.X0_Y0), Attributes.DEFAULT_BAKED_FORMAT, r -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(r.toString()));
|
||||
|
||||
for (String ctm : ctmTypes)
|
||||
for(String ctm : ctmTypes)
|
||||
{
|
||||
ModelChisel chiselModel = new ModelChisel(baseModel, ctm);
|
||||
chiselModel.load();
|
||||
@@ -79,14 +85,4 @@ public class TextureStitcher {
|
||||
|
||||
return new ChiselTextureCTM(EnumWorldBlockLayer.SOLID, callbacks);
|
||||
}
|
||||
|
||||
public static ChiselFace createFace(String name)
|
||||
{
|
||||
ChiselFace face = new ChiselFace();
|
||||
|
||||
face.addTexture(textureCache.get(name));
|
||||
face.setLayer(EnumWorldBlockLayer.SOLID);
|
||||
|
||||
return face;
|
||||
}
|
||||
}
|
||||
@@ -7,28 +7,30 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.EnumWorldBlockLayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class ChiselTextureCTM {
|
||||
|
||||
@Getter
|
||||
public class ChiselTextureCTM
|
||||
{
|
||||
protected EnumWorldBlockLayer layer;
|
||||
|
||||
protected TextureSpriteCallback[] sprites;
|
||||
public TextureSpriteCallback[] sprites;
|
||||
|
||||
public ChiselTextureCTM(EnumWorldBlockLayer layer, TextureSpriteCallback[] sprites) {
|
||||
public ChiselTextureCTM(EnumWorldBlockLayer layer, TextureSpriteCallback[] sprites)
|
||||
{
|
||||
this.layer = layer;
|
||||
this.sprites = sprites;
|
||||
}
|
||||
|
||||
public List<BakedQuad> transformQuad(BakedQuad bq, CTMBlockRenderContext context, int quadGoal) {
|
||||
public List<BakedQuad> transformQuad(BakedQuad bq, CTMBlockRenderContext context, int quadGoal)
|
||||
{
|
||||
Quad quad = Quad.from(bq, DefaultVertexFormats.ITEM);
|
||||
if (context == null) {
|
||||
|
||||
if(context == null)
|
||||
{
|
||||
return Collections.singletonList(quad.transformUVs(sprites[0].getSprite()).rebake());
|
||||
}
|
||||
|
||||
@@ -36,21 +38,27 @@ public class ChiselTextureCTM {
|
||||
|
||||
int[] ctm = ((CTMBlockRenderContext)context).getCTM(bq.getFace()).getSubmapIndices();
|
||||
|
||||
for (int i = 0; i < quads.length; i++) {
|
||||
for(int i = 0; i < quads.length; i++)
|
||||
{
|
||||
Quad q = quads[i];
|
||||
if (q != null) {
|
||||
int ctmid = q.getUvs().normalize().getQuadrant();
|
||||
|
||||
if(q != null)
|
||||
{
|
||||
int ctmid = q.getUVs().normalize().getQuadrant();
|
||||
quads[i] = q.grow().transformUVs(sprites[ctm[ctmid] > 15 ? 0 : 1].getSprite(), CTM.uvs[ctm[ctmid]].normalize());
|
||||
}
|
||||
}
|
||||
|
||||
return Arrays.stream(quads).filter(Objects::nonNull).map(q -> q.rebake()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getParticle(){
|
||||
public TextureAtlasSprite getParticle()
|
||||
{
|
||||
return sprites[0].getSprite();
|
||||
}
|
||||
|
||||
public Collection<ResourceLocation> getTextures() {
|
||||
public Collection<ResourceLocation> getTextures()
|
||||
{
|
||||
return Arrays.stream(sprites).map(TextureSpriteCallback::getLocation).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,14 @@
|
||||
package mekanism.client.render.ctm;
|
||||
|
||||
public interface ICTMBlock {
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public interface ICTMBlock<T extends Enum & IStringSerializable>
|
||||
{
|
||||
public CTMData getCTMData(IBlockState state);
|
||||
|
||||
public PropertyEnum<? extends T> getTypeProperty();
|
||||
|
||||
public String getOverrideTexture(IBlockState state);
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.statemap.DefaultStateMapper;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
@@ -24,20 +22,15 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
||||
public class ModelChisel implements IModel {
|
||||
|
||||
private static StateMapperBase mapper = new DefaultStateMapper();
|
||||
|
||||
public class ModelChisel implements IModel
|
||||
{
|
||||
private Map<EnumFacing, String> overrides = Maps.newHashMap();
|
||||
|
||||
private transient ChiselFace faceObj;
|
||||
private transient Map<EnumFacing, ChiselFace> overridesObj = new EnumMap<>(EnumFacing.class);
|
||||
private transient ChiselTextureCTM faceObj;
|
||||
private transient Map<EnumFacing, ChiselTextureCTM> overridesObj = new EnumMap<>(EnumFacing.class);
|
||||
|
||||
private transient IBakedModel modelObj;
|
||||
|
||||
private transient Map<IBlockState, IBakedModel> stateMap = Maps.newHashMap();
|
||||
|
||||
private transient List<ResourceLocation> textures = Lists.newArrayList();
|
||||
|
||||
public String modelName;
|
||||
@@ -49,44 +42,53 @@ public class ModelChisel implements IModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return new ArrayList<ResourceLocation>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures() {
|
||||
public Collection<ResourceLocation> getTextures()
|
||||
{
|
||||
return ImmutableList.copyOf(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState() {
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
|
||||
void load() {
|
||||
if (faceObj != null) {
|
||||
void load()
|
||||
{
|
||||
if(faceObj != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
System.out.println("LOADING MODEL");
|
||||
faceObj = TextureStitcher.createFace(modelName);
|
||||
faceObj.getTextureList().forEach(t -> textures.addAll(t.getTextures()));
|
||||
overridesObj.values().forEach(f -> f.getTextureList().forEach(t -> textures.addAll(t.getTextures())));
|
||||
|
||||
faceObj = CTMRegistry.textureCache.get(modelName);
|
||||
textures.addAll(faceObj.getTextures());
|
||||
overridesObj.values().forEach(t -> textures.addAll(t.getTextures()));
|
||||
}
|
||||
|
||||
public ChiselFace getDefaultFace() {
|
||||
public ChiselTextureCTM getDefaultFace()
|
||||
{
|
||||
return faceObj;
|
||||
}
|
||||
|
||||
public ChiselFace getFace(EnumFacing facing) {
|
||||
public ChiselTextureCTM getFace(EnumFacing facing)
|
||||
{
|
||||
return overridesObj.getOrDefault(facing, faceObj);
|
||||
}
|
||||
|
||||
public IBakedModel getModel(IBlockState state) {
|
||||
public IBakedModel getModel(IBlockState state)
|
||||
{
|
||||
return modelObj;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
import mekanism.common.block.BlockBasic;
|
||||
import mekanism.common.block.states.BlockStateFacing;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
@@ -32,14 +33,13 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
/**
|
||||
* Model for all chisel blocks
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ModelChiselBlock implements ISmartBlockModel, ISmartItemModel, IPerspectiveAwareModel {
|
||||
|
||||
public class ModelChiselBlock implements ISmartBlockModel, ISmartItemModel, IPerspectiveAwareModel
|
||||
{
|
||||
public static final TRSRTransformation DEFAULT_BLOCK_THIRD_PERSON_TRANSOFRM = new TRSRTransformation(new Vector3f(0, 1.5f / 16f, -2.75f / 16f), TRSRTransformation.quatFromYXZDegrees(new Vector3f(10, -45, 170)), new Vector3f(0.375f, 0.375f, 0.375f), null);
|
||||
public static final Matrix4f DEFAULT_BLOCK_THIRD_PERSON_MATRIX = DEFAULT_BLOCK_THIRD_PERSON_TRANSOFRM.getMatrix();
|
||||
|
||||
@@ -48,107 +48,144 @@ public class ModelChiselBlock implements ISmartBlockModel, ISmartItemModel, IPer
|
||||
|
||||
private ModelChisel model;
|
||||
|
||||
public ModelChiselBlock(List<BakedQuad> face, List<BakedQuad> general, ModelChisel model){
|
||||
public ModelChiselBlock(List<BakedQuad> face, List<BakedQuad> general, ModelChisel model)
|
||||
{
|
||||
this.face = face;
|
||||
this.general = general;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public ModelChiselBlock(ModelChisel model){
|
||||
public ModelChiselBlock(ModelChisel model)
|
||||
{
|
||||
this(Collections.emptyList(), Collections.emptyList(), model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing facing){
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing facing)
|
||||
{
|
||||
return FluentIterable.from(face).filter(quad -> quad.getFace() == facing).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getGeneralQuads() {
|
||||
public List<BakedQuad> getGeneralQuads()
|
||||
{
|
||||
return general;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion(){
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d(){
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer(){
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture() {
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return this.model.getDefaultFace().getParticle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms(){
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
// TODO implement model caching, returning a new model every time is a HUGE waste of memory and CPU
|
||||
|
||||
@Override
|
||||
public IBakedModel handleBlockState(IBlockState stateIn) {
|
||||
if (stateIn.getBlock() instanceof ICTMBlock && stateIn instanceof IExtendedBlockState) {
|
||||
public IBakedModel handleBlockState(IBlockState stateIn)
|
||||
{
|
||||
if(stateIn.getBlock() instanceof ICTMBlock && stateIn instanceof IExtendedBlockState)
|
||||
{
|
||||
IExtendedBlockState state = (IExtendedBlockState) stateIn;
|
||||
CTMBlockRenderContext ctxList = state.getValue(BlockBasic.ctmProperty);
|
||||
return createModel(stateIn, model, ctxList);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState(ItemStack stack) {
|
||||
public IBakedModel handleItemState(ItemStack stack)
|
||||
{
|
||||
Block block = ((ItemBlock) stack.getItem()).getBlock();
|
||||
return createModel(block.getDefaultState(), model, null);
|
||||
}
|
||||
|
||||
private ModelChiselBlock createModel(IBlockState state, ModelChisel model, CTMBlockRenderContext ctx) {
|
||||
private ModelChiselBlock createModel(IBlockState state, ModelChisel model, CTMBlockRenderContext ctx)
|
||||
{
|
||||
List<BakedQuad> faceQuads = Lists.newArrayList();
|
||||
List<BakedQuad> generalQuads = Lists.newArrayList();
|
||||
for (EnumFacing facing : EnumFacing.VALUES){
|
||||
ChiselFace face = model.getFace(facing);
|
||||
|
||||
for(EnumFacing facing : EnumFacing.VALUES)
|
||||
{
|
||||
ChiselTextureCTM face = model.getFace(facing);
|
||||
ICTMBlock block = (ICTMBlock)state.getBlock();
|
||||
CTMData data = block.getCTMData(state);
|
||||
|
||||
if(block.getOverrideTexture(state) != null)
|
||||
{
|
||||
face = CTMRegistry.textureCache.get(block.getOverrideTexture(state));
|
||||
}
|
||||
|
||||
int quadGoal = ctx == null ? 1 : Ordering.natural().max(FluentIterable.from(face.getTextureList()).transform(tex -> CTM.QUADS_PER_SIDE));
|
||||
int quadGoal = ctx == null ? 1 : CTM.QUADS_PER_SIDE;
|
||||
IBakedModel baked = model.getModel(state);
|
||||
List<BakedQuad> origFaceQuads = baked.getFaceQuads(facing);
|
||||
List<BakedQuad> origGeneralQuads = FluentIterable.from(baked.getGeneralQuads()).filter(q -> q.getFace() == facing).toList();
|
||||
addAllQuads(origFaceQuads, face, ctx, quadGoal, faceQuads);
|
||||
addAllQuads(origGeneralQuads, face, ctx, quadGoal, generalQuads);
|
||||
addAllQuads(origFaceQuads, face, ctx, state, quadGoal, faceQuads);
|
||||
addAllQuads(origGeneralQuads, face, ctx, state, quadGoal, generalQuads);
|
||||
}
|
||||
|
||||
return new ModelChiselBlock(faceQuads, generalQuads, model);
|
||||
}
|
||||
|
||||
private void addAllQuads(List<BakedQuad> from, ChiselFace face, @Nullable CTMBlockRenderContext ctx, int quadGoal, List<BakedQuad> to) {
|
||||
for (BakedQuad q : from) {
|
||||
for (ChiselTextureCTM tex : face.getTextureList()) {
|
||||
to.addAll(tex.transformQuad(q, ctx == null ? null : ctx, quadGoal));
|
||||
private void addAllQuads(List<BakedQuad> from, ChiselTextureCTM tex, @Nullable CTMBlockRenderContext ctx, IBlockState state, int quadGoal, List<BakedQuad> to)
|
||||
{
|
||||
for(BakedQuad q : from)
|
||||
{
|
||||
ChiselTextureCTM toUse = tex;
|
||||
CTMData data = ((ICTMBlock)state.getBlock()).getCTMData(state);
|
||||
|
||||
if(data.hasFacingOverride() && q.getFace() == state.getValue(BlockStateFacing.facingProperty))
|
||||
{
|
||||
toUse = CTMRegistry.textureCache.get(data.facingOverride);
|
||||
}
|
||||
|
||||
to.addAll(toUse.transformQuad(q, ctx == null ? null : ctx, quadGoal));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexFormat getFormat() {
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return Attributes.DEFAULT_BAKED_FORMAT;
|
||||
}
|
||||
|
||||
private Pair<IPerspectiveAwareModel, Matrix4f> thirdPersonTransform;
|
||||
|
||||
@Override
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
|
||||
if (cameraTransformType == TransformType.THIRD_PERSON) {
|
||||
if (thirdPersonTransform == null) {
|
||||
public Pair<? extends IFlexibleBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType)
|
||||
{
|
||||
if(cameraTransformType == TransformType.THIRD_PERSON)
|
||||
{
|
||||
if(thirdPersonTransform == null)
|
||||
{
|
||||
thirdPersonTransform = ImmutablePair.of(this, DEFAULT_BLOCK_THIRD_PERSON_MATRIX);
|
||||
}
|
||||
|
||||
return thirdPersonTransform;
|
||||
}
|
||||
return Pair.of(this, null);
|
||||
|
||||
@@ -5,25 +5,29 @@ import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
/**
|
||||
* Block Property for the render context list
|
||||
*/
|
||||
public class PropertyCTMRenderContext implements IUnlistedProperty<CTMBlockRenderContext> {
|
||||
|
||||
public class PropertyCTMRenderContext implements IUnlistedProperty<CTMBlockRenderContext>
|
||||
{
|
||||
@Override
|
||||
public String getName(){
|
||||
public String getName()
|
||||
{
|
||||
return "connections";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(CTMBlockRenderContext value){
|
||||
public boolean isValid(CTMBlockRenderContext value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<CTMBlockRenderContext> getType(){
|
||||
public Class<CTMBlockRenderContext> getType()
|
||||
{
|
||||
return CTMBlockRenderContext.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString(CTMBlockRenderContext value){
|
||||
public String valueToString(CTMBlockRenderContext value)
|
||||
{
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,6 @@ import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.Value;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -29,34 +24,31 @@ import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
|
||||
@ToString(of = { "vertPos", "vertUv" })
|
||||
public class Quad {
|
||||
|
||||
public class Quad
|
||||
{
|
||||
public static final ISubmap TOP_LEFT = new Submap(8, 8, 0, 0);
|
||||
public static final ISubmap TOP_RIGHT = new Submap(8, 8, 8, 0);
|
||||
public static final ISubmap BOTTOM_LEFT = new Submap(8, 8, 0, 8);
|
||||
public static final ISubmap BOTTOM_RIGHT = new Submap(8, 8, 8, 8);
|
||||
|
||||
@Value
|
||||
public static class Vertex {
|
||||
public static class Vertex
|
||||
{
|
||||
Vector3f pos;
|
||||
Vector2f uvs;
|
||||
}
|
||||
|
||||
private static final TextureAtlasSprite BASE = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(TextureMap.LOCATION_MISSING_TEXTURE.toString());
|
||||
|
||||
@ToString
|
||||
public class UVs {
|
||||
|
||||
@Getter
|
||||
public class UVs
|
||||
{
|
||||
private float minU, minV, maxU, maxV;
|
||||
|
||||
@Getter
|
||||
private final TextureAtlasSprite sprite;
|
||||
|
||||
private final Vector2f[] data;
|
||||
|
||||
private UVs(Vector2f... data) {
|
||||
private UVs(Vector2f... data)
|
||||
{
|
||||
this(BASE, data);
|
||||
}
|
||||
|
||||
@@ -134,6 +126,11 @@ public class Quad {
|
||||
public UVs relativize() {
|
||||
return relativize(sprite);
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getSprite()
|
||||
{
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public UVs relativize(TextureAtlasSprite sprite) {
|
||||
Vector2f min = new Vector2f(sprite.getMinU(), sprite.getMinV());
|
||||
@@ -190,8 +187,7 @@ public class Quad {
|
||||
private final Vector2f[] vertUv;
|
||||
|
||||
// Technically nonfinal, but treated as such except in constructor
|
||||
@Getter
|
||||
private UVs uvs;
|
||||
private UVs uvsObj;
|
||||
|
||||
private final Builder builder;
|
||||
|
||||
@@ -199,16 +195,17 @@ public class Quad {
|
||||
this.vertPos = verts;
|
||||
this.vertUv = uvs;
|
||||
this.builder = builder;
|
||||
this.uvs = new UVs(uvs);
|
||||
this.uvsObj = new UVs(uvs);
|
||||
}
|
||||
|
||||
private Quad(Vector3f[] verts, UVs uvs, Builder builder) {
|
||||
this(verts, uvs.vectorize(), builder);
|
||||
this.uvs = new UVs(uvs.getSprite(), vertUv);
|
||||
this.uvsObj = new UVs(uvs.getSprite(), vertUv);
|
||||
}
|
||||
|
||||
public void compute() {
|
||||
|
||||
|
||||
public UVs getUVs()
|
||||
{
|
||||
return uvsObj;
|
||||
}
|
||||
|
||||
public Quad[] subdivide(int count) {
|
||||
@@ -235,7 +232,7 @@ public class Quad {
|
||||
@Nullable
|
||||
private Pair<Quad, Quad> divide(boolean vertical) {
|
||||
float min, max;
|
||||
UVs uvs = getUvs().normalize();
|
||||
UVs uvs = uvsObj.normalize();
|
||||
if (vertical) {
|
||||
min = uvs.minV;
|
||||
max = uvs.maxV;
|
||||
@@ -249,7 +246,7 @@ public class Quad {
|
||||
|
||||
int firstIndex = 0;
|
||||
for (int i = 0; i < vertUv.length; i++) {
|
||||
if (vertUv[i].y == getUvs().minV && vertUv[i].x == getUvs().minU) {
|
||||
if (vertUv[i].y == uvsObj.minV && vertUv[i].x == uvsObj.minU) {
|
||||
firstIndex = i;
|
||||
break;
|
||||
}
|
||||
@@ -305,7 +302,7 @@ public class Quad {
|
||||
public Quad rotate(int amount) {
|
||||
Vector2f[] uvs = new Vector2f[4];
|
||||
|
||||
TextureAtlasSprite s = getUvs().getSprite();
|
||||
TextureAtlasSprite s = uvsObj.getSprite();
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Vector2f normalized = new Vector2f(normalize(s.getMinU(), s.getMaxU(), vertUv[i].x), normalize(s.getMinV(), s.getMaxV(), vertUv[i].y));
|
||||
@@ -332,14 +329,14 @@ public class Quad {
|
||||
}
|
||||
|
||||
Quad ret = new Quad(vertPos, uvs, builder);
|
||||
ret.uvs = new UVs(getUvs().getSprite(), ret.vertUv);
|
||||
ret.uvsObj = new UVs(uvsObj.getSprite(), ret.vertUv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Quad derotate() {
|
||||
int start = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (vertUv[i].x <= getUvs().minU && vertUv[i].y <= getUvs().minV) {
|
||||
if (vertUv[i].x <= uvsObj.minU && vertUv[i].y <= uvsObj.minV) {
|
||||
start = i;
|
||||
break;
|
||||
}
|
||||
@@ -383,11 +380,11 @@ public class Quad {
|
||||
}
|
||||
|
||||
public Quad transformUVs(TextureAtlasSprite sprite, ISubmap submap) {
|
||||
return new Quad(vertPos, getUvs().transform(sprite, submap), builder);
|
||||
return new Quad(vertPos, uvsObj.transform(sprite, submap), builder);
|
||||
}
|
||||
|
||||
public Quad grow() {
|
||||
return new Quad(vertPos, getUvs().normalizeQuadrant(), builder);
|
||||
return new Quad(vertPos, uvsObj.normalizeQuadrant(), builder);
|
||||
}
|
||||
|
||||
public static Quad from(BakedQuad baked, VertexFormat fmt) {
|
||||
@@ -396,17 +393,36 @@ public class Quad {
|
||||
return b.build().derotate(); // for now we will ignore rotated UVs
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public static class Builder implements IVertexConsumer {
|
||||
|
||||
@Getter
|
||||
public static class Builder implements IVertexConsumer
|
||||
{
|
||||
public Builder(VertexFormat fmt)
|
||||
{
|
||||
vertexFormat = fmt;
|
||||
}
|
||||
|
||||
private final VertexFormat vertexFormat;
|
||||
|
||||
@Setter
|
||||
private int quadTint;
|
||||
|
||||
@Setter
|
||||
private EnumFacing quadOrientation;
|
||||
|
||||
@Override
|
||||
public void setQuadTint(int tint)
|
||||
{
|
||||
quadTint = tint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadOrientation(EnumFacing orientation)
|
||||
{
|
||||
quadOrientation = orientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexFormat getVertexFormat()
|
||||
{
|
||||
return vertexFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadColored() {}
|
||||
|
||||
@@ -1,18 +1,45 @@
|
||||
package mekanism.client.render.ctm;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Submap implements ISubmap {
|
||||
|
||||
public class Submap implements ISubmap
|
||||
{
|
||||
private final float width, height;
|
||||
private final float xOffset, yOffset;
|
||||
|
||||
private final SubmapNormalized normalized = new SubmapNormalized(this);
|
||||
|
||||
public Submap(float w, float h, float x, float y)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
xOffset = x;
|
||||
yOffset = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getXOffset()
|
||||
{
|
||||
return xOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYOffset()
|
||||
{
|
||||
return yOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInterpolatedU(TextureAtlasSprite sprite, float u) {
|
||||
@@ -41,10 +68,14 @@ public class Submap implements ISubmap {
|
||||
|
||||
private static final float FACTOR = 16f;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class SubmapNormalized implements ISubmap {
|
||||
|
||||
private static class SubmapNormalized implements ISubmap
|
||||
{
|
||||
private final ISubmap parent;
|
||||
|
||||
public SubmapNormalized(ISubmap submap)
|
||||
{
|
||||
parent = submap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getXOffset() {
|
||||
|
||||
@@ -9,16 +9,18 @@ import net.minecraft.util.ResourceLocation;
|
||||
* Callback when textures are stitched
|
||||
*/
|
||||
@Getter
|
||||
public class TextureSpriteCallback {
|
||||
|
||||
public class TextureSpriteCallback
|
||||
{
|
||||
private ResourceLocation location;
|
||||
private TextureAtlasSprite sprite;
|
||||
|
||||
public TextureSpriteCallback(ResourceLocation loc) {
|
||||
this.location = loc;
|
||||
public TextureSpriteCallback(ResourceLocation loc)
|
||||
{
|
||||
location = loc;
|
||||
}
|
||||
|
||||
public void stitch(TextureMap map) {
|
||||
this.sprite = map.registerSprite(location);
|
||||
public void stitch(TextureMap map)
|
||||
{
|
||||
sprite = map.registerSprite(location);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user