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

Feature/1.20.x/ropes #1952

Merged
merged 14 commits into from
Dec 19, 2023
Prev Previous commit
Next Next commit
Implemented rope drops
  • Loading branch information
jodlodi committed Dec 5, 2023
commit 5d218e3f476e66d15591bdc024f2459a11ec8a3a
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.2 2023-12-04T00:56:16.4426133 Loot Tables
// 1.20.2 2023-12-05T02:19:29.6111151 Loot Tables
afe7197a19b997d2f5c5980d9805b6093191b44f data/twilightforest/loot_tables/blocks/acacia_banister.json
d29388fb46e8211e8d3624b744d195b3a6f4c6ff data/twilightforest/loot_tables/blocks/alpha_yeti_trophy.json
3f04f0369241cf99202c72b4d56bc5368396e367 data/twilightforest/loot_tables/blocks/alpha_yeti_wall_trophy.json
Expand Down Expand Up @@ -285,7 +285,7 @@ d4cf2ba1c9d5ad6b35a2ef1b173496f27a7c789f data/twilightforest/loot_tables/blocks/
6575da0cee084bff5caab6b006d0b86fe22001b1 data/twilightforest/loot_tables/blocks/red_thread.json
7a1a62c933a562e1ad0abff252fb72d3a8c5dc33 data/twilightforest/loot_tables/blocks/root.json
7af2b7ae2db4231a3998eee4866773da816842b8 data/twilightforest/loot_tables/blocks/root_strand.json
b6f0cb1c7c1126cea4b747457b368de581e99ff7 data/twilightforest/loot_tables/blocks/rope.json
fb7868a21fc15bb2227693e0604831ce049a0772 data/twilightforest/loot_tables/blocks/rope.json
ef904a158987dbd9963909ef8fb80667071025b7 data/twilightforest/loot_tables/blocks/skeleton_skull_candle.json
ae6d7a73102bfb46c3fe678debd0a35187e9125f data/twilightforest/loot_tables/blocks/skeleton_wall_skull_candle.json
b7336d3399cc73483a2b33de9185b17f64d19c1d data/twilightforest/loot_tables/blocks/smoker.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,61 @@
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"add": true,
"conditions": [
{
"block": "twilightforest:rope",
"condition": "minecraft:block_state_property",
"properties": {
"x": "true"
}
}
],
"count": 1.0,
"function": "minecraft:set_count"
},
{
"add": true,
"conditions": [
{
"block": "twilightforest:rope",
"condition": "minecraft:block_state_property",
"properties": {
"y": "true"
}
}
],
"count": 1.0,
"function": "minecraft:set_count"
},
{
"add": true,
"conditions": [
{
"block": "twilightforest:rope",
"condition": "minecraft:block_state_property",
"properties": {
"z": "true"
}
}
],
"count": 1.0,
"function": "minecraft:set_count"
},
{
"add": true,
"count": -1.0,
"function": "minecraft:set_count"
},
{
"function": "minecraft:explosion_decay"
}
],
"name": "twilightforest:rope"
}
],
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/twilightforest/block/RopeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.SupportType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
Expand All @@ -23,7 +26,7 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

//TODO: Break when shot, knots when intersect, actual item texture, world generation, multiple drops depending on blockstate
//TODO: Break when shot, knots when intersect, actual item texture, world generation
public class RopeBlock extends Block implements SimpleWaterloggedBlock {
private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty X = BooleanProperty.create("x");
Expand Down Expand Up @@ -121,24 +124,32 @@ public BlockState updateShape(BlockState state, Direction direction, BlockState
@SuppressWarnings("deprecation")
public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
boolean flag = true;
int drops = 0;
BlockState newState = state;
if (state.getValue(X)) {
if (!this.checkConnection(level, pos, Direction.WEST) && !this.checkConnection(level, pos, Direction.EAST)) newState = newState.setValue(X, false);
else flag = false;
if (!this.checkConnection(level, pos, Direction.WEST) && !this.checkConnection(level, pos, Direction.EAST)) {
newState = newState.setValue(X, false);
drops++;
} else flag = false;
}
if (state.getValue(Y)) {
if (!this.checkConnection(level, pos, Direction.UP)) newState = newState.setValue(Y, false);
else flag = false;
if (!this.checkConnection(level, pos, Direction.UP)) {
newState = newState.setValue(Y, false);
drops++;
} else flag = false;
}
if (state.getValue(Z)) {
if (!this.checkConnection(level, pos, Direction.NORTH) && !this.checkConnection(level, pos, Direction.SOUTH)) newState = newState.setValue(Z, false);
else flag = false;
if (!this.checkConnection(level, pos, Direction.NORTH) && !this.checkConnection(level, pos, Direction.SOUTH)) {
newState = newState.setValue(Z, false);
drops++;
} else flag = false;
}

if (flag) {
level.destroyBlock(pos, true);
} else if (!state.equals(newState)) {
} else if (drops > 0) {
level.setBlockAndUpdate(pos, newState);
for (int i = 0; i < drops; i++) dropResources(this.defaultBlockState(), level, pos);
}
}

Expand Down
21 changes: 20 additions & 1 deletion src/main/java/twilightforest/data/BlockLootTables.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected void generate() {
add(TFBlocks.PIGLIN_WALL_SKULL_CANDLE.value(), createSingleItemTable(Blocks.PIGLIN_HEAD));

dropSelf(TFBlocks.IRON_LADDER.value());
dropSelf(TFBlocks.ROPE.value());
add(TFBlocks.ROPE.value(), this.rope());
dropSelf(TFBlocks.TWISTED_STONE.value());
dropSelf(TFBlocks.TWISTED_STONE_PILLAR.value());
dropSelf(TFBlocks.BOLD_STONE_PILLAR.value());
Expand Down Expand Up @@ -584,6 +584,25 @@ protected LootTable.Builder redThread() {
.apply(SetItemCountFunction.setCount(ConstantValue.exactly(-1.0F), true)))));
}

