Skip to content

Commit

Permalink
VisualOverhaul 3.0.0 - Puddles & Colors
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Motschen committed Mar 14, 2021
1 parent 920bb69 commit e43e483
Show file tree
Hide file tree
Showing 22 changed files with 661 additions and 55 deletions.
6 changes: 0 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ dependencies {

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

modImplementation ("me.sargunvohra.mcmods:autoconfig1u:${project.auto_config_version}") {
exclude group: "net.fabricmc.fabric-api"
}
modImplementation ("me.shedaniel.cloth:config-2:${project.cloth_config_version}") {
exclude group: "net.fabricmc.fabric-api"
}
modImplementation ("io.github.prospector:modmenu:${project.mod_menu_version}") {
exclude group: "net.fabricmc.fabric-api"
}
Expand Down
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.11.1

# Mod Properties
mod_version = 2.0.1
mod_version = 3.0.0
maven_group = eu.midnightdust
archives_base_name = visualoverhaul

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

auto_config_version = 3.2.0-unstable
cloth_config_version = 4.7.0-unstable
mod_menu_version = 1.14.6+build.31
26 changes: 25 additions & 1 deletion src/main/java/eu/midnightdust/visualoverhaul/VisualOverhaul.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
package eu.midnightdust.visualoverhaul;

import eu.midnightdust.visualoverhaul.block.PuddleBlock;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.GameRules;

public class VisualOverhaul implements ModInitializer {
public static final String MOD_ID = "visualoverhaul";
public static final Block Puddle = new PuddleBlock(Fluids.WATER, FabricBlockSettings.of(Material.WATER));
public static GameRules.Key<GameRules.IntRule> PUDDLE_SPAWN_RATE;
public static GameRules.Key<GameRules.IntRule> SNOW_STACK_CHANCE;

public class VisualOverhaul {
public static final Identifier UPDATE_POTION_BOTTLES = new Identifier("visualoverhaul", "brewingstand");
public static final Identifier UPDATE_RECORD = new Identifier("visualoverhaul", "record");
public static final Identifier UPDATE_FURNACE_ITEMS = new Identifier("visualoverhaul", "furnace");

public void onInitialize() {
PUDDLE_SPAWN_RATE = GameRuleRegistry.register("puddleSpawnRate", GameRules.Category.SPAWNING, GameRuleFactory.createIntRule(1));
SNOW_STACK_CHANCE = GameRuleRegistry.register("snowStackChance", GameRules.Category.SPAWNING, GameRuleFactory.createIntRule(1));
Registry.register(Registry.BLOCK, new Identifier(MOD_ID,"puddle"), Puddle);
Registry.register(Registry.ITEM, new Identifier(MOD_ID,"puddle"), new BlockItem(Puddle, new Item.Settings()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import eu.midnightdust.visualoverhaul.block.renderer.FurnaceBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.block.renderer.JukeboxBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.config.VOConfig;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.impl.blockrenderlayer.BlockRenderLayerMapImpl;
import net.fabricmc.fabric.impl.client.rendering.ColorProviderRegistryImpl;
import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
Expand All @@ -23,23 +24,30 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.MusicDiscItem;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BuiltinBiomes;

import java.util.Objects;

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

@SuppressWarnings("deprecation")
public class VisualOverhaulClient implements ClientModInitializer {
public static VOConfig VO_CONFIG;
public static Block JukeBoxTop = new JukeboxTop();

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

@Override
public void onInitializeClient() {
AutoConfig.register(VOConfig.class, JanksonConfigSerializer::new);
VO_CONFIG = AutoConfig.getConfigHolder(VOConfig.class).getConfig();
VOConfig.init("visualoverhaul", VOConfig.class);

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


ClientSidePacketRegistryImpl.INSTANCE.register(UPDATE_POTION_BOTTLES,
(packetContext, attachedData) -> {
BlockPos pos = attachedData.readBlockPos();
Expand All @@ -67,21 +74,25 @@ public void onInitializeClient() {
inv.set(i, attachedData.readItemStack());
}
packetContext.getTaskQueue().execute(() -> {
BrewingStandBlockEntity blockEntity = (BrewingStandBlockEntity) MinecraftClient.getInstance().world.getBlockEntity(pos);
blockEntity.setStack(0,inv.get(0));
blockEntity.setStack(1,inv.get(1));
blockEntity.setStack(2,inv.get(2));
blockEntity.setStack(3,inv.get(3));
blockEntity.setStack(4,inv.get(4));
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof BrewingStandBlockEntity) {
BrewingStandBlockEntity blockEntity = (BrewingStandBlockEntity) client.world.getBlockEntity(pos);
blockEntity.setStack(0, inv.get(0));
blockEntity.setStack(1, inv.get(1));
blockEntity.setStack(2, inv.get(2));
blockEntity.setStack(3, inv.get(3));
blockEntity.setStack(4, inv.get(4));
}
});
});
ClientSidePacketRegistryImpl.INSTANCE.register(UPDATE_RECORD,
(packetContext, attachedData) -> {
BlockPos pos = attachedData.readBlockPos();
ItemStack record = attachedData.readItemStack();
packetContext.getTaskQueue().execute(() -> {
JukeboxBlockEntity blockEntity = (JukeboxBlockEntity)MinecraftClient.getInstance().world.getBlockEntity(pos);
blockEntity.setRecord(record);
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof JukeboxBlockEntity) {
JukeboxBlockEntity blockEntity = (JukeboxBlockEntity) client.world.getBlockEntity(pos);
blockEntity.setRecord(record);
}
});
});
ClientSidePacketRegistryImpl.INSTANCE.register(UPDATE_FURNACE_ITEMS,
Expand All @@ -92,16 +103,54 @@ public void onInitializeClient() {
inv.set(i, attachedData.readItemStack());
}
packetContext.getTaskQueue().execute(() -> {
FurnaceBlockEntity blockEntity = (FurnaceBlockEntity)MinecraftClient.getInstance().world.getBlockEntity(pos);
blockEntity.setStack(0,inv.get(0));
blockEntity.setStack(1,inv.get(1));
blockEntity.setStack(2,inv.get(2));
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof FurnaceBlockEntity) {
FurnaceBlockEntity blockEntity = (FurnaceBlockEntity) client.world.getBlockEntity(pos);
blockEntity.setStack(0, inv.get(0));
blockEntity.setStack(1, inv.get(1));
blockEntity.setStack(2, inv.get(2));
}
});
});

// Register builtin resourcepacks
FabricLoader.getInstance().getModContainer("visualoverhaul").ifPresent(modContainer -> {
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("visualoverhaul:nobottles"), "resourcepacks/nobrewingbottles", modContainer, true);
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("visualoverhaul:fancyfurnace"), "resourcepacks/fancyfurnace", modContainer, true);
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("visualoverhaul:coloredwaterbucket"), "resourcepacks/coloredwaterbucket", modContainer, true);
});

// Context Colored Items
if (VOConfig.coloredItems) {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
int waterColor;
int foliageColor;
if (client.world != null) {
Biome biome = client.world.getBiome(client.player.getBlockPos());
waterColor = biome.getWaterColor();
foliageColor = biome.getFoliageColor();
} else {
waterColor = BuiltinBiomes.PLAINS.getWaterColor();
foliageColor = BuiltinBiomes.PLAINS.getFoliageColor();
}
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> waterColor, VisualOverhaul.Puddle);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.WATER_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.GRASS_BLOCK);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.ACACIA_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.DARK_OAK_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.JUNGLE_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
if (PotionUtil.getPotion(stack) == Potions.WATER && tintIndex == 0) {
return waterColor;
}
return tintIndex > 0 ? -1 : PotionUtil.getColor(stack);
}, Items.POTION);
});
}
// Else just register a static color for our puddle item
else {
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> BuiltinBiomes.PLAINS.getWaterColor(), Puddle);
}
ColorProviderRegistry.BLOCK.register((state, view, pos, tintIndex) -> Objects.requireNonNull(ColorProviderRegistryImpl.BLOCK.get(Blocks.WATER)).getColor(state, view, pos, tintIndex), Puddle);
}
}
134 changes: 134 additions & 0 deletions src/main/java/eu/midnightdust/visualoverhaul/block/PuddleBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package eu.midnightdust.visualoverhaul.block;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.*;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.*;
import net.minecraft.item.*;
import net.minecraft.loot.context.LootContext;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;

