Skip to content

Commit

Permalink
fix: fix fluidReg sounds and render types.
Browse files Browse the repository at this point in the history
  • Loading branch information
MegumiKasuga committed Dec 2, 2024
1 parent 1ae68c2 commit 01a4b63
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/kasuga/lib/core/KasugaLibStacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class KasugaLibStacks {
private final FontRegistry FONTS;
private final RandomSource random = RandomSource.create();
private final HashMap<Block, CustomBlockRenderer> BLOCK_RENDERERS;
public static final HashMap<FluidReg<?>, RenderType> FLUID_RENDERS = new HashMap<>();
public static final HashMap<FluidReg<?>, String> FLUID_RENDERS = new HashMap<>();

public final JavascriptApi JAVASCRIPT = new JavascriptApi();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public class AllExampleElements {
.blockType((fluid, properties) ->
new ExampleFluidBlock(fluid, BlockBehaviour.Properties.copy(Blocks.WATER)))
.noLootAndOcclusion()
.setRenderType(RenderType.translucent())
.setRenderType("translucent")
.tab(tab)
.submit(REGISTRY);

Expand Down
23 changes: 19 additions & 4 deletions src/main/java/kasuga/lib/registrations/common/FluidReg.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.NamedRenderTypeManager;
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
import net.minecraftforge.common.SoundAction;
import net.minecraftforge.common.SoundActions;
Expand Down Expand Up @@ -63,7 +67,7 @@ public class FluidReg<E extends ForgeFlowingFluid> extends Reg {
private int tintColor = 0xffffff;
boolean registerItem = false, registerBlock = false, registerMenu = false;
private final FluidTagReg tag;
private RenderType renderType = null;
private String renderType = "solid";
private Vector3f fogColor = null;

/**
Expand Down Expand Up @@ -434,20 +438,26 @@ public FluidReg<E> sound(SoundEvent fillSound, SoundEvent emptySound, SoundEvent
return bucketFillSound(fillSound).bucketEmptySound(emptySound).vaporizeSound(vaporizeSound);
}

@Optional
public FluidReg<E> blockSound(SoundType sound) {
block.withSound(sound);
return this;
}

@Optional
public FluidReg<E> defaultSounds() {
return sound(SoundEvents.BUCKET_FILL, SoundEvents.BUCKET_EMPTY, SoundEvents.FIRE_EXTINGUISH);
}

@Optional
public FluidReg<E> setRenderType(RenderType type) {
public FluidReg<E> setRenderType(String type) {
this.renderType = type;
return this;
}

@Optional
public FluidReg<E> setTranslucentRenderType() {
this.renderType = RenderType.translucent();
this.renderType = "translucent";
return this;
}

Expand Down Expand Up @@ -543,10 +553,15 @@ public LiquidBlock legacyBlock() {
return block.getBlock();
}

public RenderType getRenderType() {
public String getRenderType() {
return renderType;
}

@OnlyIn(Dist.CLIENT)
public RenderType genRenderType() {
return NamedRenderTypeManager.get(new ResourceLocation(renderType)).block();
}

@Override
public String getIdentifier() {
return "fluid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.NamedRenderTypeManager;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
Expand Down Expand Up @@ -443,10 +445,11 @@ public void onCustomItemRendererReg(Map<ResourceLocation, BakedModel> registry)
@Inner
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public void hookFluidAndRenders(FMLLoadCompleteEvent event) {
for (Map.Entry<FluidReg<?>, RenderType> entry : KasugaLibStacks.FLUID_RENDERS.entrySet()) {
ItemBlockRenderTypes.setRenderLayer(entry.getKey().stillFluid(), entry.getValue());
ItemBlockRenderTypes.setRenderLayer(entry.getKey().flowingFluid(), entry.getValue());
public void hookFluidAndRenders(FMLCommonSetupEvent event) {
for (Map.Entry<FluidReg<?>, String> entry : KasugaLibStacks.FLUID_RENDERS.entrySet()) {
RenderType type = NamedRenderTypeManager.get(new ResourceLocation(entry.getValue())).block();
ItemBlockRenderTypes.setRenderLayer(entry.getKey().stillFluid(), type);
ItemBlockRenderTypes.setRenderLayer(entry.getKey().flowingFluid(), type);
}
}

Expand Down

0 comments on commit 01a4b63

Please sign in to comment.