some new features

- Added new green screen block with glow
- Added GreenScreenBlockModel for fine-tune the block
- Diffuse Shading and Ambient Occlusion has been removed from GreenScreenBlockModel
- GreenScreenBlockModel also ignores the lightmap
This commit is contained in:
Timofey Gelazoniya 2022-05-21 08:32:26 +03:00
parent d58f217d23
commit 85a48ba186
Signed by: zeldon
GPG Key ID: 047886915281DD2A
14 changed files with 224 additions and 28 deletions

View File

@ -3,7 +3,7 @@
This mod just adds a green block to the miscellaneous tab. This mod just adds a green block to the miscellaneous tab.
# Download # Download
Download last version from [releases](https://github.com/xzeldon/green-screen-mod/releases). Download last version from [releases](https://github.com/xzeldon/GreenScreenMod/releases).
# Install # Install
Place `.jar` file to the `mods` folder. Download and install [Fabric](https://fabricmc.net/use/installer/) then place `.jar` file to the `mods` folder.

View File

@ -3,17 +3,14 @@ package ru.xzeldon.greenscreenmod;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ru.xzeldon.greenscreenmod.block.ModBlocks; import ru.xzeldon.greenscreenmod.block.GreenScreenBlocks;
public class GreenScreenMod implements ModInitializer { public class GreenScreenMod implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final String MOD_ID = "greenscreenmod"; public static final String MOD_ID = "greenscreenmod";
public static final Logger LOGGER = LoggerFactory.getLogger("greenscreenmod"); public static final Logger LOGGER = LoggerFactory.getLogger("greenscreenmod");
@Override @Override
public void onInitialize() { public void onInitialize() {
ModBlocks.registerModBlocks(); GreenScreenBlocks.registerBlocks();
} }
} }

View File

@ -0,0 +1,12 @@
package ru.xzeldon.greenscreenmod;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import ru.xzeldon.greenscreenmod.model.GreenScreenModelProvider;
public class GreenScreenModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> new GreenScreenModelProvider());
}
}

View File

@ -1,17 +1,28 @@
package ru.xzeldon.greenscreenmod.block; package ru.xzeldon.greenscreenmod.block;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import ru.xzeldon.greenscreenmod.GreenScreenMod; import ru.xzeldon.greenscreenmod.GreenScreenMod;
import net.minecraft.block.AbstractGlassBlock; import ru.xzeldon.greenscreenmod.block.custom.GreenScreenBlock;
public class ModBlocks { public class GreenScreenBlocks {
public static final Block GREEN_SCREEN_BLOCK = registerBlock("green_screen_block", new GreenScreenBlock(), ItemGroup.MISC); public static final Block GREEN_SCREEN_BLOCK = registerBlock("green_screen_block",
new Block(FabricBlockSettings.of(Material.METAL)
.breakInstantly()
), ItemGroup.MISC);
public static final Block GREEN_SCREEN_BLOCK_DIM = registerBlock("green_screen_block_dim",
new Block(FabricBlockSettings.of(Material.METAL)
.breakInstantly()
.luminance(15)
), ItemGroup.MISC);
private static Block registerBlock(String name, Block block, ItemGroup group) { private static Block registerBlock(String name, Block block, ItemGroup group) {
registerBlockItem(name, block, group); registerBlockItem(name, block, group);
@ -23,7 +34,7 @@ public class ModBlocks {
new BlockItem(block, new FabricItemSettings().group(group))); new BlockItem(block, new FabricItemSettings().group(group)));
} }
public static void registerModBlocks() { public static void registerBlocks() {
GreenScreenMod.LOGGER.info("Registering ModBlocks for " + GreenScreenMod.MOD_ID); GreenScreenMod.LOGGER.info("Registering ModBlocks for " + GreenScreenMod.MOD_ID);
} }
} }

View File

@ -1,4 +1,4 @@
package ru.xzeldon.greenscreenmod.block; package ru.xzeldon.greenscreenmod.block.custom;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -8,14 +8,12 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
public class GreenScreenBlock extends Block { public class GreenScreenBlock extends Block {
public GreenScreenBlock() { public GreenScreenBlock(Settings settings) {
super(FabricBlockSettings.of(Material.METAL) super(settings);
.breakInstantly()
);
} }
@Override @Override
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) { public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
return 1; return 1.0F;
} }
} }

View File

@ -0,0 +1,7 @@
package ru.xzeldon.greenscreenmod.block.custom;
public class GreenScreenBlockDim extends GreenScreenBlock {
public GreenScreenBlockDim(Settings settings) {
super(settings);
}
}

View File

