Skip to content

Commit e43e483

Browse files
committed
VisualOverhaul 3.0.0 - Puddles & Colors
Switched to MidnightConfig (No need to seperately download AutoConfig & ClothConfig anymore) Adds puddles which spawn during rain and can be used to fill a water bottle. (Game rule: "puddleSpawnRate") Also, snow layers can now pile up during snow storms. (Game rule: "snowStackChance") Items which are colored in their block form also show the color corresponding to the biome as an item. (Toggleable via config)
1 parent 920bb69 commit e43e483

22 files changed

+661
-55
lines changed

build.gradle

-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ dependencies {
2525

2626
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
2727

28-
modImplementation ("me.sargunvohra.mcmods:autoconfig1u:${project.auto_config_version}") {
29-
exclude group: "net.fabricmc.fabric-api"
30-
}
31-
modImplementation ("me.shedaniel.cloth:config-2:${project.cloth_config_version}") {
32-
exclude group: "net.fabricmc.fabric-api"
33-
}
3428
modImplementation ("io.github.prospector:modmenu:${project.mod_menu_version}") {
3529
exclude group: "net.fabricmc.fabric-api"
3630
}

gradle.properties

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ org.gradle.jvmargs=-Xmx1G
88
loader_version=0.11.1
99

1010
# Mod Properties
11-
mod_version = 2.0.1
11+
mod_version = 3.0.0
1212
maven_group = eu.midnightdust
1313
archives_base_name = visualoverhaul
1414

1515
# Dependencies
1616
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
1717
fabric_version=0.29.4+1.16
1818

19-
auto_config_version = 3.2.0-unstable
20-
cloth_config_version = 4.7.0-unstable
2119
mod_menu_version = 1.14.6+build.31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
package eu.midnightdust.visualoverhaul;
22

3+
import eu.midnightdust.visualoverhaul.block.PuddleBlock;
4+
import net.fabricmc.api.ModInitializer;
5+
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
6+
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
7+
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
8+
import net.minecraft.block.Block;
9+
import net.minecraft.block.Material;
10+
import net.minecraft.fluid.Fluids;
11+
import net.minecraft.item.BlockItem;
12+
import net.minecraft.item.Item;
313
import net.minecraft.util.Identifier;
14+
import net.minecraft.util.registry.Registry;
15+
import net.minecraft.world.GameRules;
16+
17+
public class VisualOverhaul implements ModInitializer {
18+
public static final String MOD_ID = "visualoverhaul";
19+
public static final Block Puddle = new PuddleBlock(Fluids.WATER, FabricBlockSettings.of(Material.WATER));
20+
public static GameRules.Key<GameRules.IntRule> PUDDLE_SPAWN_RATE;
21+
public static GameRules.Key<GameRules.IntRule> SNOW_STACK_CHANCE;
422

5-
public class VisualOverhaul {
623
public static final Identifier UPDATE_POTION_BOTTLES = new Identifier("visualoverhaul", "brewingstand");
724
public static final Identifier UPDATE_RECORD = new Identifier("visualoverhaul", "record");
825
public static final Identifier UPDATE_FURNACE_ITEMS = new Identifier("visualoverhaul", "furnace");
26+
27+
public void onInitialize() {
28+
PUDDLE_SPAWN_RATE = GameRuleRegistry.register("puddleSpawnRate", GameRules.Category.SPAWNING, GameRuleFactory.createIntRule(1));
29+
SNOW_STACK_CHANCE = GameRuleRegistry.register("snowStackChance", GameRules.Category.SPAWNING, GameRuleFactory.createIntRule(1));
30+
Registry.register(Registry.BLOCK, new Identifier(MOD_ID,"puddle"), Puddle);
31+
Registry.register(Registry.ITEM, new Identifier(MOD_ID,"puddle"), new BlockItem(Puddle, new Item.Settings()));
32+
}
933
}

src/main/java/eu/midnightdust/visualoverhaul/VisualOverhaulClient.java

+68-19
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import eu.midnightdust.visualoverhaul.block.renderer.FurnaceBlockEntityRenderer;
66
import eu.midnightdust.visualoverhaul.block.renderer.JukeboxBlockEntityRenderer;
77
import eu.midnightdust.visualoverhaul.config.VOConfig;
8-
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
9-
import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer;
108
import net.fabricmc.api.ClientModInitializer;
9+
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
1110
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
11+
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
1212
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
1313
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
1414
import net.fabricmc.fabric.impl.blockrenderlayer.BlockRenderLayerMapImpl;
15+
import net.fabricmc.fabric.impl.client.rendering.ColorProviderRegistryImpl;
1516
import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl;
1617
import net.fabricmc.loader.api.FabricLoader;
1718
import net.minecraft.block.Block;
@@ -23,23 +24,30 @@
2324
import net.minecraft.client.MinecraftClient;
2425
import net.minecraft.client.render.RenderLayer;
2526
import net.minecraft.item.ItemStack;
27+
import net.minecraft.item.Items;
2628
import net.minecraft.item.MusicDiscItem;
29+
import net.minecraft.potion.PotionUtil;
30+
import net.minecraft.potion.Potions;
2731
import net.minecraft.util.Identifier;
2832
import net.minecraft.util.collection.DefaultedList;
2933
import net.minecraft.util.math.BlockPos;
3034
import net.minecraft.util.registry.Registry;
35+
import net.minecraft.world.biome.Biome;
36+
import net.minecraft.world.biome.BuiltinBiomes;
37+
38+
import java.util.Objects;
3139

3240
import static eu.midnightdust.visualoverhaul.VisualOverhaul.*;
3341

42+
@SuppressWarnings("deprecation")
3443
public class VisualOverhaulClient implements ClientModInitializer {
35-
public static VOConfig VO_CONFIG;
36-
public static Block JukeBoxTop = new JukeboxTop();
3744

45+
public static Block JukeBoxTop = new JukeboxTop();
46+
private final MinecraftClient client = MinecraftClient.getInstance();
3847

3948
@Override
4049
public void onInitializeClient() {
41-
AutoConfig.register(VOConfig.class, JanksonConfigSerializer::new);
42-
VO_CONFIG = AutoConfig.getConfigHolder(VOConfig.class).getConfig();
50+
VOConfig.init("visualoverhaul", VOConfig.class);
4351

4452
// Block only registered on client, because it's just used for the renderer //
4553
Registry.register(Registry.BLOCK, new Identifier("visualoverhaul","jukebox_top"), JukeBoxTop);
@@ -58,7 +66,6 @@ public void onInitializeClient() {
5866
}
5967
});
6068

61-
6269
ClientSidePacketRegistryImpl.INSTANCE.register(UPDATE_POTION_BOTTLES,
6370
(packetContext, attachedData) -> {
6471
BlockPos pos = attachedData.readBlockPos();
@@ -67,21 +74,25 @@ public void onInitializeClient() {
6774
inv.set(i, attachedData.readItemStack());
6875
}
6976
packetContext.getTaskQueue().execute(() -> {
70-
BrewingStandBlockEntity blockEntity = (BrewingStandBlockEntity) MinecraftClient.getInstance().world.getBlockEntity(pos);
71-
blockEntity.setStack(0,inv.get(0));
72-
blockEntity.setStack(1,inv.get(1));
73-
blockEntity.setStack(2,inv.get(2));
74-
blockEntity.setStack(3,inv.get(3));
75-
blockEntity.setStack(4,inv.get(4));
77+
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof BrewingStandBlockEntity) {
78+
BrewingStandBlockEntity blockEntity = (BrewingStandBlockEntity) client.world.getBlockEntity(pos);
79+
blockEntity.setStack(0, inv.get(0));
80+
blockEntity.setStack(1, inv.get(1));
81+
blockEntity.setStack(2, inv.get(2));
82+
blockEntity.setStack(3, inv.get(3));
83+
blockEntity.setStack(4, inv.get(4));
84+
}
7685
});
7786
});
7887
ClientSidePacketRegistryImpl.INSTANCE.register(UPDATE_RECORD,
7988
(packetContext, attachedData) -> {
8089
BlockPos pos = attachedData.readBlockPos();
8190
ItemStack record = attachedData.readItemStack();
8291
packetContext.getTaskQueue().execute(() -> {
83-
JukeboxBlockEntity blockEntity = (JukeboxBlockEntity)MinecraftClient.getInstance().world.getBlockEntity(pos);
84-
blockEntity.setRecord(record);
92+
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof JukeboxBlockEntity) {
93+
JukeboxBlockEntity blockEntity = (JukeboxBlockEntity) client.world.getBlockEntity(pos);
94+
blockEntity.setRecord(record);
95+
}
8596
});
8697
});
8798
ClientSidePacketRegistryImpl.INSTANCE.register(UPDATE_FURNACE_ITEMS,
@@ -92,16 +103,54 @@ public void onInitializeClient() {
92103
inv.set(i, attachedData.readItemStack());
93104
}
94105
packetContext.getTaskQueue().execute(() -> {
95-
FurnaceBlockEntity blockEntity = (FurnaceBlockEntity)MinecraftClient.getInstance().world.getBlockEntity(pos);
96-
blockEntity.setStack(0,inv.get(0));
97-
blockEntity.setStack(1,inv.get(1));
98-
blockEntity.setStack(2,inv.get(2));
106+
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof FurnaceBlockEntity) {
107+
FurnaceBlockEntity blockEntity = (FurnaceBlockEntity) client.world.getBlockEntity(pos);
108+
blockEntity.setStack(0, inv.get(0));
109+
blockEntity.setStack(1, inv.get(1));
110+
blockEntity.setStack(2, inv.get(2));
111+
}
99112
});
100113
});
101114

