Skip to content

Commit

Permalink
It works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Feb 24, 2024
1 parent b09030f commit 230312c
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// 1.20.4 2024-02-23T16:02:28.1852557 Loot Tables
// 1.20.4 2024-02-24T11:23:34.8138253 Loot Tables
9d014f2566cbaceeb72689cf25beee59806d4a11 data/justdirethings/loot_tables/blocks/dire_iron_block.json
9d62cc762313305bbe032473310bafd15bcdb8bd data/justdirethings/loot_tables/blocks/gooblock_tier1.json
c622ac3c8481d6f9edca06131dc3fd0e63d2e7db data/justdirethings/loot_tables/blocks/testblock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 1.20.4 2024-02-23T16:27:08.1051804 Item Models: justdirethings
// 1.20.4 2024-02-24T11:23:34.8113223 Item Models: justdirethings
e465ae52244667022d3ec84f7b9ba7277ded6ac5 assets/justdirethings/models/item/dire_iron_block.json
cc689b22f0c6c9518ffe455897cc66247515d38d assets/justdirethings/models/item/dire_iron_ingot.json
af62c31381c904f86fde9370e374e01d828fa643 assets/justdirethings/models/item/fuel_canister.json
2ec271fed6a1fb15d49837326283ca1f0e269689 assets/justdirethings/models/item/gooblock_tier1.json
3f50e98f22d6abc6b3edab6c01b82deec145ec78 assets/justdirethings/models/item/pocket_generator.json
b013898ecc294c4a1d765e68064b9ee90f796cac assets/justdirethings/models/item/testblock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// 1.20.4 2024-02-23T16:02:28.1842549 Block States: justdirethings
// 1.20.4 2024-02-24T11:23:34.8128231 Block States: justdirethings
920cb18580ea999cb4670bf40b25ba5c2a914032 assets/justdirethings/blockstates/dire_iron_block.json
5a4cd222f3bde8915594a1363e2758ee5208517c assets/justdirethings/blockstates/gooblock_tier1.json
f6a6dbb4058fba20b89a5bb05a9a78757a5b3f52 assets/justdirethings/blockstates/testblock.json
cffdbed997636075f20d3cdcd18712085357f847 assets/justdirethings/models/block/dire_iron_block.json
42066c831f2979ed0f605a673e9b7cbdcb5e3f87 assets/justdirethings/models/block/gooblock_tier1.json
6e57e22c83a9c4fe215e7e2c951d9188562ba3e3 assets/justdirethings/models/block/testblock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "justdirethings:block/testblock"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "justdirethings:block/testblock"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "justdirethings:block/testblock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "justdirethings:testblock"
}
],
"rolls": 1.0
}
],
"random_sequence": "justdirethings:blocks/testblock"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.direwolf20.justdirethings.client.blockentityrenders;

import com.direwolf20.justdirethings.JustDireThings;
import com.direwolf20.justdirethings.client.renderers.DireVertexConsumerSquished;
import com.direwolf20.justdirethings.client.renderers.OurRenderTypes;
import com.direwolf20.justdirethings.common.blockentities.gooblocks.GooBlockBE_Base;
Expand All @@ -13,16 +14,20 @@
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.model.data.ModelData;
import org.joml.Matrix3f;
import org.joml.Matrix4f;

import java.util.BitSet;
import java.util.List;
Expand All @@ -41,12 +46,14 @@ public void render(T blockentity, float partialTicks, PoseStack matrixStackIn, M
BakedModel ibakedmodel = blockrendererdispatcher.getBlockModel(renderState);
BlockColors blockColors = Minecraft.getInstance().getBlockColors();
ModelBlockRenderer modelBlockRenderer = new ModelBlockRenderer(blockColors);
renderSquished(level, pos, matrixStackIn, bufferIn, combinedLightsIn, combinedOverlayIn, 1f, renderState, ibakedmodel, blockrendererdispatcher, modelBlockRenderer, true, false);
//renderSquished(level, pos, matrixStackIn, bufferIn, combinedLightsIn, combinedOverlayIn, 1f, renderState, ibakedmodel, blockrendererdispatcher, modelBlockRenderer, true, false);
renderTexturePattern(level, pos, matrixStackIn, bufferIn, combinedLightsIn, combinedOverlayIn, 1f, renderState, ibakedmodel, blockrendererdispatcher, modelBlockRenderer, true, false);
}

