Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resorted entity interaction and submerged fog rendering for mod fluids. #272

Open
wants to merge 4 commits into
base: 1.15.X
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/main/java/com/mrcrayfish/vehicle/client/ClientEvents.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mrcrayfish.vehicle.client;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mrcrayfish.obfuscate.client.event.PlayerModelEvent;
import com.mrcrayfish.obfuscate.client.event.RenderItemEvent;
import com.mrcrayfish.obfuscate.common.data.SyncedPlayerData;
Expand All @@ -14,6 +16,7 @@
import com.mrcrayfish.vehicle.entity.PoweredVehicleEntity;
import com.mrcrayfish.vehicle.entity.VehicleEntity;
import com.mrcrayfish.vehicle.entity.VehicleProperties;
import com.mrcrayfish.vehicle.fluid.ModFluid;
import com.mrcrayfish.vehicle.init.ModDataKeys;
import com.mrcrayfish.vehicle.init.ModSounds;
import com.mrcrayfish.vehicle.item.SprayCanItem;
Expand All @@ -33,6 +36,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.HandSide;
Expand All @@ -49,6 +53,7 @@

import java.awt.*;
import java.text.DecimalFormat;
import java.util.function.Consumer;

/**
* Author: MrCrayfish
Expand Down Expand Up @@ -583,15 +588,32 @@ private void boxRenderGlEnd()
@SubscribeEvent
public void setLiquidFogDensity(EntityViewRenderEvent.FogDensity event)
{
event.getInfo().getBlockAtCamera();
/*Block block = event.getState().getBlock(); //TODO do i need to fix this
boolean isSap = block == ModBlocks.ENDER_SAP.get();
if (isSap || block == ModBlocks.FUELIUM.get() || block == ModBlocks.BLAZE_JUICE.get())
alterFog(event, fluid ->
{
GlStateManager.setFog(GlStateManager.FogMode.EXP);
event.setDensity(isSap ? 1 : 0.5F);
RenderSystem.fogMode(GlStateManager.FogMode.EXP);
event.setDensity(fluid.getFogDensity());
event.setCanceled(true);
}*/
});
}

@SubscribeEvent
public void setLiquidFogColor(EntityViewRenderEvent.FogColors event)
{
alterFog(event, fluid ->
{
event.setRed(fluid.getFogRed());
event.setGreen(fluid.getFogGreen());
event.setBlue(fluid.getFogBlue());
});
}

private void alterFog(EntityViewRenderEvent event, Consumer<ModFluid> action)
{
Fluid fluid = event.getInfo().getFluidState().getFluid();
if(fluid instanceof ModFluid)
{
action.accept((ModFluid) fluid);
}
}

@SubscribeEvent
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/com/mrcrayfish/vehicle/fluid/BlazeJuice.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
package com.mrcrayfish.vehicle.fluid;

import com.mrcrayfish.vehicle.Reference;
import com.mrcrayfish.vehicle.init.ModBlocks;
import com.mrcrayfish.vehicle.init.ModFluids;
import com.mrcrayfish.vehicle.init.ModItems;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.Item;
import net.minecraft.state.StateContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.ForgeFlowingFluid;

/**
* Author: MrCrayfish
*/
public abstract class BlazeJuice extends ForgeFlowingFluid
public abstract class BlazeJuice extends ModFluid
{
public BlazeJuice()
{
super(new Properties(() -> ModFluids.BLAZE_JUICE.get(), () -> ModFluids.FLOWING_BLAZE_JUICE.get(), FluidAttributes.builder(new ResourceLocation(Reference.MOD_ID, "block/blaze_juice_still"), new ResourceLocation(Reference.MOD_ID, "block/blaze_juice_flowing")).viscosity(800).sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY)).block(() -> ModBlocks.BLAZE_JUICE.get()));
}

@Override
public Item getFilledBucket()
{
return ModItems.BLAZE_JUICE_BUCKET.get();
super(ModFluids.BLAZE_JUICE, ModFluids.FLOWING_BLAZE_JUICE, ModBlocks.BLAZE_JUICE, ModItems.BLAZE_JUICE_BUCKET, 1000, 800, 0.5F, 254, 198, 0);
}

public static class Source extends BlazeJuice
Expand All @@ -38,7 +26,7 @@ public boolean isSource(IFluidState state)
}

@Override
public int getLevel(IFluidState p_207192_1_)
public int getLevel(IFluidState state)
{
return 8;
}
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/com/mrcrayfish/vehicle/fluid/EnderSap.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
package com.mrcrayfish.vehicle.fluid;

import com.mrcrayfish.vehicle.Reference;
import com.mrcrayfish.vehicle.init.ModBlocks;
import com.mrcrayfish.vehicle.init.ModFluids;
import com.mrcrayfish.vehicle.init.ModItems;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.Item;
import net.minecraft.state.StateContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.ForgeFlowingFluid;