import java.util.Collections;
import java.util.List;
import java.util.Random;

public class PuddleBlock extends Block {

protected final FlowableFluid fluid;
public static final VoxelShape COLLISION_SHAPE;

public PuddleBlock(FlowableFluid fluid, AbstractBlock.Settings settings) {
super(settings);
this.fluid = fluid;
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ItemStack itemStack = player.getStackInHand(hand);
if (itemStack.isEmpty()) {
return ActionResult.PASS;
} else {
Item item = itemStack.getItem();
ItemStack waterBottleStack;
if (item == Items.GLASS_BOTTLE) {
if (!world.isClient) {
if (!player.abilities.creativeMode) {
waterBottleStack = PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER);
player.incrementStat(Stats.USE_CAULDRON);
itemStack.decrement(1);
if (itemStack.isEmpty()) {
player.setStackInHand(hand, waterBottleStack);
} else if (!player.inventory.insertStack(waterBottleStack)) {
player.dropItem(waterBottleStack, false);
} else if (player instanceof ServerPlayerEntity) {
((ServerPlayerEntity)player).refreshScreenHandler(player.playerScreenHandler);
}
}

world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
return ActionResult.success(world.isClient);
}
else return ActionResult.FAIL;
}

}
@Override
public boolean hasRandomTicks(BlockState state) {
return true;
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!world.isRaining() && random.nextInt(2000) == 0) {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
}

this.scheduledTick(state, world, pos, random);
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return context.isAbove(COLLISION_SHAPE, pos, true) ? COLLISION_SHAPE : VoxelShapes.empty();
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return COLLISION_SHAPE;
}
@Override
public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return VoxelShapes.empty();
}

public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return true;
}

public FluidState getFluidState(BlockState state) {
return fluid.getFlowing(1,false);
}

@Environment(EnvType.CLIENT)
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
return stateFrom.getFluidState().getFluid().matchesType(this.fluid);
}

public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.INVISIBLE;
}

public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
return Collections.emptyList();
}

public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
}

static {
COLLISION_SHAPE = net.minecraft.block.Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 0.5D, 16.0D);
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.midnightdust.visualoverhaul.block.renderer;

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

if (VisualOverhaulClient.VO_CONFIG.brewingstand) {
if (VOConfig.brewingstand) {
int lightAtBlock = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), blockEntity.getPos());
ItemStack item1 = blockEntity.getStack(0);
ItemStack item2 = blockEntity.getStack(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.midnightdust.visualoverhaul.block.renderer;

import eu.midnightdust.visualoverhaul.VisualOverhaulClient;
import eu.midnightdust.visualoverhaul.config.VOConfig;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.*;
Expand Down Expand Up @@ -62,7 +62,7 @@ public FurnaceBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderD

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

0 comments on commit e43e483

Please sign in to comment.