protected LootTable.Builder rope() {
return LootTable.lootTable()
.withPool(LootPool.lootPool()
.add(this.applyExplosionDecay(TFBlocks.ROPE.value(), LootItem.lootTableItem(TFBlocks.ROPE.value())
.apply(SetItemCountFunction.setCount(ConstantValue.exactly(1.0F), true)
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(TFBlocks.ROPE.value())
.setProperties(StatePropertiesPredicate.Builder.properties()
.hasProperty(RopeBlock.X, true))))
.apply(SetItemCountFunction.setCount(ConstantValue.exactly(1.0F), true)
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(TFBlocks.ROPE.value())
.setProperties(StatePropertiesPredicate.Builder.properties()
.hasProperty(RopeBlock.Y, true))))
.apply(SetItemCountFunction.setCount(ConstantValue.exactly(1.0F), true)
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(TFBlocks.ROPE.value())
.setProperties(StatePropertiesPredicate.Builder.properties()
.hasProperty(RopeBlock.Z, true))))
.apply(SetItemCountFunction.setCount(ConstantValue.exactly(-1.0F), true)))));
}

protected LootTable.Builder fallenLeaves() {
return LootTable.lootTable().withPool(LootPool.lootPool()
.add(AlternativesEntry.alternatives(AlternativesEntry.alternatives(FallenLeavesBlock.LAYERS.getPossibleValues(), layer ->
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/twilightforest/init/TFBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class TFBlocks {
public static final DeferredBlock<Block> HUGE_WATER_LILY = BLOCKS.register("huge_water_lily", () -> new HugeWaterLilyBlock(BlockBehaviour.Properties.of().instabreak().mapColor(MapColor.PLANT).noCollission().pushReaction(PushReaction.DESTROY).sound(SoundType.GRASS)));
public static final DeferredBlock<Block> SLIDER = register("slider", () -> new SliderBlock(BlockBehaviour.Properties.of().mapColor(MapColor.DIRT).noLootTable().noOcclusion().randomTicks().strength(2.0F, 10.0F)));
public static final DeferredBlock<Block> IRON_LADDER = register("iron_ladder", () -> new IronLadderBlock(BlockBehaviour.Properties.of().forceSolidOff().noOcclusion().pushReaction(PushReaction.DESTROY).requiresCorrectToolForDrops().sound(SoundType.METAL).strength(5.0F, 6.0F)));
public static final DeferredBlock<Block> ROPE = BLOCKS.register("rope", () -> new RopeBlock(BlockBehaviour.Properties.of().forceSolidOff().noOcclusion().pushReaction(PushReaction.DESTROY).sound(SoundType.WOOL).strength(2.0F, 10.0F)));//FIXME strength
public static final DeferredBlock<Block> ROPE = BLOCKS.register("rope", () -> new RopeBlock(BlockBehaviour.Properties.of().forceSolidOff().noOcclusion().pushReaction(PushReaction.DESTROY).sound(SoundType.WOOL).strength(0.3F, 3.0F)));//FIXME strength

//naga courtyard
public static final DeferredBlock<Block> NAGASTONE_HEAD = register("nagastone_head", () -> new TFHorizontalBlock(BlockBehaviour.Properties.of().instrument(NoteBlockInstrument.BASEDRUM).mapColor(MapColor.STONE).requiresCorrectToolForDrops().sound(SoundType.STONE).strength(1.5F, 6.0F)));
Expand Down