public void renderSquished(Level level, BlockPos pos, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightsIn, int combinedOverlayIn, float scale, BlockState renderState, BakedModel ibakedmodel, BlockRenderDispatcher blockrendererdispatcher, ModelBlockRenderer modelBlockRenderer, boolean adjustUV, boolean bottomUp) {
matrixStackIn.pushPose();
matrixStackIn.translate(0, 1, 0);

VertexConsumer builder = bufferIn.getBuffer(OurRenderTypes.RenderBlockBackface);

scale = Mth.lerp(scale, 0f, 1f);
Expand Down Expand Up @@ -78,4 +85,119 @@ public void renderSquished(Level level, BlockPos pos, PoseStack matrixStackIn, M
matrixStackIn.popPose();
}

public void renderTexturePattern(Level level, BlockPos pos, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightsIn, int combinedOverlayIn, float scale, BlockState renderState, BakedModel ibakedmodel, BlockRenderDispatcher blockrendererdispatcher, ModelBlockRenderer modelBlockRenderer, boolean adjustUV, boolean bottomUp) {
matrixStackIn.pushPose();
matrixStackIn.translate(0, 1, 0);

ResourceLocation DRAGON_EXPLODING_LOCATION = new ResourceLocation(JustDireThings.MODID, "textures/block/goorender5-pattern.png");

OurRenderTypes.updateRenders();
VertexConsumer vertexconsumer = bufferIn.getBuffer(OurRenderTypes.dragonExplosionAlpha(DRAGON_EXPLODING_LOCATION));

matrixStackIn.pushPose();
matrixStackIn.translate(0, 0, -0.003f);

PoseStack.Pose posestack$pose = matrixStackIn.last();
Matrix4f matrix4f = posestack$pose.pose();
Matrix3f matrix3f = posestack$pose.normal();

renderQuad(
matrix4f,
matrix3f,
vertexconsumer,
1f,
1f,
1f,
1f,
0,
1,
0,
0,
1,
0,
0,
1,
0,
1
);
matrixStackIn.popPose();
matrixStackIn.translate(0, 0, -0.002f);

float[] afloat = new float[Direction.values().length * 2];
BitSet bitset = new BitSet(3);
RandomSource randomSource = RandomSource.create();
randomSource.setSeed(renderState.getSeed(pos));
BlockPos.MutableBlockPos blockpos$mutableblockpos = pos.mutable();
List<BakedQuad> list;
ModelBlockRenderer.AmbientOcclusionFace modelblockrenderer$ambientocclusionface = new ModelBlockRenderer.AmbientOcclusionFace();
Direction direction = Direction.NORTH;

VertexConsumer builder = bufferIn.getBuffer(OurRenderTypes.RenderBlockBackface);
DireVertexConsumerSquished chunksConsumer = new DireVertexConsumerSquished(builder, 0, 0, 0, 1, 1, 1, matrixStackIn.last().pose());

chunksConsumer.adjustUV = adjustUV;
chunksConsumer.bottomUp = bottomUp;
if (!renderState.isSolidRender(level, pos))
chunksConsumer.adjustUV = false;
list = ibakedmodel.getQuads(renderState, direction, randomSource, ModelData.EMPTY, null);
if (!list.isEmpty()) {
TextureAtlasSprite sprite = list.get(0).getSprite();
chunksConsumer.setSprite(sprite);
chunksConsumer.setDirection(direction);
blockpos$mutableblockpos.setWithOffset(pos, direction);
modelBlockRenderer.renderModelFaceAO(level, renderState, pos, matrixStackIn, chunksConsumer, list, afloat, bitset, modelblockrenderer$ambientocclusionface, combinedOverlayIn);
}

matrixStackIn.popPose();
}


private static void renderQuad(
Matrix4f pPose,
Matrix3f pNormal,
VertexConsumer pConsumer,
float pRed,
float pGreen,
float pBlue,
float pAlpha,
int pMinY,
int pMaxY,
float pMinX,
float pMinZ,
float pMaxX,
float pMaxZ,
float pMinU,
float pMaxU,
float pMinV,
float pMaxV
) {
addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMaxY, pMinX, pMinZ, pMaxU, pMinV);
addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMinX, pMinZ, pMaxU, pMaxV);
addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMinY, pMaxX, pMaxZ, pMinU, pMaxV);
addVertex(pPose, pNormal, pConsumer, pRed, pGreen, pBlue, pAlpha, pMaxY, pMaxX, pMaxZ, pMinU, pMinV);
}

