From 85a48ba1860fe21bb6eb5770aa6938e007e32d14 Mon Sep 17 00:00:00 2001 From: xzeldon Date: Sat, 21 May 2022 08:32:26 +0300 Subject: [PATCH] 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 --- README.md | 4 +- .../greenscreenmod/GreenScreenMod.java | 7 +- .../greenscreenmod/GreenScreenModClient.java | 12 ++ ...{ModBlocks.java => GreenScreenBlocks.java} | 19 ++- .../block/{ => custom}/GreenScreenBlock.java | 10 +- .../block/custom/GreenScreenBlockDim.java | 7 + .../model/GreenScreenBlockModel.java | 133 ++++++++++++++++++ .../model/GreenScreenModelProvider.java | 34 +++++ .../blockstates/green_screen_block_dim.json | 7 + .../assets/greenscreenmod/lang/en_us.json | 4 +- .../models/block/green_screen_block.json | 6 - .../models/item/green_screen_block.json | 3 - .../textures/block/green_screen_block_dim.png | Bin 0 -> 162 bytes src/main/resources/fabric.mod.json | 6 +- 14 files changed, 224 insertions(+), 28 deletions(-) create mode 100644 src/main/java/ru/xzeldon/greenscreenmod/GreenScreenModClient.java rename src/main/java/ru/xzeldon/greenscreenmod/block/{ModBlocks.java => GreenScreenBlocks.java} (60%) rename src/main/java/ru/xzeldon/greenscreenmod/block/{ => custom}/GreenScreenBlock.java (70%) create mode 100644 src/main/java/ru/xzeldon/greenscreenmod/block/custom/GreenScreenBlockDim.java create mode 100644 src/main/java/ru/xzeldon/greenscreenmod/model/GreenScreenBlockModel.java create mode 100644 src/main/java/ru/xzeldon/greenscreenmod/model/GreenScreenModelProvider.java create mode 100644 src/main/resources/assets/greenscreenmod/blockstates/green_screen_block_dim.json delete mode 100644 src/main/resources/assets/greenscreenmod/models/block/green_screen_block.json delete mode 100644 src/main/resources/assets/greenscreenmod/models/item/green_screen_block.json create mode 100644 src/main/resources/assets/greenscreenmod/textures/block/green_screen_block_dim.png diff --git a/README.md b/README.md index c267488..b80df16 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This mod just adds a green block to the miscellaneous tab. # 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 -Place `.jar` file to the `mods` folder. +Download and install [Fabric](https://fabricmc.net/use/installer/) then place `.jar` file to the `mods` folder. diff --git a/src/main/java/ru/xzeldon/greenscreenmod/GreenScreenMod.java b/src/main/java/ru/xzeldon/greenscreenmod/GreenScreenMod.java index b7c78b3..ee6c7af 100644 --- a/src/main/java/ru/xzeldon/greenscreenmod/GreenScreenMod.java +++ b/src/main/java/ru/xzeldon/greenscreenmod/GreenScreenMod.java @@ -3,17 +3,14 @@ package ru.xzeldon.greenscreenmod; import net.fabricmc.api.ModInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ru.xzeldon.greenscreenmod.block.ModBlocks; +import ru.xzeldon.greenscreenmod.block.GreenScreenBlocks; 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 Logger LOGGER = LoggerFactory.getLogger("greenscreenmod"); @Override public void onInitialize() { - ModBlocks.registerModBlocks(); + GreenScreenBlocks.registerBlocks(); } } diff --git a/src/main/java/ru/xzeldon/greenscreenmod/GreenScreenModClient.java b/src/main/java/ru/xzeldon/greenscreenmod/GreenScreenModClient.java new file mode 100644 index 0000000..1aa312c --- /dev/null +++ b/src/main/java/ru/xzeldon/greenscreenmod/GreenScreenModClient.java @@ -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()); + } +} diff --git a/src/main/java/ru/xzeldon/greenscreenmod/block/ModBlocks.java b/src/main/java/ru/xzeldon/greenscreenmod/block/GreenScreenBlocks.java similarity index 60% rename from src/main/java/ru/xzeldon/greenscreenmod/block/ModBlocks.java rename to src/main/java/ru/xzeldon/greenscreenmod/block/GreenScreenBlocks.java index 1456106..c5aa1fb 100644 --- a/src/main/java/ru/xzeldon/greenscreenmod/block/ModBlocks.java +++ b/src/main/java/ru/xzeldon/greenscreenmod/block/GreenScreenBlocks.java @@ -1,17 +1,28 @@ package ru.xzeldon.greenscreenmod.block; 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.Material; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import ru.xzeldon.greenscreenmod.GreenScreenMod; -import net.minecraft.block.AbstractGlassBlock; +import ru.xzeldon.greenscreenmod.block.custom.GreenScreenBlock; -public class ModBlocks { - public static final Block GREEN_SCREEN_BLOCK = registerBlock("green_screen_block", new GreenScreenBlock(), ItemGroup.MISC); +public class GreenScreenBlocks { + 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) { registerBlockItem(name, block, group); @@ -23,7 +34,7 @@ public class ModBlocks { new BlockItem(block, new FabricItemSettings().group(group))); } - public static void registerModBlocks() { + public static void registerBlocks() { GreenScreenMod.LOGGER.info("Registering ModBlocks for " + GreenScreenMod.MOD_ID); } } diff --git a/src/main/java/ru/xzeldon/greenscreenmod/block/GreenScreenBlock.java b/src/main/java/ru/xzeldon/greenscreenmod/block/custom/GreenScreenBlock.java similarity index 70% rename from src/main/java/ru/xzeldon/greenscreenmod/block/GreenScreenBlock.java rename to src/main/java/ru/xzeldon/greenscreenmod/block/custom/GreenScreenBlock.java index d54a261..6e95a09 100644 --- a/src/main/java/ru/xzeldon/greenscreenmod/block/GreenScreenBlock.java +++ b/src/main/java/ru/xzeldon/greenscreenmod/block/custom/GreenScreenBlock.java @@ -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.minecraft.block.Block; @@ -8,14 +8,12 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; public class GreenScreenBlock extends Block { - public GreenScreenBlock() { - super(FabricBlockSettings.of(Material.METAL) - .breakInstantly() - ); + public GreenScreenBlock(Settings settings) { + super(settings); } @Override public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) { - return 1; + return 1.0F; } } diff --git a/src/main/java/ru/xzeldon/greenscreenmod/block/custom/GreenScreenBlockDim.java b/src/main/java/ru/xzeldon/greenscreenmod/block/custom/GreenScreenBlockDim.java new file mode 100644 index 0000000..967d4e2 --- /dev/null +++ b/src/main/java/ru/xzeldon/greenscreenmod/block/custom/GreenScreenBlockDim.java @@ -0,0 +1,7 @@ +package ru.xzeldon.greenscreenmod.block.custom; + +public class GreenScreenBlockDim extends GreenScreenBlock { + public GreenScreenBlockDim(Settings settings) { + super(settings); + } +} diff --git a/src/main/java/ru/xzeldon/greenscreenmod/model/GreenScreenBlockModel.java b/src/main/java/ru/xzeldon/greenscreenmod/model/GreenScreenBlockModel.java new file mode 100644 index 0000000..9618aba --- /dev/null +++ b/src/main/java/ru/xzeldon/greenscreenmod/model/GreenScreenBlockModel.java @@ -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 randomSupplier, RenderContext context) { + context.meshConsumer().accept(mesh); + } + + @Override + public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { + context.meshConsumer().accept(mesh); + } + + @Override + public Collection getModelDependencies() { + return List.of(DEFAULT_BLOCK_MODEL); + } + + @Override + public Collection getTextureDependencies(Function unbakedModelGetter, Set> unresolvedTextureReferences) { + return List.of(SPRITE_ID); + } + + @Nullable + @Override + public BakedModel bake(ModelLoader loader, Function 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 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; + } +} diff --git a/src/main/java/ru/xzeldon/greenscreenmod/model/GreenScreenModelProvider.java b/src/main/java/ru/xzeldon/greenscreenmod/model/GreenScreenModelProvider.java new file mode 100644 index 0000000..63c4645 --- /dev/null +++ b/src/main/java/ru/xzeldon/greenscreenmod/model/GreenScreenModelProvider.java @@ -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; + } + } +} diff --git a/src/main/resources/assets/greenscreenmod/blockstates/green_screen_block_dim.json b/src/main/resources/assets/greenscreenmod/blockstates/green_screen_block_dim.json new file mode 100644 index 0000000..a25acdf --- /dev/null +++ b/src/main/resources/assets/greenscreenmod/blockstates/green_screen_block_dim.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "greenscreenmod:block/green_screen_block" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/greenscreenmod/lang/en_us.json b/src/main/resources/assets/greenscreenmod/lang/en_us.json index eec3f75..6f0a0f8 100644 --- a/src/main/resources/assets/greenscreenmod/lang/en_us.json +++ b/src/main/resources/assets/greenscreenmod/lang/en_us.json @@ -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" + } \ No newline at end of file diff --git a/src/main/resources/assets/greenscreenmod/models/block/green_screen_block.json b/src/main/resources/assets/greenscreenmod/models/block/green_screen_block.json deleted file mode 100644 index c8cec48..0000000 --- a/src/main/resources/assets/greenscreenmod/models/block/green_screen_block.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "block/cube_all", - "textures": { - "all": "greenscreenmod:block/green_screen_block" - } -} \ No newline at end of file diff --git a/src/main/resources/assets/greenscreenmod/models/item/green_screen_block.json b/src/main/resources/assets/greenscreenmod/models/item/green_screen_block.json deleted file mode 100644 index 7a1c28f..0000000 --- a/src/main/resources/assets/greenscreenmod/models/item/green_screen_block.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "greenscreenmod:block/green_screen_block" -} \ No newline at end of file diff --git a/src/main/resources/assets/greenscreenmod/textures/block/green_screen_block_dim.png b/src/main/resources/assets/greenscreenmod/textures/block/green_screen_block_dim.png new file mode 100644 index 0000000000000000000000000000000000000000..de180ddf84d0a851f2e0cb9e3ebe91b6c1d012b0 GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#5j!gfr_9Z=uB|{J+02lL66gHf+|;}hAeVu`xhOTUBsE2$JhLQ2!QIn0AVn{g z9Vjm0>EaloaXvZa$9V^#gro$Cs|KqQcVsaz*y}UO%jI&kgEV`(`njxgN@xNAX>TS} literal 0 HcmV?d00001 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f21f7b1..850d3c5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -10,7 +10,7 @@ ], "contact": { "homepage": "https://zeldon.ru/", - "sources": "https://github.com/xzeldon/green-screen-mod" + "sources": "https://github.com/xzeldon/GreenScreenMod" }, "license": "MIT", @@ -20,6 +20,10 @@ "entrypoints": { "main": [ "ru.xzeldon.greenscreenmod.GreenScreenMod" + ], + + "client": [ + "ru.xzeldon.greenscreenmod.GreenScreenModClient" ] }, "mixins": [],