115+
// Register builtin resourcepacks
102116
FabricLoader.getInstance().getModContainer("visualoverhaul").ifPresent(modContainer -> {
103117
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("visualoverhaul:nobottles"), "resourcepacks/nobrewingbottles", modContainer, true);
104118
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("visualoverhaul:fancyfurnace"), "resourcepacks/fancyfurnace", modContainer, true);
119+
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("visualoverhaul:coloredwaterbucket"), "resourcepacks/coloredwaterbucket", modContainer, true);
105120
});
121+
122+
// Context Colored Items
123+
if (VOConfig.coloredItems) {
124+
ClientTickEvents.END_CLIENT_TICK.register(client -> {
125+
int waterColor;
126+
int foliageColor;
127+
if (client.world != null) {
128+
Biome biome = client.world.getBiome(client.player.getBlockPos());
129+
waterColor = biome.getWaterColor();
130+
foliageColor = biome.getFoliageColor();
131+
} else {
132+
waterColor = BuiltinBiomes.PLAINS.getWaterColor();
133+
foliageColor = BuiltinBiomes.PLAINS.getFoliageColor();
134+
}
135+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> waterColor, VisualOverhaul.Puddle);
136+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.WATER_BUCKET);
137+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.GRASS_BLOCK);
138+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.ACACIA_LEAVES);
139+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.DARK_OAK_LEAVES);
140+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.JUNGLE_LEAVES);
141+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES);
142+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
143+
if (PotionUtil.getPotion(stack) == Potions.WATER && tintIndex == 0) {
144+
return waterColor;
145+
}
146+
return tintIndex > 0 ? -1 : PotionUtil.getColor(stack);
147+
}, Items.POTION);
148+
});
149+
}
150+
// Else just register a static color for our puddle item
151+
else {
152+
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> BuiltinBiomes.PLAINS.getWaterColor(), Puddle);
153+
}
154+
ColorProviderRegistry.BLOCK.register((state, view, pos, tintIndex) -> Objects.requireNonNull(ColorProviderRegistryImpl.BLOCK.get(Blocks.WATER)).getColor(state, view, pos, tintIndex), Puddle);
106155
}
107156
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package eu.midnightdust.visualoverhaul.block;
2+
3+
import net.fabricmc.api.EnvType;
4+
import net.fabricmc.api.Environment;
5+
import net.minecraft.block.*;
6+
import net.minecraft.entity.ai.pathing.NavigationType;
7+
import net.minecraft.entity.player.PlayerEntity;
8+
import net.minecraft.fluid.*;
9+
import net.minecraft.item.*;
10+
import net.minecraft.loot.context.LootContext;
11+
import net.minecraft.potion.PotionUtil;
12+
import net.minecraft.potion.Potions;
13+
import net.minecraft.server.network.ServerPlayerEntity;
14+
import net.minecraft.server.world.ServerWorld;
15+
import net.minecraft.sound.BlockSoundGroup;
16+
import net.minecraft.sound.SoundCategory;
17+
import net.minecraft.sound.SoundEvents;
18+
import net.minecraft.stat.Stats;
19+
import net.minecraft.util.ActionResult;
20+
import net.minecraft.util.Hand;
21+
import net.minecraft.util.hit.BlockHitResult;
22+
import net.minecraft.util.math.BlockPos;
23+
import net.minecraft.util.math.Direction;
24+
import net.minecraft.util.shape.VoxelShape;
25+
import net.minecraft.util.shape.VoxelShapes;
26+
import net.minecraft.world.BlockView;
27+
import net.minecraft.world.World;
28+
import net.minecraft.world.WorldAccess;
29+
import net.minecraft.world.WorldView;
30+
31+
import java.util.Collections;
32+
import java.util.List;
33+
import java.util.Random;
34+
35+
public class PuddleBlock extends Block {
36+
37+
protected final FlowableFluid fluid;
38+
public static final VoxelShape COLLISION_SHAPE;
39+
40+
public PuddleBlock(FlowableFluid fluid, AbstractBlock.Settings settings) {
41+
super(settings);
42+
this.fluid = fluid;
43+
}
44+
@Override
45+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
46+
ItemStack itemStack = player.getStackInHand(hand);
47+
if (itemStack.isEmpty()) {
48+
return ActionResult.PASS;
49+
} else {
50+
Item item = itemStack.getItem();
51+
ItemStack waterBottleStack;
52+
if (item == Items.GLASS_BOTTLE) {
53+
if (!world.isClient) {
54+
if (!player.abilities.creativeMode) {
55+
waterBottleStack = PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER);
56+
player.incrementStat(Stats.USE_CAULDRON);
57+
itemStack.decrement(1);
58+
if (itemStack.isEmpty()) {
59+
player.setStackInHand(hand, waterBottleStack);
60+
} else if (!player.inventory.insertStack(waterBottleStack)) {
61+
player.dropItem(waterBottleStack, false);
62+
} else if (player instanceof ServerPlayerEntity) {
63+
((ServerPlayerEntity)player).refreshScreenHandler(player.playerScreenHandler);
64+
}
65+
}
66+
67+
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
68+
world.setBlockState(pos, Blocks.AIR.getDefaultState());
69+
}
70+
return ActionResult.success(world.isClient);
71+
}
72+
else return ActionResult.FAIL;
73+
}
74+
75+
}
76+
@Override
77+
public boolean hasRandomTicks(BlockState state) {
78+
return true;
79+
}
80+
@Override
81+
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
82+
if (!world.isRaining() && random.nextInt(2000) == 0) {
83+
world.setBlockState(pos, Blocks.AIR.getDefaultState());
84+
}
85+
86+
this.scheduledTick(state, world, pos, random);
87+
}
88+
89+
@Override
90+
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
91+
return context.isAbove(COLLISION_SHAPE, pos, true) ? COLLISION_SHAPE : VoxelShapes.empty();
92+
}
93+
@Override
94+
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
95+
return COLLISION_SHAPE;
96+
}
97+
@Override
98+
public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
99+
return VoxelShapes.empty();
100+
}
101+
102+
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
103+
return true;
104+
}
105+
106+
public FluidState getFluidState(BlockState state) {
107+
return fluid.getFlowing(1,false);
108+
}
109+
110+
@Environment(EnvType.CLIENT)
111+
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
112+
return stateFrom.getFluidState().getFluid().matchesType(this.fluid);
113+
}
114+
115+
public BlockRenderType getRenderType(BlockState state) {
116+
return BlockRenderType.INVISIBLE;
117+
}
118+
119+
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
120+
return Collections.emptyList();
121+
}
122+
123+
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
124+
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
125+
}
126+
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
127+
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
128+
}
129+
130+
static {
131+
COLLISION_SHAPE = net.minecraft.block.Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 0.5D, 16.0D);
132+
}
133+
}
134+