private static void addVertex(
Matrix4f pPose,
Matrix3f pNormal,
VertexConsumer pConsumer,
float pRed,
float pGreen,
float pBlue,
float pAlpha,
int pY,
float pX,
float pZ,
float pU,
float pV
) {
pConsumer.vertex(pPose, pX, (float) pY, pZ)
.color(pRed, pGreen, pBlue, pAlpha)
.uv(pU, pV)
.overlayCoords(OverlayTexture.NO_OVERLAY)
.uv2(15728880)
.normal(pNormal, 0.0F, 1.0F, 0.0F)
.endVertex();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ public VertexConsumer uv(float u, float v) {
float adjustedV = minV + adjustedVDistance;

parent.uv(adjustedU, adjustedV);
return this;
} else {
parent.uv(u, v);
return this;
}
} else {
//Building above!
Expand Down Expand Up @@ -150,6 +152,7 @@ public VertexConsumer uv(float u, float v) {
float adjustedV2Distance = vDistanceToStart * (minY);
float adjustedV = maxV - adjustedVDistance - adjustedV2Distance; // Subtracting because we're adjusting from the end.
parent.uv(adjustedU, adjustedV);
return this;
} else {
//When drawing the top/bottom, we do like above, but both U and V are different, so we calculate both
float uDistanceToEnd, uDistanceToStart;
Expand Down Expand Up @@ -184,11 +187,12 @@ public VertexConsumer uv(float u, float v) {
adjustedV = maxV - adjustedVDistance - adjustedV2Distance;
}
parent.uv(adjustedU, adjustedV);
return this;
}
}
}
parent.uv(u, v);
}
parent.uv(u, v);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.Util;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;

import java.util.function.Function;

