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

Bugfixes introduced in Schnowy 2022 #35

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
16 changes: 16 additions & 0 deletions src/main/generated/data/minecraft/tags/blocks/fences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"replace": false,
"values": [
"schnowy:snowed_dark_oak_fence",
"schnowy:snowed_warped_fence",
"schnowy:snowed_crimson_fence",
"schnowy:snowed_jungle_fence",
"schnowy:snowed_oak_fence",
"schnowy:snowed_spruce_fence",
"schnowy:snowed_mangrove_fence",
"schnowy:snowed_birch_fence",
"schnowy:snowed_cherry_fence",
"schnowy:snowed_acacia_fence",
"schnowy:snowed_nether_brick_fence"
]
}
141 changes: 141 additions & 0 deletions src/main/generated/data/minecraft/tags/blocks/mineable/shovel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"replace": false,
"values": [
"schnowy:snowed_dandelion",
"schnowy:snowed_poppy",
"schnowy:snowed_oxeye_daisy",
"schnowy:snowed_white_tulip",
"schnowy:snowed_blue_orchid",
"schnowy:snowed_allium",
"schnowy:snowed_lily_of_the_valley",
"schnowy:snowed_orange_tulip",
"schnowy:snowed_wither_rose",
"schnowy:snowed_red_tulip",
"schnowy:snowed_cornflower",
"schnowy:snowed_azure_bluet",
"schnowy:snowed_pink_tulip",
"schnowy:snowed_torchflower",
"schnowy:snowed_birch_slab",
"schnowy:snowed_blackstone_slab",
"schnowy:snowed_deepslate_brick_slab",
"schnowy:snowed_bamboo_mosaic_slab",
"schnowy:snowed_mossy_stone_brick_slab",
"schnowy:snowed_waxed_weathered_cut_copper_slab",
"schnowy:snowed_smooth_sandstone_slab",
"schnowy:snowed_waxed_exposed_cut_copper_slab",
"schnowy:snowed_oak_slab",
"schnowy:snowed_cut_copper_slab",
"schnowy:snowed_mossy_cobblestone_slab",
"schnowy:snowed_acacia_slab",
"schnowy:snowed_cobbled_deepslate_slab",
"schnowy:snowed_andesite_slab",
"schnowy:snowed_smooth_red_sandstone_slab",
"schnowy:snowed_crimson_slab",
"schnowy:snowed_end_stone_brick_slab",
"schnowy:snowed_waxed_cut_copper_slab",
"schnowy:snowed_warped_slab",
"schnowy:snowed_cobblestone_slab",
"schnowy:snowed_cherry_slab",
"schnowy:snowed_deepslate_tile_slab",
"schnowy:snowed_polished_blackstone_slab",
"schnowy:snowed_spruce_slab",
"schnowy:snowed_diorite_slab",
"schnowy:snowed_purpur_slab",
"schnowy:snowed_mangrove_slab",
"schnowy:snowed_exposed_cut_copper_slab",
"schnowy:snowed_jungle_slab",
"schnowy:snowed_dark_oak_slab",
"schnowy:snowed_oxidized_cut_copper_slab",
"schnowy:snowed_polished_deepslate_slab",
"schnowy:snowed_bamboo_slab",
"schnowy:snowed_brick_slab",
"schnowy:snowed_polished_blackstone_brick_slab",
"schnowy:snowed_weathered_cut_copper_slab",
"schnowy:snowed_stone_brick_slab",
"schnowy:snowed_smooth_quartz_slab",
"schnowy:snowed_granite_slab",
"schnowy:snowed_polished_andesite_slab",
"schnowy:snowed_sandstone_slab",
"schnowy:snowed_nether_brick_slab",
"schnowy:snowed_cut_red_sandstone_slab",
"schnowy:snowed_red_nether_brick_slab",
"schnowy:snowed_stone_slab",
"schnowy:snowed_red_sandstone_slab",
"schnowy:snowed_polished_diorite_slab",
"schnowy:snowed_prismarine_brick_slab",
"schnowy:snowed_prismarine_slab",
"schnowy:snowed_mud_brick_slab",
"schnowy:snowed_quartz_slab",
"schnowy:snowed_polished_granite_slab",
"schnowy:snowed_waxed_oxidized_cut_copper_slab",
"schnowy:snowed_cut_sandstone_slab",
"schnowy:snowed_dark_prismarine_slab",
"schnowy:snowed_mangrove_stairs",
"schnowy:snowed_nether_brick_stairs",
"schnowy:snowed_deepslate_tile_stairs",
"schnowy:snowed_deepslate_brick_stairs",
"schnowy:snowed_cobblestone_stairs",
"schnowy:snowed_polished_andesite_stairs",
"schnowy:snowed_purpur_stairs",
"schnowy:snowed_granite_stairs",
"schnowy:snowed_mossy_cobblestone_stairs",
"schnowy:snowed_quartz_stairs",
"schnowy:snowed_warped_stairs",
"schnowy:snowed_prismarine_brick_stairs",
"schnowy:snowed_mossy_stone_brick_stairs",
"schnowy:snowed_prismarine_stairs",
"schnowy:snowed_cherry_stairs",
"schnowy:snowed_stone_stairs",
"schnowy:snowed_smooth_quartz_stairs",
"schnowy:snowed_cobbled_deepslate_stairs",
"schnowy:snowed_acacia_stairs",
"schnowy:snowed_dark_prismarine_stairs",
"schnowy:snowed_cut_copper_stairs",
"schnowy:snowed_blackstone_stairs",
"schnowy:snowed_oxidized_cut_copper_stairs",
"schnowy:snowed_smooth_red_sandstone_stairs",
"schnowy:snowed_waxed_exposed_cut_copper_stairs",
"schnowy:snowed_brick_stairs",
"schnowy:snowed_exposed_cut_copper_stairs",
"schnowy:snowed_crimson_stairs",
"schnowy:snowed_andesite_stairs",
"schnowy:snowed_birch_stairs",
"schnowy:snowed_smooth_sandstone_stairs",
"schnowy:snowed_mud_brick_stairs",
"schnowy:snowed_red_nether_brick_stairs",
"schnowy:snowed_polished_deepslate_stairs",
"schnowy:snowed_end_stone_brick_stairs",
"schnowy:snowed_sandstone_stairs",
"schnowy:snowed_polished_diorite_stairs",
"schnowy:snowed_polished_granite_stairs",
"schnowy:snowed_bamboo_stairs",
"schnowy:snowed_polished_blackstone_brick_stairs",
"schnowy:snowed_jungle_stairs",
"schnowy:snowed_polished_blackstone_stairs",
"schnowy:snowed_spruce_stairs",
"schnowy:snowed_dark_oak_stairs",
"schnowy:snowed_waxed_weathered_cut_copper_stairs",
"schnowy:snowed_waxed_cut_copper_stairs",
"schnowy:snowed_waxed_oxidized_cut_copper_stairs",
"schnowy:snowed_red_sandstone_stairs",
"schnowy:snowed_stone_brick_stairs",
"schnowy:snowed_oak_stairs",
"schnowy:snowed_diorite_stairs",
"schnowy:snowed_bamboo_mosaic_stairs",
"schnowy:snowed_weathered_cut_copper_stairs",
"schnowy:snowed_dark_oak_fence",
"schnowy:snowed_warped_fence",
"schnowy:snowed_crimson_fence",
"schnowy:snowed_jungle_fence",
"schnowy:snowed_oak_fence",
"schnowy:snowed_spruce_fence",
"schnowy:snowed_mangrove_fence",
"schnowy:snowed_birch_fence",
"schnowy:snowed_cherry_fence",
"schnowy:snowed_acacia_fence",
"schnowy:snowed_nether_brick_fence",
"schnowy:snowed_grass",
"schnowy:snowed_fern",
"schnowy:snowed_dead_bush"
]
}
33 changes: 33 additions & 0 deletions src/main/generated/data/minecraft/tags/blocks/snow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"replace": false,
"values": [
"schnowy:snowed_dandelion",
"schnowy:snowed_poppy",
"schnowy:snowed_oxeye_daisy",
"schnowy:snowed_white_tulip",
"schnowy:snowed_blue_orchid",
"schnowy:snowed_allium",
"schnowy:snowed_lily_of_the_valley",
"schnowy:snowed_orange_tulip",
"schnowy:snowed_wither_rose",
"schnowy:snowed_red_tulip",
"schnowy:snowed_cornflower",
"schnowy:snowed_azure_bluet",
"schnowy:snowed_pink_tulip",
"schnowy:snowed_torchflower",
"schnowy:snowed_dark_oak_fence",
"schnowy:snowed_warped_fence",
"schnowy:snowed_crimson_fence",
"schnowy:snowed_jungle_fence",
"schnowy:snowed_oak_fence",
"schnowy:snowed_spruce_fence",
"schnowy:snowed_mangrove_fence",
"schnowy:snowed_birch_fence",
"schnowy:snowed_cherry_fence",
"schnowy:snowed_acacia_fence",
"schnowy:snowed_nether_brick_fence",
"schnowy:snowed_grass",
"schnowy:snowed_fern",
"schnowy:snowed_dead_bush"
]
}
16 changes: 16 additions & 0 deletions src/main/generated/data/minecraft/tags/blocks/wooden_fences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"replace": false,
"values": [
"schnowy:snowed_dark_oak_fence",
"schnowy:snowed_warped_fence",
"schnowy:snowed_crimson_fence",
"schnowy:snowed_jungle_fence",
"schnowy:snowed_oak_fence",
"schnowy:snowed_spruce_fence",
"schnowy:snowed_mangrove_fence",
"schnowy:snowed_birch_fence",
"schnowy:snowed_cherry_fence",
"schnowy:snowed_acacia_fence",
"schnowy:snowed_nether_brick_fence"
]
}
115 changes: 115 additions & 0 deletions src/main/java/dev/schmarrn/schnowy/common/FallingSnowUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package dev.schmarrn.schnowy.common;

