-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Block::getFogColor to allow custom blocks to control fog colors…
… while inside them. (#4090)
- Loading branch information
1 parent
0b969ef
commit 9e413de
Showing
5 changed files
with
205 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
patches/minecraft/net/minecraft/block/BlockLiquid.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- ../src-base/minecraft/net/minecraft/block/BlockLiquid.java | ||
+++ ../src-work/minecraft/net/minecraft/block/BlockLiquid.java | ||
@@ -452,4 +452,29 @@ | ||
{ | ||
return BlockFaceShape.UNDEFINED; | ||
} | ||
+ | ||
+ @Override | ||
+ @SideOnly (Side.CLIENT) | ||
+ public Vec3d getFogColor(World world, BlockPos pos, IBlockState state, Entity entity, Vec3d originalColor, float partialTicks) | ||
+ { | ||
+ Vec3d viewport = net.minecraft.client.renderer.ActiveRenderInfo.func_178806_a(entity, partialTicks); | ||
+ | ||
+ if (state.func_185904_a().func_76224_d()) | ||
+ { | ||
+ float height = 0.0F; | ||
+ if (state.func_177230_c() instanceof BlockLiquid) | ||
+ { | ||
+ height = func_149801_b(state.func_177229_b(field_176367_b)) - 0.11111111F; | ||
+ } | ||
+ float f1 = (float) (pos.func_177956_o() + 1) - height; | ||
+ if (viewport.field_72448_b > (double)f1) | ||
+ { | ||
+ BlockPos upPos = pos.func_177984_a(); | ||
+ IBlockState upState = world.func_180495_p(upPos); | ||
+ return upState.func_177230_c().getFogColor(world, upPos, upState, entity, originalColor, partialTicks); | ||
+ } | ||
+ } | ||
+ | ||
+ return super.getFogColor(world, pos, state, entity, originalColor, partialTicks); | ||
+ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/net/minecraftforge/debug/FogColorInsideMaterialTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package net.minecraftforge.debug; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.client.renderer.block.model.ModelResourceLocation; | ||
import net.minecraft.client.renderer.block.statemap.StateMapperBase; | ||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemBlock; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.client.event.ModelRegistryEvent; | ||
import net.minecraftforge.client.model.ModelLoader; | ||
import net.minecraftforge.event.RegistryEvent; | ||
import net.minecraftforge.fluids.BlockFluidClassic; | ||
import net.minecraftforge.fluids.FluidRegistry; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder; | ||
|
||
@EventBusSubscriber | ||
@Mod (modid = FogColorInsideMaterialTest.MOD_ID, name = "FogColor inside material debug.", version = "1.0", acceptableRemoteVersions = "*") | ||
public class FogColorInsideMaterialTest | ||
{ | ||
|
||
public static final String MOD_ID = "fogcolorinsidematerialtest"; | ||
|
||
@ObjectHolder ("test_fluid") | ||
public static final Block FLUID_BLOCK = null; | ||
@ObjectHolder ("test_fluid") | ||
public static final Item FLUID_ITEM = null; | ||
|
||
@SubscribeEvent | ||
public static void registerBlocks(RegistryEvent.Register<Block> event) | ||
{ | ||
Block fluid = new BlockFluidClassic(FluidRegistry.WATER, Material.WATER) | ||
{ | ||
@Override | ||
public Vec3d getFogColor(World world, BlockPos pos, IBlockState state, Entity entity, Vec3d originalColor, float partialTicks) | ||
{ | ||
return new Vec3d(0.6F, 0.1F, 0.0F); | ||
} | ||
}; | ||
fluid.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); | ||
fluid.setUnlocalizedName(MOD_ID + ":" + "test_fluid"); | ||
fluid.setRegistryName("test_fluid"); | ||
event.getRegistry().register(fluid); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void registerItems(RegistryEvent.Register<Item> event) | ||
{ | ||
event.getRegistry().register(new ItemBlock(FLUID_BLOCK).setRegistryName(FLUID_BLOCK.getRegistryName())); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void registerModels(ModelRegistryEvent event) | ||
{ | ||
ModelResourceLocation fluidLocation = new ModelResourceLocation(MOD_ID.toLowerCase() + ":test_fluid", "fluid"); | ||
ModelLoader.registerItemVariants(FLUID_ITEM); | ||
ModelLoader.setCustomMeshDefinition(FLUID_ITEM, stack -> fluidLocation); | ||
ModelLoader.setCustomStateMapper(FLUID_BLOCK, new StateMapperBase() | ||
{ | ||
@Override | ||
protected ModelResourceLocation getModelResourceLocation(IBlockState state) | ||
{ | ||
return fluidLocation; | ||
} | ||
}); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/test/resources/assets/fogcolorinsidematerialtest/blockstates/test_fluid.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"forge_marker": 1, | ||
"defaults": { | ||
"model": "forge:fluid" | ||
}, | ||
"variants": { | ||
"fluid": [ | ||
{ | ||
"custom": { | ||
"fluid": "test_fluid" | ||
} | ||
} | ||
] | ||
} | ||
} |