Skip to content

Commit

Permalink
Reworked Stringy Cobweb generation and added top connected state, pre…
Browse files Browse the repository at this point in the history
…vented players from obtaining Stringy Cobwebs since manual placement is/was broken
  • Loading branch information
Forstride committed Dec 1, 2023
1 parent c44357b commit 9151fac
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.2 2023-11-30T22:19:29.5428274 Registries
// 1.20.2 2023-12-01T05:58:34.6500989 Registries
a09ddf53150a7fcf8767a311dd5cf040fa2e9221 data/biomesoplenty/damage_type/bramble.json
2d0eab2cc85c4c6397fdc41dd0cedefbc4a7a150 data/biomesoplenty/damage_type/fumarole.json
1db19ce8d33b8c131955b60ed830200bbee6a912 data/biomesoplenty/worldgen/biome/aspen_glade.json
Expand Down Expand Up @@ -561,7 +561,7 @@ ee7f4df006fd534f998daf475482bb1acca0cd3f data/biomesoplenty/worldgen/placed_feat
212bb036d2b8b398ce520a3670f6124efa9bd229 data/biomesoplenty/worldgen/placed_feature/spruce_bush.json
e0d549bf2e58a98f405659b64f9831d25f979f88 data/biomesoplenty/worldgen/placed_feature/spruce_poplar_tree.json
849711fce232370528ad51f0f4111fc8657dfd18 data/biomesoplenty/worldgen/placed_feature/spruce_twiglet_tree.json
d08ca8d1b844d090e87861b280fd62ad9bd2c867 data/biomesoplenty/worldgen/placed_feature/stringy_cobweb.json
fefb2c64348097e2ec8da7f62dbcad1ad2e047d2 data/biomesoplenty/worldgen/placed_feature/stringy_cobweb.json
eed31e45b9d0416bc9f3360d84481a98ba55f877 data/biomesoplenty/worldgen/placed_feature/sunflower.json
b49b4fe6426269383157659659eb8cbd7fd1c7d9 data/biomesoplenty/worldgen/placed_feature/tall_dead_twiglet_tree.json
2d8a13b82e2207df536eb2107efd5938169b6522 data/biomesoplenty/worldgen/placed_feature/tall_spruce_tree.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"placement": [
{
"type": "minecraft:count",
"count": 150
"count": 250
},
{
"type": "minecraft:in_square"
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/biomesoplenty/common/block/StringyCobwebBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package biomesoplenty.common.block;

import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.common.block.state.properties.ConnectedProperty;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Entity;
Expand All @@ -16,8 +17,8 @@
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

Expand All @@ -26,14 +27,14 @@
public class StringyCobwebBlock extends Block
{
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty CONNECTED = BooleanProperty.create("connected");
public static final EnumProperty<ConnectedProperty> CONNECTED = EnumProperty.create("connected", ConnectedProperty.class);
protected static final VoxelShape SHAPE_X = Block.box(0.0D, 0.0D, 7.0D, 16.0D, 16.0D, 9.0D);
protected static final VoxelShape SHAPE_Z = Block.box(7.0D, 0.0D, 0.0D, 9.0D, 16.0D, 16.0D);

public StringyCobwebBlock(Properties properties)
{
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(CONNECTED, false));
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(CONNECTED, ConnectedProperty.MIDDLE));
}

@Override
Expand Down Expand Up @@ -76,15 +77,17 @@ public BlockState updateShape(BlockState stateIn, Direction facing, BlockState f
public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos)
{
Direction direction = state.getValue(FACING);
BlockPos abovePos = pos.relative(direction).above();
BlockPos abovePos = pos.above();
BlockPos nextStringPos = pos.relative(direction).above();
BlockPos prevStringPos = pos.relative(direction.getOpposite()).below();
BlockPos belowPos = pos.below();

BlockState aboveState = level.getBlockState(abovePos);
BlockState nextStringState = level.getBlockState(nextStringPos);
BlockState prevStringState = level.getBlockState(prevStringPos);
BlockState belowState = level.getBlockState(belowPos);

BlockPos belowDirPos = pos.relative(direction.getOpposite()).below();
BlockState belowDirState = level.getBlockState(belowDirPos);

if ((aboveState.isFaceSturdy(level, abovePos, Direction.DOWN) || aboveState.getBlock() == BOPBlocks.STRINGY_COBWEB.get()) && (belowState.isFaceSturdy(level, belowPos, Direction.UP) || belowDirState.getBlock() == BOPBlocks.STRINGY_COBWEB.get()))
if ((aboveState.isFaceSturdy(level, abovePos, Direction.DOWN) || nextStringState.getBlock() == BOPBlocks.STRINGY_COBWEB.get()) && (belowState.isFaceSturdy(level, belowPos, Direction.UP) || prevStringState.getBlock() == BOPBlocks.STRINGY_COBWEB.get()))
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package biomesoplenty.common.block.state.properties;

import net.minecraft.util.StringRepresentable;

public enum ConnectedProperty implements StringRepresentable {
MIDDLE("middle"),
BOTTOM("bottom"),
TOP("top");

private final String name;

ConnectedProperty(String p_61743_) {
this.name = p_61743_;
}

public String getName() {
return this.name;
}

public String toString() {
return this.name;
}

public String getSerializedName() {
return this.name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.common.block.StringyCobwebBlock;
import biomesoplenty.common.block.state.properties.ConnectedProperty;
import com.mojang.serialization.Codec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.SectionPos;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature;
Expand All @@ -19,55 +23,109 @@
public class StringyCobwebFeature extends Feature<NoneFeatureConfiguration>
{
private static final int MIN_DISTANCE = 2;
private static final int MAX_DISTANCE = 16;
private static final int MAX_DISTANCE = 32;

public StringyCobwebFeature(Codec<NoneFeatureConfiguration> deserializer)
{
super(deserializer);
}

private boolean moveDiagnonally(WorldGenLevel level, BlockPos origin, Direction direction, boolean place)
public boolean canPlace(WorldGenLevel world, BlockPos pos, int length, Direction dir)
{
int distance;
boolean connected = true;
BlockPos belowPos = pos.below();
BlockState belowState = world.getBlockState(belowPos);

for (distance = 0; distance < MAX_DISTANCE; distance++)
if (!world.getBlockState(pos).isAir() || !belowState.isFaceSturdy(world, belowPos, Direction.UP) || !this.respectsCutoff((WorldGenRegion)world, pos))
{
if (distance > 0)
{
connected = false;
}
return false;
}

BlockPos pos = origin.relative(direction, distance).above(distance);
BlockState state = level.getBlockState(pos);
BlockPos nextStringPos = pos;

if (!state.isAir())
{
// Don't allow connecting to non-solid materials
if (!state.isSolid()) return false;
for (int i = 0; i < length; i++)
{
nextStringPos = nextStringPos.relative(dir, 1).above(1);
BlockState nextStringState = world.getBlockState(nextStringPos);

// Discontinue once we hit a block
break;
if (!nextStringState.isAir() || !this.respectsCutoff((WorldGenRegion)world, nextStringPos))
{
return false;
}
}

if (place) this.setBlock(level, pos, BOPBlocks.STRINGY_COBWEB.get().defaultBlockState().setValue(StringyCobwebBlock.FACING, direction).setValue(StringyCobwebBlock.CONNECTED, connected));
BlockPos abovePos = nextStringPos.above();
BlockState aboveState = world.getBlockState(abovePos);

if (!aboveState.isFaceSturdy(world, abovePos, Direction.DOWN) || !this.respectsCutoff((WorldGenRegion)world, nextStringPos))
{
return false;
}

if (distance < MIN_DISTANCE || distance >= MAX_DISTANCE) return false;
return true;
}

public void placeCobweb(WorldGenLevel world, BlockPos pos, int length, Direction dir)
{
if (this.respectsCutoff((WorldGenRegion)world, pos))
{
world.setBlock(pos, BOPBlocks.STRINGY_COBWEB.get().defaultBlockState().setValue(StringyCobwebBlock.FACING, dir).setValue(StringyCobwebBlock.CONNECTED, ConnectedProperty.BOTTOM), 2);
}

BlockPos nextStringPos = pos;

for (int i = 0; i < length; ++i)
{
nextStringPos = nextStringPos.relative(dir, 1).above(1);

if (this.respectsCutoff((WorldGenRegion)world, nextStringPos))
{
world.setBlock(nextStringPos, BOPBlocks.STRINGY_COBWEB.get().defaultBlockState().setValue(StringyCobwebBlock.FACING, dir).setValue(StringyCobwebBlock.CONNECTED, ConnectedProperty.MIDDLE), 2);
}
}

if (this.respectsCutoff((WorldGenRegion)world, nextStringPos))
{
world.setBlock(nextStringPos, BOPBlocks.STRINGY_COBWEB.get().defaultBlockState().setValue(StringyCobwebBlock.FACING, dir).setValue(StringyCobwebBlock.CONNECTED, ConnectedProperty.TOP), 2);
}
}

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context)
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext)
{
WorldGenLevel level = context.level();
RandomSource rand = context.random();
BlockPos origin = context.origin();
Direction dir = Direction.Plane.HORIZONTAL.getRandomDirection(rand);
WorldGenLevel world = featurePlaceContext.level();
RandomSource rand = featurePlaceContext.random();
BlockPos pos = featurePlaceContext.origin();
int k = 0;

if (!this.moveDiagnonally(level, origin, dir, false))
return false;
for(int j = 0; j < 128; ++j)
{
int length = MIN_DISTANCE + rand.nextInt(MAX_DISTANCE - MIN_DISTANCE);
Direction dir = Direction.Plane.HORIZONTAL.getRandomDirection(rand);
BlockPos blockPos = pos.offset(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

if (canPlace(world, blockPos, length, dir))
{
placeCobweb(world, blockPos, length, dir);
++k;
}
}

return k > 0;
}

private boolean respectsCutoff(WorldGenRegion region, BlockPos pos)
{
int i = SectionPos.blockToSectionCoord(pos.getX());
int j = SectionPos.blockToSectionCoord(pos.getZ());
ChunkPos chunkpos = region.getCenter();
int k = Math.abs(chunkpos.x - i);
int l = Math.abs(chunkpos.z - j);

if (k <= region.writeRadiusCutoff && l <= region.writeRadiusCutoff)
{
return true;
}

return this.moveDiagnonally(level, origin, dir, true);
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void bootstrap(BootstapContext<PlacedFeature> context)
register(context, BOPCavePlacements.HANGING_COBWEBS, HANGING_COBWEB, List.of(CountPlacement.of(200), InSquarePlacement.spread(), PlacementUtils.RANGE_BOTTOM_TO_MAX_TERRAIN_HEIGHT, EnvironmentScanPlacement.scanningFor(Direction.UP, BlockPredicate.hasSturdyFace(Direction.DOWN), BlockPredicate.ONLY_IN_AIR_PREDICATE, 12), RandomOffsetPlacement.vertical(ConstantInt.of(-1)), BiomeFilter.biome()));
register(context, BOPCavePlacements.CORNER_COBWEBS, CORNER_COBWEBS, List.of(CountPlacement.of(40), InSquarePlacement.spread(), PlacementUtils.RANGE_BOTTOM_TO_MAX_TERRAIN_HEIGHT, EnvironmentScanPlacement.scanningFor(Direction.DOWN, BlockPredicate.solid(), BlockPredicate.ONLY_IN_AIR_PREDICATE, 24), RandomOffsetPlacement.vertical(ConstantInt.of(1)), BiomeFilter.biome()));
register(context, BOPCavePlacements.SPIDER_EGGS, SPIDER_EGG, List.of(CountPlacement.of(35), InSquarePlacement.spread(), PlacementUtils.RANGE_BOTTOM_TO_MAX_TERRAIN_HEIGHT, EnvironmentScanPlacement.scanningFor(Direction.DOWN, BlockPredicate.solid(), BlockPredicate.ONLY_IN_AIR_PREDICATE, 12), RandomOffsetPlacement.vertical(ConstantInt.of(1)), BiomeFilter.biome()));
register(context, BOPCavePlacements.STRINGY_COBWEB, STRINGY_COBWEB, List.of(CountPlacement.of(150), InSquarePlacement.spread(), PlacementUtils.RANGE_BOTTOM_TO_MAX_TERRAIN_HEIGHT, EnvironmentScanPlacement.scanningFor(Direction.DOWN, BlockPredicate.solid(), BlockPredicate.ONLY_IN_AIR_PREDICATE, 12), RandomOffsetPlacement.vertical(ConstantInt.of(1)), BiomeFilter.biome()));
register(context, BOPCavePlacements.STRINGY_COBWEB, STRINGY_COBWEB, List.of(CountPlacement.of(250), InSquarePlacement.spread(), PlacementUtils.RANGE_BOTTOM_TO_MAX_TERRAIN_HEIGHT, EnvironmentScanPlacement.scanningFor(Direction.DOWN, BlockPredicate.solid(), BlockPredicate.ONLY_IN_AIR_PREDICATE, 12), RandomOffsetPlacement.vertical(ConstantInt.of(1)), BiomeFilter.biome()));
register(context, BOPCavePlacements.WEBBING, WEBBING, List.of(CountPlacement.of(18), InSquarePlacement.spread(), PlacementUtils.RANGE_BOTTOM_TO_MAX_TERRAIN_HEIGHT, BiomeFilter.biome()));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/biomesoplenty/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static void registerBlocks()
SPIDER_EGG = registerBlock(() -> new SpiderEggBlock(BlockBehaviour.Properties.of().strength(0.1F).mapColor(MapColor.WOOL).pushReaction(PushReaction.DESTROY).sound(SoundType.METAL).lightLevel((state) -> 5)), "spider_egg");
HANGING_COBWEB = registerBlock(() -> new HangingCobwebBottomBlock(BlockBehaviour.Properties.of().mapColor(MapColor.WOOL).pushReaction(PushReaction.DESTROY).replaceable().ignitedByLava().noCollission().instabreak().sound(SoundType.WOOL)), "hanging_cobweb");
HANGING_COBWEB_STRAND = registerBlock(() -> new HangingCobwebBlock(BlockBehaviour.Properties.of().mapColor(MapColor.WOOL).pushReaction(PushReaction.DESTROY).replaceable().ignitedByLava().noCollission().instabreak().sound(SoundType.WOOL)), "hanging_cobweb_strand");
STRINGY_COBWEB = registerBlock(() -> new StringyCobwebBlock(BlockBehaviour.Properties.of().mapColor(MapColor.WOOL).pushReaction(PushReaction.DESTROY).replaceable().ignitedByLava().noCollission().instabreak().sound(SoundType.WOOL)), "stringy_cobweb");
STRINGY_COBWEB = registerBlock(() -> new StringyCobwebBlock(BlockBehaviour.Properties.of().noLootTable().mapColor(MapColor.WOOL).pushReaction(PushReaction.DESTROY).replaceable().ignitedByLava().noCollission().instabreak().sound(SoundType.WOOL)), "stringy_cobweb");
WEBBING = registerBlock(() -> new WebbingBlock(BlockBehaviour.Properties.of().mapColor(MapColor.WOOL).pushReaction(PushReaction.DESTROY).replaceable().ignitedByLava().noCollission().instabreak().sound(SoundType.WOOL)), "webbing");

ORIGIN_GRASS_BLOCK = registerBlock(() -> new OriginGrassBlock(BlockBehaviour.Properties.of().randomTicks().mapColor(MapColor.GRASS).strength(0.6F).randomTicks().sound(SoundType.GRASS)), "origin_grass_block");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/biomesoplenty/init/ModCreativeTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ModCreativeTab
private static final List<RegistryObject<Item>> ITEM_BLACKLIST = ImmutableList.of(BOPItems.BOP_ICON);

private static final List<RegistryObject<Block>> BLOCK_BLACKLIST = ImmutableList.of(BOPBlocks.BLOOD, BOPBlocks.HIGH_GRASS_PLANT, BOPBlocks.SPANISH_MOSS_PLANT,
BOPBlocks.GLOWWORM_SILK_STRAND, BOPBlocks.HANGING_COBWEB_STRAND, BOPBlocks.FLESH_TENDONS_STRAND, BOPBlocks.POTTED_ORIGIN_SAPLING,
BOPBlocks.GLOWWORM_SILK_STRAND, BOPBlocks.HANGING_COBWEB_STRAND, BOPBlocks.STRINGY_COBWEB, BOPBlocks.FLESH_TENDONS_STRAND, BOPBlocks.POTTED_ORIGIN_SAPLING,
BOPBlocks.POTTED_FLOWERING_OAK_SAPLING, BOPBlocks.POTTED_SNOWBLOSSOM_SAPLING, BOPBlocks.POTTED_RAINBOW_BIRCH_SAPLING,
BOPBlocks.POTTED_FIR_SAPLING, BOPBlocks.POTTED_PINE_SAPLING, BOPBlocks.POTTED_RED_MAPLE_SAPLING, BOPBlocks.POTTED_ORANGE_MAPLE_SAPLING,
BOPBlocks.POTTED_YELLOW_MAPLE_SAPLING, BOPBlocks.POTTED_REDWOOD_SAPLING, BOPBlocks.POTTED_MAHOGANY_SAPLING, BOPBlocks.POTTED_JACARANDA_SAPLING,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
{
"variants": {
"facing=east,connected=false": [
"facing=east,connected=middle": [
{ "model": "biomesoplenty:block/stringy_cobweb", "y": 90 },
{ "model": "biomesoplenty:block/stringy_cobweb", "y": 90 },
{ "model": "biomesoplenty:block/stringy_cobweb_alt", "y": 90 }
],
"facing=south,connected=false": [
"facing=south,connected=middle": [
{ "model": "biomesoplenty:block/stringy_cobweb", "y": 180 },
{ "model": "biomesoplenty:block/stringy_cobweb", "y": 180 },
{ "model": "biomesoplenty:block/stringy_cobweb_alt", "y": 180 }
],
"facing=west,connected=false": [
"facing=west,connected=middle": [
{ "model": "biomesoplenty:block/stringy_cobweb", "y": 270 },
{ "model": "biomesoplenty:block/stringy_cobweb", "y": 270 },
{ "model": "biomesoplenty:block/stringy_cobweb_alt", "y": 270 }
],
"facing=north,connected=false": [
"facing=north,connected=middle": [
{ "model": "biomesoplenty:block/stringy_cobweb", "y": 0 },
{ "model": "biomesoplenty:block/stringy_cobweb", "y": 0 },
{ "model": "biomesoplenty:block/stringy_cobweb_alt", "y": 0 }
],
"facing=east,connected=true": { "model": "biomesoplenty:block/stringy_cobweb_connected", "y": 90 },
"facing=south,connected=true": { "model": "biomesoplenty:block/stringy_cobweb_connected", "y": 180 },
"facing=west,connected=true": { "model": "biomesoplenty:block/stringy_cobweb_connected", "y": 270 },
"facing=north,connected=true": { "model": "biomesoplenty:block/stringy_cobweb_connected", "y": 0 }
"facing=east,connected=bottom": { "model": "biomesoplenty:block/stringy_cobweb_bottom", "y": 90 },
"facing=south,connected=bottom": { "model": "biomesoplenty:block/stringy_cobweb_bottom", "y": 180 },
"facing=west,connected=bottom": { "model": "biomesoplenty:block/stringy_cobweb_bottom", "y": 270 },
"facing=north,connected=bottom": { "model": "biomesoplenty:block/stringy_cobweb_bottom", "y": 0 },
"facing=east,connected=top": { "model": "biomesoplenty:block/stringy_cobweb_top", "y": 90 },
"facing=south,connected=top": { "model": "biomesoplenty:block/stringy_cobweb_top", "y": 180 },
"facing=west,connected=top": { "model": "biomesoplenty:block/stringy_cobweb_top", "y": 270 },
"facing=north,connected=top": { "model": "biomesoplenty:block/stringy_cobweb_top", "y": 0 }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ambientocclusion": false,
"textures": {
"string": "biomesoplenty:block/stringy_cobweb_connected",
"particle": "biomesoplenty:block/stringy_cobweb_connected"
"string": "biomesoplenty:block/stringy_cobweb_bottom",
"particle": "biomesoplenty:block/stringy_cobweb_bottom"
},
"elements": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"ambientocclusion": false,
"textures": {
"string": "biomesoplenty:block/stringy_cobweb_top",
"particle": "biomesoplenty:block/stringy_cobweb_top"
},
"elements": [
{
"from": [8, 0, 0],
"to": [8, 16, 16],
"rotation": {"angle": -22.5, "axis": "y", "origin": [8, 0, 16]},
"shade": false,
"faces": {
"east": {"uv": [0, 0, 16, 16], "texture": "#string"},
"west": {"uv": [16, 0, 0, 16], "texture": "#string"}
}
},
{
"from": [8, 0, 0],
"to": [8, 16, 16],
"rotation": {"angle": 22.5, "axis": "y", "origin": [8, 0, 16]},
"shade": false,
"faces": {
"east": {"uv": [0, 0, 16, 16], "texture": "#string"},
"west": {"uv": [16, 0, 0, 16], "texture": "#string"}
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9151fac

Please sign in to comment.