import dev.schmarrn.schnowy.common.blocks.SchnowyProperties;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;

public class FallingSnowUtil {
public static BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos, Block parent) {
if (world instanceof ServerLevel level && !state.canSurvive(world, pos) && direction.equals(Direction.DOWN)) {
// Find lowest BlockState that isn't air anymore
BlockPos belowPos = neighborPos;
while (level.getBlockState(belowPos) == Blocks.AIR.defaultBlockState()) {
belowPos = belowPos.below();
}
BlockState belowState = level.getBlockState(belowPos);

// Get the Layers of the Block that cannot survive anymore
int layers = state.getValue(BlockStateProperties.LAYERS);

// Block snow should fall on block corresponding with belowState
if (belowState.hasProperty(BlockStateProperties.LAYERS)) {
int layersToRemove = 8 - belowState.getValue(BlockStateProperties.LAYERS);

// The Block cannot fit into the lower block
if (layers > layersToRemove) {
// Fill up the lower block
if (belowState.is(Blocks.SNOW)) {
level.setBlockAndUpdate(belowPos, Blocks.SNOW_BLOCK.defaultBlockState());
} else {
level.setBlockAndUpdate(belowPos, belowState.setValue(BlockStateProperties.LAYERS, 8));
}
// If there was no air between the blocks
if (belowState == neighborState) {
// Just Remove the required layers
return state.setValue(BlockStateProperties.LAYERS, layers - layersToRemove);
} else {
// otherwise, destroy the snow layer block, and set the destroyed block on top
// of the lower block
level.setBlockAndUpdate(belowPos.above(), state.setValue(BlockStateProperties.LAYERS, layers - layersToRemove));
return parent.defaultBlockState();
}
} else {
// If the block can fit into the lower block
level.setBlockAndUpdate(belowPos, belowState.setValue(BlockStateProperties.LAYERS, belowState.getValue(BlockStateProperties.LAYERS) + layers));
return parent.defaultBlockState();
}
} else if (belowState.hasProperty(SchnowyProperties.HALF_LAYERS)) {
int layersToRemove = 4 - belowState.getValue(SchnowyProperties.HALF_LAYERS);

// The Block cannot fit into the lower block
if (layers > layersToRemove) {
// Fill up the lower block
level.setBlockAndUpdate(belowPos, belowState.setValue(SchnowyProperties.HALF_LAYERS, 4));
// If there was no air between the blocks
if (belowState == neighborState) {
// Just Remove the required layers
return state.setValue(BlockStateProperties.LAYERS, layers - layersToRemove);
} else {
// otherwise, destroy the snow layer block, and set the destroyed block on top
// of the lower block
level.setBlockAndUpdate(belowPos.above(), state.setValue(BlockStateProperties.LAYERS, layers - layersToRemove));
return parent.defaultBlockState();
}
} else {
// If the block can fit into the lower block
level.setBlockAndUpdate(belowPos, belowState.setValue(SchnowyProperties.HALF_LAYERS, belowState.getValue(SchnowyProperties.HALF_LAYERS) + layers));
return parent.defaultBlockState();
}
} else if (ReplaceableBlocks.withSnow(belowState) != null) {
// If we have a snowloggable block
BlockState snowlogged = ReplaceableBlocks.withSnow(belowState);

if (snowlogged.hasProperty(BlockStateProperties.LAYERS)) {
// We can fit 8 layers into it - the most that can be dropped are technically seven layers, so it can
// fit into this block no problem
level.setBlockAndUpdate(belowPos, snowlogged.setValue(BlockStateProperties.LAYERS, layers));
} else if (snowlogged.hasProperty(SchnowyProperties.HALF_LAYERS)) {
// now we could run into problems
if (layers <= 4) {
level.setBlockAndUpdate(belowPos, snowlogged.setValue(SchnowyProperties.HALF_LAYERS, layers));
} else {
// Here is the problem: we have more layers than we can fit into the block, so we need to
// put the remaining layers above
level.setBlockAndUpdate(belowPos, snowlogged.setValue(SchnowyProperties.HALF_LAYERS, 4));

// If there was no air between the blocks
if (belowState == neighborState) {
// Just Remove the required layers
return state.setValue(BlockStateProperties.LAYERS, layers - 4);
} else {
// otherwise, destroy the snow layer block, and set the destroyed block on top
// of the lower block
level.setBlockAndUpdate(belowPos.above(), state.setValue(BlockStateProperties.LAYERS, layers - 4));
return parent.defaultBlockState();
}
}
}

} else {
// If we do not have a snowloggable block, place the snow above the lower block if the snow can survive on it
if (state.canSurvive(level, belowPos.above())) {
level.setBlockAndUpdate(belowPos.above(), state);
}
return parent.defaultBlockState();
}
}
return null;
}
}
31 changes: 25 additions & 6 deletions src/main/java/dev/schmarrn/schnowy/common/SchnowyEngine.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.schmarrn.schnowy.common;

