-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c0b975
commit c510bcd
Showing
10 changed files
with
289 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/main/java/gregtech/client/model/modelfactories/SurfaceRockBakedModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package gregtech.client.model.modelfactories; | ||
|
||
import gregtech.api.unification.material.Material; | ||
import gregtech.api.unification.material.info.MaterialIconSet; | ||
import gregtech.api.unification.material.info.MaterialIconType; | ||
import gregtech.client.model.ModelFactory; | ||
import gregtech.common.blocks.BlockSurfaceRock; | ||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.block.model.*; | ||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.item.ItemBlock; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.client.model.ModelLoader; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.lwjgl.util.vector.Vector3f; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import javax.vecmath.Matrix4f; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class SurfaceRockBakedModel implements IBakedModel { | ||
|
||
public static final SurfaceRockBakedModel INSTANCE = new SurfaceRockBakedModel(); | ||
|
||
private final Map<MaterialIconSet, Map<EnumFacing, BakedQuad>> materialFaces; | ||
private final ThreadLocal<TextureAtlasSprite> particle; | ||
|
||
private SurfaceRockBakedModel() { | ||
this.materialFaces = new Object2ObjectOpenHashMap<>(); | ||
this.particle = ThreadLocal.withInitial(() -> Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite()); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) { | ||
List<BakedQuad> quads = new ArrayList<>(); | ||
if (side == null) return quads; | ||
if (state != null) { | ||
Material material = state.getValue(((BlockSurfaceRock) state.getBlock()).variantProperty); | ||
Map<EnumFacing, BakedQuad> materialFace = materialFaces.get(material.getMaterialIconSet()); | ||
if (materialFace == null) { | ||
materialFaces.put(material.getMaterialIconSet(), materialFace = new Object2ObjectOpenHashMap<>()); | ||
} | ||
BakedQuad materialFaceQuad = materialFace.get(side); | ||
if (materialFaceQuad == null) { | ||
materialFace.put(side, materialFaceQuad = ModelFactory.getBakery().makeBakedQuad( | ||
new Vector3f(0F, 0F, 0F), | ||
new Vector3f(16F, 16F, 16F), | ||
new BlockPartFace(side, 1, "", new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F, 0.0F, 0.0F, 16.0F, 16.0F }, 0)), | ||
ModelLoader.defaultTextureGetter().apply(MaterialIconType.block.getBlockPath(material.getMaterialIconSet())), | ||
side, | ||
ModelRotation.X0_Y0, | ||
null, | ||
true, | ||
true)); | ||
} | ||
quads.add(materialFaceQuad); | ||
particle.set(materialFaceQuad.getSprite()); | ||
} else { | ||
ItemStack stack = SurfaceRockBlockItemOverride.INSTANCE.stack.get(); | ||
if (!stack.isEmpty()) { | ||
BlockSurfaceRock rock = (BlockSurfaceRock) ((ItemBlock) stack.getItem()).getBlock(); | ||
IBlockState compressedState = rock.getDefaultState().withProperty(rock.variantProperty, rock.variantProperty.getAllowedValues().get(stack.getMetadata())); | ||
for (EnumFacing face : EnumFacing.VALUES) { | ||
quads.addAll(getQuads(compressedState, face, rand)); | ||
} | ||
} | ||
} | ||
return quads; | ||
} | ||
|
||
@Override | ||
public boolean isAmbientOcclusion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isGui3d() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isBuiltInRenderer() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public TextureAtlasSprite getParticleTexture() { | ||
return particle.get(); | ||
} | ||
|
||
@Override | ||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) { | ||
return Pair.of(this, ModelFactory.getBlockTransform(cameraTransformType).getMatrix()); | ||
} | ||
|
||
@Override | ||
public ItemOverrideList getOverrides() { | ||
return SurfaceRockBlockItemOverride.INSTANCE; | ||
} | ||
|
||
private static class SurfaceRockBlockItemOverride extends ItemOverrideList { | ||
|
||
private static final SurfaceRockBlockItemOverride INSTANCE = new SurfaceRockBlockItemOverride(); | ||
|
||
private final ThreadLocal<ItemStack> stack = ThreadLocal.withInitial(() -> ItemStack.EMPTY); | ||
|
||
@Override | ||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { | ||
this.stack.set(stack); | ||
return originalModel; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.