src/main/java/eu/midnightdust/visualoverhaul/block/renderer/BrewingStandBlockEntityRenderer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package eu.midnightdust.visualoverhaul.block.renderer;
22

3-
import eu.midnightdust.visualoverhaul.VisualOverhaulClient;
3+
import eu.midnightdust.visualoverhaul.config.VOConfig;
44
import net.fabricmc.api.EnvType;
55
import net.fabricmc.api.Environment;
66
import net.minecraft.block.entity.BrewingStandBlockEntity;
@@ -25,7 +25,7 @@ public BrewingStandBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRe
2525
@Override
2626
public void render(BrewingStandBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
2727

28-
if (VisualOverhaulClient.VO_CONFIG.brewingstand) {
28+
if (VOConfig.brewingstand) {
2929
int lightAtBlock = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), blockEntity.getPos());
3030
ItemStack item1 = blockEntity.getStack(0);
3131
ItemStack item2 = blockEntity.getStack(1);

src/main/java/eu/midnightdust/visualoverhaul/block/renderer/FurnaceBlockEntityRenderer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package eu.midnightdust.visualoverhaul.block.renderer;
22

3-
import eu.midnightdust.visualoverhaul.VisualOverhaulClient;
3+
import eu.midnightdust.visualoverhaul.config.VOConfig;
44
import net.fabricmc.api.EnvType;
55
import net.fabricmc.api.Environment;
66
import net.minecraft.block.*;
@@ -62,7 +62,7 @@ public FurnaceBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderD
6262

6363
@Override
6464
public void render(FurnaceBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
65-
if (VisualOverhaulClient.VO_CONFIG.furnace && blockEntity.getCachedState().getBlock().is(Blocks.FURNACE)) {
65+
if (VOConfig.furnace && blockEntity.getCachedState().getBlock().is(Blocks.FURNACE)) {
6666
BlockState blockState = blockEntity.getCachedState();
6767
int lightAtBlock = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), blockEntity.getPos().offset(blockState.get(AbstractFurnaceBlock.FACING)));
6868
ItemStack item1 = blockEntity.getStack(0);

0 commit comments

Comments
 (0)