@ -0,0 +1,133 @@
package ru.xzeldon.greenscreenmod.model;
import com.mojang.datafixers.util.Pair;
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.*;
import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
public class GreenScreenBlockModel implements UnbakedModel, BakedModel, FabricBakedModel {
private static final SpriteIdentifier SPRITE_ID = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("greenscreenmod:block/green_screen_block"));
private static final Identifier DEFAULT_BLOCK_MODEL = new Identifier("minecraft:block/block");
private final Sprite[] SPRITES = new Sprite[1];
private static final Renderer renderer = RendererAccess.INSTANCE.getRenderer();
private ModelTransformation transformation;
private Mesh mesh;
@Override
public boolean isVanillaAdapter() {
return false;
}
@Override
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
context.meshConsumer().accept(mesh);
}
@Override
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
context.meshConsumer().accept(mesh);
}
@Override
public Collection<Identifier> getModelDependencies() {
return List.of(DEFAULT_BLOCK_MODEL);
}
@Override
public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier, UnbakedModel> unbakedModelGetter, Set<Pair<String, String>> unresolvedTextureReferences) {
return List.of(SPRITE_ID);
}
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
JsonUnbakedModel defaultBlockModel = (JsonUnbakedModel) loader.getOrLoadModel(DEFAULT_BLOCK_MODEL);
transformation = defaultBlockModel.getTransformations();
SPRITES[0] = textureGetter.apply(SPRITE_ID);
RenderMaterial material = renderer.materialFinder()
.disableAo(0, true)
.disableDiffuse(0, true)
.emissive(0, true)
.find();
MeshBuilder builder = renderer.meshBuilder();
QuadEmitter emitter = builder.getEmitter();
for (Direction direction : Direction.values()) {
emitter.square(direction, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f);
emitter.spriteBake(0, SPRITES[0], MutableQuadView.BAKE_LOCK_UV);
emitter.spriteColor(0, -1, -1, -1, -1);
emitter.material(material);
emitter.emit();
}
mesh = builder.build();
return this;
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction face, Random random) {
return Collections.emptyList();
}
@Override
public boolean useAmbientOcclusion() {
return false;
}
@Override
public boolean hasDepth() {
return false;
}
@Override
public boolean isSideLit() {
return true;
}
@Override
public boolean isBuiltin() {
return false;
}
@Override
public Sprite getParticleSprite() {
return SPRITES[0];
}
@Override
public ModelTransformation getTransformation() {
return transformation;
}
@Override
public ModelOverrideList getOverrides() {
return ModelOverrideList.EMPTY;
}
}

View File

@ -0,0 +1,34 @@
package ru.xzeldon.greenscreenmod.model;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.model.ModelProviderContext;
import net.fabricmc.fabric.api.client.model.ModelProviderException;
import net.fabricmc.fabric.api.client.model.ModelResourceProvider;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import ru.xzeldon.greenscreenmod.GreenScreenMod;
@Environment(EnvType.CLIENT)
public class GreenScreenModelProvider implements ModelResourceProvider {
public static final Identifier GREEN_SCREEN_MODEL = new Identifier("greenscreenmod:block/green_screen_block");
public static final Identifier GREEN_SCREEN_MODEL_DIM = new Identifier("greenscreenmod:block/green_screen_block_dim");
public static final Identifier GREEN_SCREEN_MODEL_ITEM = new Identifier("greenscreenmod:item/green_screen_block");
public static final Identifier GREEN_SCREEN_MODEL_ITEM_DIM = new Identifier("greenscreenmod:item/green_screen_block_dim");
@Override
public @Nullable UnbakedModel loadModelResource(Identifier resourceId, ModelProviderContext context) throws ModelProviderException {
if (
resourceId.equals(GREEN_SCREEN_MODEL) ||
resourceId.equals(GREEN_SCREEN_MODEL_ITEM) ||
resourceId.equals(GREEN_SCREEN_MODEL_DIM) ||
resourceId.equals(GREEN_SCREEN_MODEL_ITEM_DIM)
) {
return new GreenScreenBlockModel();
} else {
return null;
}
}
}

View File

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "greenscreenmod:block/green_screen_block"
}
}
}

View File

@ -1,3 +1,5 @@
{ {
"block.greenscreenmod.green_screen_block": "Green Screen Block" "block.greenscreenmod.green_screen_block": "Green Screen Block",
"block.greenscreenmod.green_screen_block_dim": "Green Screen Block Dim"
} }

View File

@ -1,6 +0,0 @@
{
"parent": "block/cube_all",
"textures": {
"all": "greenscreenmod:block/green_screen_block"
}
}

View File

@ -1,3 +0,0 @@
{
"parent": "greenscreenmod:block/green_screen_block"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

View File

@ -10,7 +10,7 @@
], ],
"contact": { "contact": {
"homepage": "https://zeldon.ru/", "homepage": "https://zeldon.ru/",
"sources": "https://github.com/xzeldon/green-screen-mod" "sources": "https://github.com/xzeldon/GreenScreenMod"
}, },
"license": "MIT", "license": "MIT",
@ -20,6 +20,10 @@
"entrypoints": { "entrypoints": {
"main": [ "main": [
"ru.xzeldon.greenscreenmod.GreenScreenMod" "ru.xzeldon.greenscreenmod.GreenScreenMod"
],
"client": [
"ru.xzeldon.greenscreenmod.GreenScreenModClient"
] ]
}, },
"mixins": [], "mixins": [],