public class OurRenderTypes extends RenderType {
public static final RenderType RenderBlockBackface = create("GadgetRenderBlockBackface",
public static RenderType RenderBlockBackface = create("GadgetRenderBlockBackface",
DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 256, false, false,
RenderType.CompositeState.builder()
// .setShadeModelState(SMOOTH_SHADE)
Expand All @@ -20,6 +24,67 @@ public class OurRenderTypes extends RenderType {
.setWriteMaskState(COLOR_DEPTH_WRITE)
.createCompositeState(false));

/*public static RenderType.CompositeState overlay = create("overlayComposite",
DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 256, false, false,
RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_ENTITY_ALPHA_SHADER)
.setTextureState(BLOCK_SHEET_MIPPED)
.setCullState(NO_CULL)
.createCompositeState(true));*/


private static Function<ResourceLocation, RenderType> GooPattern = Util.memoize(
p_286150_ -> {
RenderType.CompositeState overlay = RenderType.CompositeState.builder()
.setShaderState(RenderStateShard.RENDERTYPE_TRANSLUCENT_SHADER)
.setLightmapState(LIGHTMAP)
.setLayeringState(VIEW_OFFSET_Z_LAYERING)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setTextureState(new RenderStateShard.TextureStateShard(p_286150_, false, false))
.setDepthTestState(LEQUAL_DEPTH_TEST)
.setCullState(NO_CULL)
.setWriteMaskState(COLOR_DEPTH_WRITE)
.createCompositeState(true);
return create("GooPattern", DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 1536, false, false, overlay);
}
);

public static void updateRenders() {
GooPattern = Util.memoize(
p_286150_ -> {
RenderType.CompositeState overlay = RenderType.CompositeState.builder()
.setShaderState(RenderStateShard.RENDERTYPE_ENTITY_ALPHA_SHADER)
.setLightmapState(LIGHTMAP)
//.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
//.setDepthTestState(LEQUAL_DEPTH_TEST)
.setTextureState(new RenderStateShard.TextureStateShard(p_286150_, false, false))
.setCullState(NO_CULL)
//.setOverlayState(RenderStateShard.NO_OVERLAY)
.setWriteMaskState(RenderStateShard.DEPTH_WRITE)
.createCompositeState(true);
return create("GooPattern", DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 1536, false, false, overlay);
});

RenderBlockBackface = create("GadgetRenderBlockBackface",
DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 256, false, false,
RenderType.CompositeState.builder()
.setShaderState(RenderStateShard.RENDERTYPE_TRANSLUCENT_SHADER)
.setLightmapState(LIGHTMAP)
.setTextureState(BLOCK_SHEET)
//.setLayeringState(RenderStateShard.NO_LAYERING)
//.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setDepthTestState(GREATER_DEPTH_TEST)
.setCullState(CULL)
//.setWriteMaskState(RenderStateShard.COLOR_DEPTH_WRITE)
.setOverlayState(RenderStateShard.OVERLAY)
.createCompositeState(false));
}

public static RenderType dragonExplosionAlpha(ResourceLocation pId) {
return GooPattern.apply(pId);
}


public OurRenderTypes(String p_173178_, VertexFormat p_173179_, VertexFormat.Mode p_173180_, int p_173181_, boolean p_173182_, boolean p_173183_, Runnable p_173184_, Runnable p_173185_) {
super(p_173178_, p_173179_, p_173180_, p_173181_, p_173182_, p_173183_, p_173184_, p_173185_);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.direwolf20.justdirethings.common.blocks;

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;

public class TestBlock extends Block {
public TestBlock() {
super(Properties.of()
.sound(SoundType.METAL)
.requiresCorrectToolForDrops()
.strength(5.0F, 6.0F)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public BlockStates(PackOutput output, ExistingFileHelper helper) {
protected void registerStatesAndModels() {
simpleBlock(Registration.GooBlock_Tier1.get(), models().cubeAll(Registration.GooBlock_Tier1_ITEM.getId().getPath(), blockTexture(Registration.GooBlock_Tier1.get())));
simpleBlock(Registration.DireIronBlock.get(), models().cubeAll(Registration.DireIronBlock_ITEM.getId().getPath(), blockTexture(Registration.DireIronBlock.get())));
simpleBlock(Registration.TestBlock.get(), models().cubeAll(Registration.TestBlock_ITEM.getId().getPath(), blockTexture(Registration.TestBlock.get())));
//models().cubeAll(ForgeRegistries.BLOCKS.getKey(Registration.RenderBlock.get()).getPath(), blockTexture(Registration.RenderBlock.get())).renderType("cutout");
//simpleBlock(Registration.RenderBlock.get(), models().cubeAll(Registration.RenderBlock.getId().getPath(), blockTexture(Registration.RenderBlock.get())).renderType("cutout"));
//simpleBlock(Registration.LaserNode.get(), models().getExistingFile(modLoc("block/laser_node")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protected void registerModels() {
//Block Items
withExistingParent(Registration.GooBlock_Tier1_ITEM.getId().getPath(), modLoc("block/gooblock_tier1"));
withExistingParent(Registration.DireIronBlock_ITEM.getId().getPath(), modLoc("block/dire_iron_block"));
withExistingParent(Registration.TestBlock.getId().getPath(), modLoc("block/testblock"));

//Item items
singleTexture(Registration.Fuel_Canister.getId().getPath(), mcLoc("item/generated"), "layer0", modLoc("item/fuel_canister"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class LootTables extends VanillaBlockLoot {
protected void generate() {
dropWhenSilkTouch(Registration.GooBlock_Tier1.get());
dropSelf(Registration.DireIronBlock.get());
dropSelf(Registration.TestBlock.get());
//add(Registration.RenderBlock.get(), noDrop());
//dropSelf(Registration.TemplateManager.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@Mod.EventBusSubscriber(modid = JustDireThings.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ClientSetup {
public static void init(final FMLClientSetupEvent event) {
//Minecraft.getInstance().getMainRenderTarget().enableStencil();
//NeoForge.EVENT_BUS.addListener(KeyBindings::onClientInput);

//Register our Render Events Class
Expand Down
Loading

0 comments on commit 230312c

Please sign in to comment.