mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-26 14:53:14 +00:00
Fix ItemBlock face side, add Model Particle, fix texture loading conflict with DragonApi (#212)
Co-authored-by: MalTeeez <[email protected]>
This commit is contained in:
1 parent
66f07dafbf
commit
532e9a4e00
23 files changed
+459
-49
No files matched your search
@@ -45,7 +45,7 @@ public class ClientProxy extends CommonProxy {
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
super.preInit(event);
|
||||
|
||||
RenderingRegistry.registerBlockHandler(new ModelISBRH());
|
||||
RenderingRegistry.registerBlockHandler(ModelISBRH.INSTANCE);
|
||||
|
||||
// External model loader handlers. For the low low price of calling this method (and having your jar scanned),
|
||||
// you too can automatically load textures for your models!
|
||||
@@ -85,7 +85,7 @@ public class ClientProxy extends CommonProxy {
|
||||
if (block.getRenderType() == ModelISBRH.JSON_ISBRH_ID) {
|
||||
Item item = Item.getItemFromBlock(block);
|
||||
if (item != null) {
|
||||
MinecraftForgeClient.registerItemRenderer(item, new ModelISBRH());
|
||||
MinecraftForgeClient.registerItemRenderer(item, ModelISBRH.INSTANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.block.BlockTest;
|
||||
import com.gtnewhorizon.gtnhlib.block.BlockTestTint;
|
||||
import com.gtnewhorizon.gtnhlib.block.BlockTestTintMul;
|
||||
import com.gtnewhorizon.gtnhlib.brigadier.BrigadierApi;
|
||||
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;
|
||||
import com.gtnewhorizon.gtnhlib.eventbus.AutoEventBus;
|
||||
@@ -45,6 +46,7 @@ public class CommonProxy {
|
||||
if (GTNHLibConfig.enableTestBlocks) {
|
||||
GameRegistry.registerBlock(new BlockTest(), "model_test");
|
||||
GameRegistry.registerBlock(new BlockTestTint(), "model_test_tint");
|
||||
GameRegistry.registerBlock(new BlockTestTintMul(), "model_test_tint_mul");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public class BlockTestTint extends Block implements IBlockColor {
|
||||
|
||||
public BlockTestTint() {
|
||||
super(Material.wood);
|
||||
setHardness(2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.gtnewhorizon.gtnhlib.block;
|
||||
|
||||
import static com.gtnewhorizon.gtnhlib.client.model.ModelISBRH.JSON_ISBRH_ID;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.color.IBlockColor;
|
||||
|
||||
public class BlockTestTintMul extends Block implements IBlockColor {
|
||||
|
||||
public BlockTestTintMul() {
|
||||
super(Material.wood);
|
||||
setHardness(2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onBlockPlaced(@NotNull World worldIn, int x, int y, int z, int side, float subX, float subY, float subZ,
|
||||
int meta) {
|
||||
|
||||
// Face NORTH if placed up or down
|
||||
final var s = ForgeDirection.getOrientation(side);
|
||||
if (s == ForgeDirection.UP || s == ForgeDirection.DOWN) return 2;
|
||||
|
||||
// Face the placed side
|
||||
return side - 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return JSON_ISBRH_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int colorMultiplier(IBlockAccess world, int x, int y, int z, int tintIndex) {
|
||||
switch (tintIndex) {
|
||||
case 0:
|
||||
return 0xFF0000; // red
|
||||
case 1:
|
||||
return 0x00FF00; // green
|
||||
case 2:
|
||||
return 0x0000FF; // blue
|
||||
case 3:
|
||||
return 0xFFFF00; // yellow
|
||||
case 4:
|
||||
return 0xFF00FF; // purple
|
||||
case 5:
|
||||
return 0x00FFFF; // cyan
|
||||
default:
|
||||
return 0xFFFFFF;// white
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int colorMultiplier(ItemStack stack, int tintIndex) {
|
||||
// Like block
|
||||
return colorMultiplier(null, 0, 0, 0, tintIndex);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,11 @@ import static com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.NormI8.unpac
|
||||
import static com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.NormI8.unpackZ;
|
||||
import static com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing.DIRECTIONS;
|
||||
import static java.lang.Math.max;
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.ENTITY;
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED;
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON;
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.FIRST_PERSON_MAP;
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.INVENTORY;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -35,6 +40,8 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
@ThreadSafeISBRH(perThread = true)
|
||||
public class ModelISBRH implements ISimpleBlockRenderingHandler, IItemRenderer {
|
||||
|
||||
public static final ModelISBRH INSTANCE = new ModelISBRH();
|
||||
|
||||
/**
|
||||
* Any blocks using a JSON model should return this for {@link Block#getRenderType()}.
|
||||
*/
|
||||
@@ -98,7 +105,7 @@ public class ModelISBRH implements ISimpleBlockRenderingHandler, IItemRenderer {
|
||||
return rendered;
|
||||
}
|
||||
|
||||
protected void renderQuad(ModelQuadView quad, float x, float y, float z, Tessellator tessellator,
|
||||
public void renderQuad(ModelQuadView quad, float x, float y, float z, Tessellator tessellator,
|
||||
@Nullable IIcon overrideIcon) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
tessellator.addVertexWithUV(
|
||||
@@ -110,7 +117,7 @@ public class ModelISBRH implements ISimpleBlockRenderingHandler, IItemRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private int getLightMap(Block block, ModelQuadView quad, ModelQuadFacing dir, IBlockAccess world, int x, int y,
|
||||
public int getLightMap(Block block, ModelQuadView quad, ModelQuadFacing dir, IBlockAccess world, int x, int y,
|
||||
int z, RenderBlocks rb) {
|
||||
// If the face is aligned or external, pick light outside
|
||||
final float avgPos = getAveragePos(quad, dir);
|
||||
@@ -228,31 +235,59 @@ public class ModelISBRH implements ISimpleBlockRenderingHandler, IItemRenderer {
|
||||
|
||||
final float shade = diffuseLight(quad.getComputedFaceNormal());
|
||||
tesselator.setColorOpaque_F(r * shade, g * shade, b * shade);
|
||||
renderQuad(quad, -0.5f, -0.5f, -0.5f, tesselator, null);
|
||||
renderQuad(quad, 0f, 0f, 0f, tesselator, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Rotated to exact side
|
||||
GL11.glRotated(-90f, 0f, 1f, 0f);
|
||||
|
||||
// TODO: Use BlockBench display transforms provided in '{}.display'
|
||||
// Translated to vanilla position
|
||||
if (type == ItemRenderType.EQUIPPED) {
|
||||
GL11.glTranslated(0.5f, 0.5f, -0.5f);
|
||||
}
|
||||
if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
|
||||
GL11.glTranslated(0.5f, 0.5f, -0.5f);
|
||||
}
|
||||
if (type == ItemRenderType.ENTITY) {
|
||||
// No op
|
||||
}
|
||||
if (type == ItemRenderType.INVENTORY) {
|
||||
// No op
|
||||
}
|
||||
// Apply ItemBlock BlockBench Display
|
||||
applyItemDisplay(type);
|
||||
|
||||
tesselator.draw();
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private void applyItemDisplay(ItemRenderType type) {
|
||||
|
||||
// BlockBench to Position
|
||||
if (type == EQUIPPED) {
|
||||
// Rotated to correct Face
|
||||
GL11.glRotatef(180f, 0f, 1f, 0f);
|
||||
// Translated to correct position
|
||||
GL11.glTranslated(-1f, 0f, -1f);
|
||||
}
|
||||
|
||||
if (type == EQUIPPED_FIRST_PERSON || type == FIRST_PERSON_MAP) {
|
||||
// Rotated to correct Face
|
||||
GL11.glRotatef(90f, 0f, 1f, 0f);
|
||||
// Translated to correct position
|
||||
GL11.glTranslated(-1f, 0f, 0f);
|
||||
}
|
||||
|
||||
if (type == ENTITY) {
|
||||
GL11.glTranslated(-0.5f, -0.5f, -0.5f);
|
||||
}
|
||||
|
||||
if (type == INVENTORY) {
|
||||
// Translated to correct position
|
||||
GL11.glTranslated(0f, -0.1f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public IIcon getParticleIcon(Block block, IBlockAccess world, int x, int y, int z, int meta) {
|
||||
final var model = getModel(world, block, meta, x, y, z);
|
||||
return model.getParticle(meta, RAND);
|
||||
}
|
||||
|
||||
public boolean isMissingIcon(IIcon icon) {
|
||||
if (icon == null) return false;
|
||||
|
||||
String name = icon.getIconName();
|
||||
if (name == null) return false;
|
||||
|
||||
if (name.equals("missingno")) return false;
|
||||
|
||||
return !name.startsWith("MISSING_ICON_BLOCK_");
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,12 @@ import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelDeserializer.Position;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
@@ -59,4 +61,17 @@ public interface BakedModel {
|
||||
/// @return A list of quads from the model. These are *not* adjusted for the given xyz - that is up to the renderer.
|
||||
List<ModelQuadView> getQuads(@Nullable IBlockAccess world, int x, int y, int z, Block block, int meta,
|
||||
ModelQuadFacing dir, Random random, int color, @Nullable Supplier<ModelQuadViewMutable> quadPool);
|
||||
|
||||
/**
|
||||
* Returns the display transformation for a specific position and metadata. Used to position/rotate/scale the model
|
||||
* when rendering in different contexts (e.g., first person, third person, GUI).
|
||||
*
|
||||
* @param pos The display position (e.g., GUI, first person right hand).
|
||||
* @param meta The metadata of the block.
|
||||
* @param random Random generator to use for variations.
|
||||
* @return The {@link Position.ModelDisplay} containing rotation, translation, and scale.
|
||||
*/
|
||||
Position.ModelDisplay getDisplay(Position pos, int meta, Random random);
|
||||
|
||||
IIcon getParticle(int meta, Random random);
|
||||
}
|
||||
@@ -5,11 +5,13 @@ import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.Weighted;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelDeserializer.Position;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
@@ -30,6 +32,16 @@ public final class MonopartModel implements BakedModel {
|
||||
return Weighted.selectOne(models, random).getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position.ModelDisplay getDisplay(Position pos, int meta, Random random) {
|
||||
return Weighted.selectOne(models, random).getDisplay(pos, meta, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getParticle(int meta, Random random) {
|
||||
return Weighted.selectOne(models, random).getParticle(meta, random);
|
||||
}
|
||||
|
||||
public ObjectArrayList<Weighted<BakedModel>> models() {
|
||||
return models;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,13 @@ import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelDeserializer.Position;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.state.MultipartState.Case.Condition;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
@@ -46,6 +49,26 @@ public final class MultipartModel implements BakedModel {
|
||||
return quads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position.ModelDisplay getDisplay(Position pos, int meta, Random random) {
|
||||
for (Map.Entry<Condition, BakedModel> entry : piles.entrySet()) {
|
||||
if (entry.getKey().matches(stateMap(meta))) {
|
||||
return entry.getValue().getDisplay(pos, meta, random);
|
||||
}
|
||||
}
|
||||
return Position.ModelDisplay.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getParticle(int meta, Random random) {
|
||||
for (Map.Entry<Condition, BakedModel> entry : piles.entrySet()) {
|
||||
if (entry.getKey().matches(stateMap(meta))) {
|
||||
return entry.getValue().getParticle(meta, random);
|
||||
}
|
||||
}
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("missingno");
|
||||
}
|
||||
|
||||
private static Map<String, String> stateMap(int meta) {
|
||||
final var m = new HashMap<String, String>();
|
||||
m.put("meta", Integer.toString(meta));
|
||||
|
||||
@@ -16,10 +16,12 @@ import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelDeserializer.Position;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
@@ -28,15 +30,20 @@ import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
|
||||
|
||||
public final class PileOfQuads implements BakedModel {
|
||||
|
||||
public static final PileOfQuads BLANK = new PileOfQuads(new HashMap<>());
|
||||
public static final PileOfQuads BLANK = new PileOfQuads(new HashMap<>(), new HashMap<>(), null);
|
||||
private final SidedQuadStore sidedQuadStore;
|
||||
private final Map<Position, Position.ModelDisplay> display;
|
||||
private final IIcon particle;
|
||||
|
||||
public PileOfQuads(SidedQuadStore sidedQuadStore) {
|
||||
public PileOfQuads(SidedQuadStore sidedQuadStore, Map<Position, Position.ModelDisplay> display, IIcon particle) {
|
||||
this.sidedQuadStore = sidedQuadStore;
|
||||
this.display = display;
|
||||
this.particle = particle;
|
||||
}
|
||||
|
||||
public PileOfQuads(Map<ModelQuadFacing, ArrayList<ModelQuadView>> sidedQuadStore) {
|
||||
this(new SidedQuadStore(sidedQuadStore));
|
||||
public PileOfQuads(Map<ModelQuadFacing, ArrayList<ModelQuadView>> sidedQuadStore,
|
||||
Map<Position, Position.ModelDisplay> display, IIcon particle) {
|
||||
this(new SidedQuadStore(sidedQuadStore), display, particle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,6 +52,16 @@ public final class PileOfQuads implements BakedModel {
|
||||
return sidedQuadStore.getQuads(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position.ModelDisplay getDisplay(Position pos, int meta, Random random) {
|
||||
return display.getOrDefault(pos, Position.ModelDisplay.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getParticle(int meta, Random random) {
|
||||
return particle;
|
||||
}
|
||||
|
||||
public static class SidedQuadStore {
|
||||
|
||||
private static final ObjectImmutableList<ModelQuadView> EMPTY = ObjectImmutableList.of();
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.model.loading;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
|
||||
public interface BackingResourceManager {
|
||||
|
||||
List<IResourcePack> nhlib$getResourcePacks();
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.model.loading;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
|
||||
public interface GlobalResourceManager {
|
||||
|
||||
Map<String, IResourceManager> nhlib$getDomainResourceManagers();
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class ModelDeserializer implements JsonDeserializer<JSONModel> {
|
||||
}
|
||||
|
||||
private static Vector3f loadVec3(JsonObject in, String name, Vector3f defaultv) {
|
||||
if (!in.isJsonArray()) return defaultv;
|
||||
if (!in.isJsonObject() || !in.has(name)) return defaultv;
|
||||
return loadVec3(in, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import static it.unimi.dsi.fastutil.objects.Object2ObjectMaps.unmodifiable;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.FallbackResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
@@ -146,14 +146,24 @@ public class ModelRegistry {
|
||||
STATE_MODEL_MAP_CACHE.clear();
|
||||
JSON_MODEL_CACHE.clear();
|
||||
|
||||
if (autoTextureLoading) detectAndLoadTextures();
|
||||
if (!(irm instanceof GlobalResourceManager manager)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (autoTextureLoading) detectAndLoadTextures(manager);
|
||||
}
|
||||
|
||||
private void detectAndLoadTextures() {
|
||||
// Scan resourcepacks for model files
|
||||
private void detectAndLoadTextures(GlobalResourceManager manager) {
|
||||
// Scan resource packs for model files
|
||||
final var domains = manager.nhlib$getDomainResourceManagers();
|
||||
final var resourcePacks = new ObjectOpenHashSet<IResourcePack>();
|
||||
Minecraft.getMinecraft().getResourcePackRepository().getRepositoryEntries()
|
||||
.forEach(e -> resourcePacks.add(e.getResourcePack()));
|
||||
|
||||
for (var entry : domains.entrySet()) {
|
||||
var files = entry.getValue();
|
||||
if (files instanceof FallbackResourceManager) {
|
||||
resourcePacks.addAll(((BackingResourceManager) files).nhlib$getResourcePacks());
|
||||
}
|
||||
}
|
||||
|
||||
final var texturesToLoad = new ObjectArrayList<String>();
|
||||
for (var pack : resourcePacks) {
|
||||
@@ -164,8 +174,8 @@ public class ModelRegistry {
|
||||
&& !PERMITTED_MODIDS.contains(fmlch.getFMLContainer().getModId()))
|
||||
continue;
|
||||
|
||||
final var texs = mrp.nhlib$getReferencedTextures(reader -> GSON.fromJson(reader, JSONModel.class));
|
||||
texturesToLoad.addAll(texs);
|
||||
final var texture = mrp.nhlib$getReferencedTextures(reader -> GSON.fromJson(reader, JSONModel.class));
|
||||
texturesToLoad.addAll(texture);
|
||||
}
|
||||
|
||||
EventHandler.texturesToLoad = texturesToLoad;
|
||||
@@ -179,7 +189,9 @@ public class ModelRegistry {
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void onTextureStitch(TextureStitchEvent.Pre event) {
|
||||
for (var tex : texturesToLoad) event.map.registerIcon(tex.replaceFirst("^minecraft:", ""));
|
||||
for (var texture : texturesToLoad) {
|
||||
event.map.registerIcon(texture.replaceFirst("^minecraft:", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -209,7 +210,7 @@ public class JSONModel implements UnbakedModel {
|
||||
}
|
||||
|
||||
// Add them to the model
|
||||
return new PileOfQuads(sidedQuadStore);
|
||||
return new PileOfQuads(sidedQuadStore, this.display, this.getParticle());
|
||||
}
|
||||
|
||||
// TODO fix
|
||||
@@ -270,6 +271,18 @@ public class JSONModel implements UnbakedModel {
|
||||
}
|
||||
}
|
||||
|
||||
private IIcon getParticle() {
|
||||
String key = "particle";
|
||||
if (!textures.containsKey(key) && !textures.isEmpty()) {
|
||||
key = textures.keySet().iterator().next();
|
||||
}
|
||||
|
||||
String texName = textures.getOrDefault(key, "missingno");
|
||||
texName = texName.replaceFirst("^minecraft:", "");
|
||||
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(texName);
|
||||
}
|
||||
|
||||
public Map<String, String> getTextures() {
|
||||
return Object2ObjectMaps.unmodifiable(textures);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,17 @@ public enum Mixins implements IMixins {
|
||||
BRIGADIER(Side.COMMON, "MixinCommandHandler", "MixinCommandHelp"),
|
||||
FONT_RENDERER(new MixinBuilder("Font rendering replacements").addClientMixins("MixinFontRenderer")
|
||||
.setPhase(Phase.EARLY).setApplyIf(() -> GTNHLibConfig.enableFontRendererMixin)),
|
||||
MODEL_TEXTURE_LOADING(new MixinBuilder("Automatically load model textures")
|
||||
.addClientMixins("models.MixinFileResourcePack", "models.MixinFolderResourcePack").setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> GTNHLibConfig.autoTextureLoading)),
|
||||
MODEL_TEXTURE_LOADING(
|
||||
new MixinBuilder("Automatically load model textures")
|
||||
.addClientMixins(
|
||||
"models.FRMAccessor",
|
||||
"models.MixinFileResourcePack",
|
||||
"models.MixinFolderResourcePack",
|
||||
"models.SRRMAccessor")
|
||||
.setPhase(Phase.EARLY).setApplyIf(() -> GTNHLibConfig.autoTextureLoading)),
|
||||
BLOCK_PARTICLE(
|
||||
new MixinBuilder("Automatically override model block particle").addClientMixins("models.MixinBlockParticle")
|
||||
.setPhase(Phase.EARLY).setApplyIf(() -> GTNHLibConfig.autoTextureLoading)),
|
||||
DYNAMIC_BLOCK_SOUNDS(new MixinBuilder("Dynamic block sounds")
|
||||
.addCommonMixins(
|
||||
"block_sounds.MixinEntity",
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.gtnewhorizon.gtnhlib.mixins.early.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.resources.FallbackResourceManager;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.BackingResourceManager;
|
||||
|
||||
@Mixin(FallbackResourceManager.class)
|
||||
public interface FRMAccessor extends BackingResourceManager {
|
||||
|
||||
@Override
|
||||
@Accessor("resourcePacks")
|
||||
List<IResourcePack> nhlib$getResourcePacks();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.gtnewhorizon.gtnhlib.mixins.early.models;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH;
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
|
||||
@Mixin(Block.class)
|
||||
public class MixinBlockParticle {
|
||||
|
||||
@WrapMethod(method = "getIcon(Lnet/minecraft/world/IBlockAccess;IIII)Lnet/minecraft/util/IIcon;")
|
||||
private IIcon nhlib$wrapGetIcon(IBlockAccess world, int x, int y, int z, int side, Operation<IIcon> original) {
|
||||
Block block = (Block) (Object) this;
|
||||
|
||||
IIcon icon = original.call(world, x, y, z, side);
|
||||
if (ModelISBRH.INSTANCE.isMissingIcon(icon)) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
if (block.getRenderType() == ModelISBRH.JSON_ISBRH_ID) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
return ModelISBRH.INSTANCE.getParticleIcon(block, world, x, y, z, meta);
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
@WrapMethod(method = "getIcon(II)Lnet/minecraft/util/IIcon;")
|
||||
private IIcon nhlib$wrapGetIcon(int side, int meta, Operation<IIcon> original) {
|
||||
Block block = (Block) (Object) this;
|
||||
|
||||
IIcon icon = original.call(meta, side);
|
||||
if (ModelISBRH.INSTANCE.isMissingIcon(icon)) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
if (block.getRenderType() == ModelISBRH.JSON_ISBRH_ID) {
|
||||
return ModelISBRH.INSTANCE.getParticleIcon(block, null, 0, 0, 0, meta);
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.gtnewhorizon.gtnhlib.mixins.early.models;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.SimpleReloadableResourceManager;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.GlobalResourceManager;
|
||||
|
||||
@Mixin(SimpleReloadableResourceManager.class)
|
||||
public interface SRRMAccessor extends GlobalResourceManager {
|
||||
|
||||
@Override
|
||||
@Accessor("domainResourceManagers")
|
||||
Map<String, IResourceManager> nhlib$getDomainResourceManagers();
|
||||
}
|
||||
Reference in new issue
Block a user