mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-18 14:35:09 +01:00
feat: fake block models
- Instead of registering a block for the jukebox top, we can now render models without a block being registered at all - This opens up a lot of interesting new visuals in the near future :)
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package eu.midnightdust.visualoverhaul;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.model.ModelNameSupplier;
|
||||
import net.minecraft.client.model.SpriteGetter;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.render.model.*;
|
||||
import net.minecraft.client.render.model.json.JsonUnbakedModel;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.LOGGER;
|
||||
|
||||
public class FakeBlocks {
|
||||
private static final Baker BAKER = new FakeBaker();
|
||||
private static final Map<Identifier, BakedModel> FAKE_MODELS = new HashMap<>();
|
||||
private static final BlockRenderManager renderManager = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
|
||||
public static void reload(ResourceManager manager) {
|
||||
manager.findResources("models", path -> path.getPath().startsWith("models/fakeblock") && path.getPath().endsWith(".json")).forEach((id, resource) -> {
|
||||
try {
|
||||
JsonUnbakedModel unbaked = JsonUnbakedModel.deserialize(resource.getReader());
|
||||
BakedModel baked = unbaked.bake(new ModelTextures.Builder().addFirst(unbaked.getTextures()).build(() -> "#fakeblock"), BAKER,
|
||||
new ModelBakeSettings(){}, Boolean.TRUE.equals(unbaked.getAmbientOcclusion()), unbaked.getGuiLight() != null && unbaked.getGuiLight().isSide(), unbaked.getTransformation());
|
||||
Identifier fakeId = Identifier.of(id.getNamespace(), id.getPath().replace("models/fakeblock/", "").replace(".json", ""));
|
||||
FAKE_MODELS.put(fakeId, baked);
|
||||
if (VOConfig.debug) LOGGER.info("Successfully loaded fake block model: {}", fakeId);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error occurred while loading fake block model {}", id.toString(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void renderFakeBlock(Identifier id, BlockPos pos, BlockRenderView world, MatrixStack matrices, VertexConsumer vertexConsumer) {
|
||||
renderManager.getModelRenderer().render(world, FAKE_MODELS.get(id), Blocks.DIRT.getDefaultState(), // State is just needed for a few generic checks
|
||||
pos, matrices, vertexConsumer, false, Random.create(), 0, OverlayTexture.DEFAULT_UV);
|
||||
}
|
||||
|
||||
public static class FakeBaker implements Baker {
|
||||
public BakedModel bake(Identifier id, ModelBakeSettings settings) {
|
||||
return null; // Not used in Json models, so we just leave ít like this and cross our fingers.
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpriteGetter getSpriteGetter() {
|
||||
return new SpriteGetter() {
|
||||
static final SpriteIdentifier MISSING = new SpriteIdentifier(Identifier.ofVanilla("textures/atlas/blocks.png"), Identifier.ofVanilla("missingno"));
|
||||
|
||||
@Override public Sprite get(SpriteIdentifier spriteId) { return spriteId.getSprite(); }
|
||||
@Override public Sprite getMissing(String textureId) { return MISSING.getSprite(); }
|
||||
};
|
||||
}
|
||||
|
||||
public ModelNameSupplier getModelNameSupplier() { return () -> "#fakeblock"; }
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.LOGGER;
|
||||
import static eu.midnightdust.visualoverhaul.util.VOColorUtil.alphaAndBrightness;
|
||||
|
||||
public class IconicButtons {
|
||||
@@ -126,7 +127,7 @@ public class IconicButtons {
|
||||
ICONS.put(iconId, textureId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogManager.getLogger("Iconic").error("Error occurred while loading texture.properties {}", id.toString(), e);
|
||||
LOGGER.error("Error occurred while loading texture.properties for button icon {}", id.toString(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package eu.midnightdust.visualoverhaul;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.MOD_ID;
|
||||
|
||||
@@ -11,8 +10,6 @@ public class VisualOverhaulClient {
|
||||
public static int grassColor = -8934609;
|
||||
public static int potionColor = -13083194;
|
||||
|
||||
public static Block JukeBoxTop;
|
||||
|
||||
public static void onInitializeClient() {
|
||||
VOConfig.init(MOD_ID, VOConfig.class);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package eu.midnightdust.visualoverhaul;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
@@ -12,6 +14,7 @@ import java.util.UUID;
|
||||
|
||||
public class VisualOverhaulCommon {
|
||||
public static final String MOD_ID = "visualoverhaul";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("VisualOverhaul");
|
||||
public static final List<UUID> playersWithMod = new ArrayList<>();
|
||||
public static final Map<BlockPos, ItemStack> jukeboxItems = new HashMap<>();
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package eu.midnightdust.visualoverhaul.block;
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.id;
|
||||
|
||||
public class JukeboxTop extends Block {
|
||||
private static final BooleanProperty HAS_RECORD = Properties.HAS_RECORD;
|
||||
|
||||
public JukeboxTop() {
|
||||
super(AbstractBlock.Settings.copy(Blocks.JUKEBOX).registryKey(RegistryKey.of(RegistryKeys.BLOCK, id("jukebox_top"))));
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(HAS_RECORD,false));
|
||||
}
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(HAS_RECORD);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user