/**
* Author: MrCrayfish
*/
public abstract class EnderSap extends ForgeFlowingFluid
public abstract class EnderSap extends ModFluid
{
public EnderSap()
{
super(new Properties(() -> ModFluids.ENDER_SAP.get(), () -> ModFluids.FLOWING_ENDER_SAP.get(), FluidAttributes.builder(new ResourceLocation(Reference.MOD_ID, "block/ender_sap_still"), new ResourceLocation(Reference.MOD_ID, "block/ender_sap_flowing")).viscosity(3000).sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY)).block(() -> ModBlocks.ENDER_SAP.get()));
}

@Override
public Item getFilledBucket()
{
return ModItems.ENDER_SAP_BUCKET.get();
super(ModFluids.ENDER_SAP, ModFluids.FLOWING_ENDER_SAP, ModBlocks.ENDER_SAP, ModItems.ENDER_SAP_BUCKET, 1000, 3000, 1F, 10, 93, 80);
}

public static class Source extends EnderSap
Expand All @@ -38,7 +26,7 @@ public boolean isSource(IFluidState state)
}

@Override
public int getLevel(IFluidState p_207192_1_)
public int getLevel(IFluidState state)
{
return 8;
}
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/com/mrcrayfish/vehicle/fluid/Fuelium.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
package com.mrcrayfish.vehicle.fluid;

import com.mrcrayfish.vehicle.Reference;
import com.mrcrayfish.vehicle.init.ModBlocks;
import com.mrcrayfish.vehicle.init.ModFluids;
import com.mrcrayfish.vehicle.init.ModItems;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.Item;
import net.minecraft.state.StateContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.ForgeFlowingFluid;

/**
* Author: MrCrayfish
*/
public abstract class Fuelium extends ForgeFlowingFluid
public abstract class Fuelium extends ModFluid
{
public Fuelium()
{
super(new Properties(() -> ModFluids.FUELIUM.get(), () -> ModFluids.FLOWING_FUELIUM.get(), FluidAttributes.builder(new ResourceLocation(Reference.MOD_ID, "block/fuelium_still"), new ResourceLocation(Reference.MOD_ID, "block/fuelium_flowing")).sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY).density(900).viscosity(900)).block(() -> ModBlocks.FUELIUM.get()));
}

@Override
public Item getFilledBucket()
{
return ModItems.FUELIUM_BUCKET.get();
super(ModFluids.FUELIUM, ModFluids.FLOWING_FUELIUM, ModBlocks.FUELIUM, ModItems.FUELIUM_BUCKET, 900, 900, 0.5F, 148, 242, 45);
}

public static class Source extends Fuelium
Expand All @@ -38,7 +26,7 @@ public boolean isSource(IFluidState state)
}

@Override
public int getLevel(IFluidState p_207192_1_)
public int getLevel(IFluidState state)
{
return 8;
}
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/com/mrcrayfish/vehicle/fluid/ModFluid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.mrcrayfish.vehicle.fluid;

import com.mrcrayfish.vehicle.Reference;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.ForgeFlowingFluid;
import net.minecraftforge.fml.RegistryObject;

import java.util.function.Supplier;

public abstract class ModFluid extends ForgeFlowingFluid
{
private final float fogDensity, fogRed, fogGreen, fogBlue;
private final Supplier<BucketItem> bucket;

protected ModFluid(Supplier<? extends Fluid> still, Supplier<? extends Fluid> flowing, RegistryObject<FlowingFluidBlock> block,
Supplier<BucketItem> bucket, int density, int viscosity, float fogDensity, int fogRed, int fogGreen, int fogBlue)
{
super(new Properties(still, flowing,
FluidAttributes.builder(getTexture(block, "_still"), getTexture(block, "_flowing"))
.density(density).viscosity(viscosity)
.sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY))
.block(block));

this.fogDensity = fogDensity;
this.fogRed = fogRed / 255F;
this.fogGreen = fogGreen / 255F;
this.fogBlue = fogBlue / 255F;
this.bucket = bucket;
}

private static ResourceLocation getTexture(RegistryObject<FlowingFluidBlock> block, String suffix)
{
return new ResourceLocation(Reference.MOD_ID, "block/" + block.getId().getPath() + suffix);
}

@Override
public Item getFilledBucket()
{
return bucket.get();
}

public float getFogDensity()
{
return fogDensity;
}

public float getFogRed()
{
return fogRed;
}

public float getFogGreen()
{
return fogGreen;
}

public float getFogBlue()
{
return fogBlue;
}
}
11 changes: 11 additions & 0 deletions src/main/resources/data/minecraft/tags/fluids/water.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"replace": false,
"values": [
"vehicle:blaze_juice",
"vehicle:flowing_blaze_juice",
"vehicle:ender_sap",
"vehicle:flowing_ender_sap",
"vehicle:fuelium",
"vehicle:flowing_fuelium"
]
}