import dev.schmarrn.schnowy.common.blocks.SchnowyBlockInterface;
import dev.schmarrn.schnowy.common.blocks.SchnowyProperties;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -36,13 +37,14 @@ public static Optional<SnowPlacementInfo> getNewSnow(ServerLevel level, BlockPos
// stacking snow
if (state.hasProperty(SnowLayerBlock.LAYERS)) {
// Normal Snow Layers, Snowed Flowers, Snowed Grass
// If we got Layers, increment them - if full, make it a snow block or powder snow if high enough
// If we got Layers, increment them - if at max height, do nothing
int newLayerCount = state.getValue(SnowLayerBlock.LAYERS) + 1;
if (state.is(Blocks.SNOW) && newLayerCount >= 8) {
if (isSnowAtMaxHeight(level, pos) || level.getBlockState(pos.below()).is(BlockTags.LEAVES)) {
return Optional.of(new SnowPlacementInfo(Blocks.POWDER_SNOW.defaultBlockState(), pos));
return Optional.empty();
// if we want powder snow at top again
//return Optional.of(new SnowPlacementInfo(Blocks.POWDER_SNOW.defaultBlockState(), pos));
}
return Optional.of(new SnowPlacementInfo(Blocks.SNOW_BLOCK.defaultBlockState(), pos));
}
if (newLayerCount <= 8) {
return Optional.of(new SnowPlacementInfo(state.setValue(SnowLayerBlock.LAYERS, newLayerCount), pos));
Expand All @@ -58,13 +60,30 @@ public static Optional<SnowPlacementInfo> getNewSnow(ServerLevel level, BlockPos
// Get the snowed equivalent of the block
BlockState newState = ReplaceableBlocks.withSnow(state);
if (newState != null) {
return Optional.of(new SnowPlacementInfo(newState, pos));
if (newState.getBlock() instanceof SchnowyBlockInterface sbi) {
if (sbi.canLog(level, pos)) {
return Optional.of(new SnowPlacementInfo(newState, pos));
} else {
return Optional.empty();
}
}
}
}

// if we can accumulate snow (this block isn't powder snow), then put a snow layer on top of it
boolean canAccumulate = !level.getBlockState(pos).is(Blocks.POWDER_SNOW);
if (canAccumulate && Blocks.SNOW.canSurvive(Blocks.SNOW.defaultBlockState(), level, pos.above())) {
if (canAccumulate && Blocks.SNOW.defaultBlockState().canSurvive(level, pos.above())) {
// Check if above block has a snowed variant (should fix fence problem
BlockState newState = ReplaceableBlocks.withSnow(level.getBlockState(pos.above()));
if (newState != null) {
if (newState.getBlock() instanceof SchnowyBlockInterface sbi) {
if (sbi.canLog(level, pos.above())) {
return Optional.of(new SnowPlacementInfo(newState, pos.above()));
} else {
return Optional.empty();
}
}
}
return Optional.of(new SnowPlacementInfo(Blocks.SNOW.defaultBlockState(), pos.above()));
}

Expand Down Expand Up @@ -142,7 +161,7 @@ private static int heightBelowToBlocks(int height) {
return Math.floorDiv(-height -1, 8) + 1;
}

private static boolean isSnow(BlockState state) {
public static boolean isSnow(BlockState state) {
return state.is(Blocks.SNOW_BLOCK)
|| state.hasProperty(SnowLayerBlock.LAYERS)
|| state.hasProperty(SchnowyProperties.HALF_LAYERS)
Expand Down
Loading