Skip to content

Commit 99fa891

Browse files
committed
Crucible Fuel Tank
1 parent b059a6c commit 99fa891

File tree

22 files changed

+609
-14
lines changed

22 files changed

+609
-14
lines changed

src/main/java/dev/quarris/fireandflames/FireAndFlames.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public class FireAndFlames {
1111

1212
public FireAndFlames(ModContainer container, IEventBus modBus) {
13+
DataComponentSetup.init(modBus);
1314
BlockSetup.init(modBus);
1415
ItemSetup.init(modBus);
1516
FluidSetup.init(modBus);

src/main/java/dev/quarris/fireandflames/client/event/handler/ClientSetupEvents.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
package dev.quarris.fireandflames.client.event.handler;
22

33
import dev.quarris.fireandflames.ModRef;
4-
import dev.quarris.fireandflames.client.renderer.blockentity.CastingBasinRenderer;
5-
import dev.quarris.fireandflames.client.renderer.blockentity.CastingTableRenderer;
6-
import dev.quarris.fireandflames.client.renderer.blockentity.CrucibleControllerRenderer;
7-
import dev.quarris.fireandflames.client.renderer.blockentity.CrucibleFawsitRenderer;
4+
import dev.quarris.fireandflames.client.renderer.blockentity.*;
85
import dev.quarris.fireandflames.client.screen.CrucibleScreen;
96
import dev.quarris.fireandflames.setup.BlockEntitySetup;
107
import dev.quarris.fireandflames.setup.FluidSetup;
118
import dev.quarris.fireandflames.setup.MenuSetup;
129
import net.minecraft.resources.ResourceLocation;
1310
import net.neoforged.bus.api.SubscribeEvent;
1411
import net.neoforged.fml.common.EventBusSubscriber;
15-
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
1612
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
1713
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
1814
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
1915
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
20-
import net.neoforged.neoforge.common.NeoForgeMod;
2116

2217
@EventBusSubscriber(modid = ModRef.ID, bus = EventBusSubscriber.Bus.MOD)
2318
public class ClientSetupEvents {
@@ -51,6 +46,7 @@ public static void registerRenderers(EntityRenderersEvent.RegisterRenderers even
5146
event.registerBlockEntityRenderer(BlockEntitySetup.CRUCIBLE_FAWSIT.get(), CrucibleFawsitRenderer::new);
5247
event.registerBlockEntityRenderer(BlockEntitySetup.CASTING_BASIN.get(), CastingBasinRenderer::new);
5348
event.registerBlockEntityRenderer(BlockEntitySetup.CASTING_TABLE.get(), CastingTableRenderer::new);
49+
event.registerBlockEntityRenderer(BlockEntitySetup.CRUCIBLE_TANK.get(), FluidStorageRenderer::new);
5450
}
5551

5652
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package dev.quarris.fireandflames.client.renderer.blockentity;
2+
3+
import com.mojang.blaze3d.vertex.PoseStack;
4+
import com.mojang.blaze3d.vertex.VertexConsumer;
5+
import dev.quarris.fireandflames.client.util.FluidRenderer;
6+
import dev.quarris.fireandflames.world.block.entity.FluidStorageBlockEntity;
7+
import net.minecraft.client.renderer.ItemBlockRenderTypes;
8+
import net.minecraft.client.renderer.MultiBufferSource;
9+
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
10+
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
11+
import net.minecraft.core.BlockPos;
12+
import net.minecraft.world.level.material.FluidState;
13+
import net.minecraft.world.phys.Vec3;
14+
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
15+
import net.neoforged.neoforge.fluids.FluidStack;
16+
import net.neoforged.neoforge.fluids.capability.templates.FluidTank;
17+
18+
public class FluidStorageRenderer implements BlockEntityRenderer<FluidStorageBlockEntity> {
19+
20+
public FluidStorageRenderer(BlockEntityRendererProvider.Context context) {
21+
}
22+
23+
@Override
24+
public void render(FluidStorageBlockEntity pStorage, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBufferSource, int pLight, int pOverlay) {
25+
FluidTank tank = pStorage.getFluidTank();
26+
FluidStack fluidStack = tank.getFluid();
27+
if (!fluidStack.isEmpty()) {
28+
assert pStorage.getLevel() != null;
29+
BlockPos blockPos = pStorage.getBlockPos();
30+
FluidState state = fluidStack.getFluid().defaultFluidState();
31+
VertexConsumer spriteBuffer = FluidRenderer.getFluidSpriteBuffer(pStorage.getLevel(), blockPos, fluidStack, pBufferSource, ItemBlockRenderTypes.getRenderLayer(state), FluidRenderer.FluidSpriteType.STILL, FluidRenderer.FluidSpriteType.FLOWING).getRight();
32+
IClientFluidTypeExtensions attributes = IClientFluidTypeExtensions.of(state);
33+
int color = attributes.getTintColor(state, pStorage.getLevel(), blockPos);
34+
35+
double height = Math.min(1, fluidStack.getAmount() / (double) tank.getCapacity());
36+
37+
// Top
38+
FluidRenderer.renderFluidFace(spriteBuffer, pPoseStack, new Vec3[]{
39+
new Vec3(0, height, 1),
40+
new Vec3(1, height, 1),
41+
new Vec3(1, height, 0),
42+
new Vec3(0, height, 0)
43+
}, color, pLight);
44+
45+
// North
46+
FluidRenderer.renderFluidFace(spriteBuffer, pPoseStack, new Vec3[]{
47+
new Vec3(1, 0, 0.01),
48+
new Vec3(0, 0, 0.01),
49+
new Vec3(0, height, 0.01),
50+
new Vec3(1, height, 0.01)
51+
}, color, pLight);
52+
53+
// South
54+
FluidRenderer.renderFluidFace(spriteBuffer, pPoseStack, new Vec3[]{
55+
new Vec3(0, 0, 0.99),
56+
new Vec3(1, 0, 0.99),
57+
new Vec3(1, height, 0.99),
58+
new Vec3(0, height, 0.99)
59+
}, color, pLight);
60+
61+
// East
62+
FluidRenderer.renderFluidFace(spriteBuffer, pPoseStack, new Vec3[]{
63+
new Vec3(0.99, 0, 1),
64+
new Vec3(0.99, 0, 0),
65+
new Vec3(0.99, height, 0),
66+
new Vec3(0.99, height, 1)
67+
}, color, pLight);
68+
69+
// West
70+
FluidRenderer.renderFluidFace(spriteBuffer, pPoseStack, new Vec3[]{
71+
new Vec3(0.01, 0, 0),
72+
new Vec3(0.01, 0, 1),
73+
new Vec3(0.01, height, 1),
74+
new Vec3(0.01, height, 0)
75+
}, color, pLight);
76+
77+
}
78+
}
79+
}

src/main/java/dev/quarris/fireandflames/datagen/client/BlockStateGen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ protected void registerStatesAndModels() {
2323
this.simpleBlockWithItem(BlockSetup.FIRE_BRICKS.get(), this.models().cubeAll("fire_bricks", blockTexture(BlockSetup.FIRE_BRICKS.get())));
2424
this.simpleBlockWithItem(BlockSetup.CRUCIBLE_WINDOW.get(), this.models().cubeColumn("crucible_window", blockTexture(BlockSetup.CRUCIBLE_WINDOW.get()), blockTexture(BlockSetup.FIRE_BRICKS.get())).renderType(RenderType.cutout().name));
2525
this.simpleBlockWithItem(BlockSetup.CRUCIBLE_DRAIN.get(), this.models().cubeAll("crucible_drain", blockTexture(BlockSetup.CRUCIBLE_DRAIN.get())));
26+
this.simpleBlockWithItem(BlockSetup.CRUCIBLE_TANK.get(), this.models().cubeColumn("crucible_tank", blockTexture(BlockSetup.CRUCIBLE_TANK.get()), blockTexture(BlockSetup.FIRE_BRICKS.get())).renderType(RenderType.cutout().name));
2627

2728
var faucetModel = this.models().withExistingParent("crucible_faucet", ModRef.res("block/crucible_faucet_base")).texture("texture", blockTexture(BlockSetup.FIRE_BRICKS.get()));
2829
this.horizontalBlock(BlockSetup.CRUCIBLE_FAWSIT.get(), faucetModel);

src/main/java/dev/quarris/fireandflames/datagen/client/EnUsLanguageGen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protected void addTranslations() {
2525
this.addBlock(BlockSetup.CRUCIBLE_CONTROLLER, "Crucible Controller");
2626
this.addBlock(BlockSetup.CRUCIBLE_WINDOW, "Crucible Window");
2727
this.addBlock(BlockSetup.CRUCIBLE_DRAIN, "Crucible Drain");
28+
this.addBlock(BlockSetup.CRUCIBLE_TANK, "Crucible Fuel Tank");
2829
this.addBlock(BlockSetup.CRUCIBLE_FAWSIT, "Crucible Fawsit (Faucet)");
2930
this.addBlock(BlockSetup.CASTING_BASIN, "Casting Basin");
3031
this.addBlock(BlockSetup.CASTING_TABLE, "Casting Table");
@@ -35,6 +36,8 @@ protected void addTranslations() {
3536

3637
this.add("container.fireandflames.crucible.title", "Crucible");
3738
this.add("container.fireandflames.crucible.fluid_tank.empty", "Empty");
39+
this.add("container.fireandflames.fluid_storage.fluid_amount", "%s - %s mb");
40+
this.add("container.fireandflames.fluid_storage.more", "and %s more...");
3841
this.add("creative_tabs.fireandflames.creative_tab", "Fire and Flames");
3942
this.add("death.attack.crucible_melting", "%1$s was melted by the heat of the crucible");
4043
this.add("death.attack.crucible_melting.player", "%1$s was thrown to the pits of the crucible by %2$s");

src/main/java/dev/quarris/fireandflames/datagen/server/BlockTagGen.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public BlockTagGen(PackOutput output, CompletableFuture<HolderLookup.Provider> l
2626
protected void addTags(HolderLookup.Provider pLookup) {
2727
this.tag(TagSetup.BlockTags.VALID_CRUCIBLE_BLOCKS).add(
2828
BlockSetup.FIRE_BRICKS.get(),
29-
BlockSetup.CRUCIBLE_WINDOW.get()
29+
BlockSetup.CRUCIBLE_WINDOW.get(),
30+
BlockSetup.CRUCIBLE_TANK.get()
3031
);
3132

3233
this.tag(BlockTags.MINEABLE_WITH_PICKAXE)
@@ -35,6 +36,7 @@ protected void addTags(HolderLookup.Provider pLookup) {
3536
BlockSetup.CRUCIBLE_CONTROLLER.get(),
3637
BlockSetup.CRUCIBLE_WINDOW.get(),
3738
BlockSetup.CRUCIBLE_DRAIN.get(),
39+
BlockSetup.CRUCIBLE_TANK.get(),
3840
BlockSetup.CRUCIBLE_FAWSIT.get(),
3941
BlockSetup.CASTING_BASIN.get(),
4042
BlockSetup.CASTING_TABLE.get()

src/main/java/dev/quarris/fireandflames/datagen/server/ItemTagGen.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package dev.quarris.fireandflames.datagen.server;
22

33
import dev.quarris.fireandflames.ModRef;
4-
import dev.quarris.fireandflames.setup.BlockSetup;
5-
import dev.quarris.fireandflames.setup.TagSetup;
64
import net.minecraft.core.HolderLookup;
75
import net.minecraft.core.registries.BuiltInRegistries;
86
import net.minecraft.core.registries.Registries;

src/main/java/dev/quarris/fireandflames/datagen/server/RecipesGen.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ public static void shapedRecipes(RecipeOutput pOutput) {
159159
.unlockedBy("has_fire_brick", has(ItemSetup.FIRE_BRICK.get()))
160160
.save(pOutput);
161161

162+
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, BlockSetup.CRUCIBLE_TANK.get())
163+
.pattern("BBB")
164+
.pattern("BGB")
165+
.pattern("BBB")
166+
.define('B', ItemSetup.FIRE_BRICK.get())
167+
.define('G', Tags.Items.GLASS_BLOCKS)
168+
.unlockedBy("has_fire_brick", has(ItemSetup.FIRE_BRICK.get()))
169+
.unlockedBy("has_glass", has(Tags.Items.GLASS_BLOCKS))
170+
.save(pOutput);
171+
162172
ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, BlockSetup.CRUCIBLE_FAWSIT.get())
163173
.pattern("B B")
164174
.pattern(" B ")

src/main/java/dev/quarris/fireandflames/datagen/server/loot/BlockLoot.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package dev.quarris.fireandflames.datagen.server.loot;
22

33
import dev.quarris.fireandflames.setup.BlockSetup;
4+
import dev.quarris.fireandflames.setup.DataComponentSetup;
45
import dev.quarris.fireandflames.setup.ItemSetup;
56
import net.minecraft.core.HolderLookup;
7+
import net.minecraft.core.component.DataComponents;
68
import net.minecraft.data.loot.BlockLootSubProvider;
79
import net.minecraft.world.flag.FeatureFlags;
810
import net.minecraft.world.level.block.Block;
11+
import net.minecraft.world.level.storage.loot.LootPool;
12+
import net.minecraft.world.level.storage.loot.LootTable;
13+
import net.minecraft.world.level.storage.loot.entries.LootItem;
14+
import net.minecraft.world.level.storage.loot.functions.CopyComponentsFunction;
915
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
1016

1117
import java.util.Set;
@@ -24,10 +30,29 @@ protected void generate() {
2430
this.dropSelf(BlockSetup.CRUCIBLE_FAWSIT.get());
2531
this.dropSelf(BlockSetup.CASTING_BASIN.get());
2632
this.dropSelf(BlockSetup.CASTING_TABLE.get());
33+
this.add(BlockSetup.CRUCIBLE_TANK.get(), this::createFluidStorageDrop);
2734

2835
this.add(BlockSetup.FIRE_CLAY.get(), block -> this.createSingleItemTableWithSilkTouch(block, ItemSetup.FIRE_CLAY_BALL, ConstantValue.exactly(4.0F)));
2936
}
3037

38+
protected LootTable.Builder createFluidStorageDrop(Block block) {
39+
return LootTable.lootTable()
40+
.withPool(
41+
this.applyExplosionCondition(
42+
block,
43+
LootPool.lootPool()
44+
.setRolls(ConstantValue.exactly(1.0F))
45+
.add(
46+
LootItem.lootTableItem(block)
47+
.apply(
48+
CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY)
49+
.include(DataComponentSetup.FLUID_CONTAINER.get())
50+
)
51+
)
52+
)
53+
);
54+
}
55+
3156
@Override
3257
protected Iterable<Block> getKnownBlocks() {
3358
return BlockSetup.REGISTRY.getEntries()

src/main/java/dev/quarris/fireandflames/event/handler/SetupEvents.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ private static void registerCapabilities(RegisterCapabilitiesEvent event) {
2121
event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, BlockEntitySetup.CRUCIBLE_DRAIN.get(), (be, dir) -> be.getCrucibleTank().orElse(null));
2222
event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, BlockEntitySetup.CASTING_BASIN.get(), (be, dir) -> be.getTank());
2323
event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, BlockEntitySetup.CASTING_TABLE.get(), (be, dir) -> be.getTank());
24+
event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, BlockEntitySetup.CRUCIBLE_TANK.get(), (be, dir) -> be.getFluidTank());
2425
}
2526

2627
}

0 commit comments

Comments
 (0)