Fixed cloud blocks not converting into their soaked forms

This commit is contained in:
Sollace 2023-11-02 17:24:18 +00:00
parent 16a282078e
commit ccec0eec81
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
8 changed files with 183 additions and 104 deletions

View file

@ -11,10 +11,12 @@ import com.minelittlepony.unicopia.block.cloud.CloudStairsBlock;
import com.minelittlepony.unicopia.block.cloud.CompactedCloudBlock; import com.minelittlepony.unicopia.block.cloud.CompactedCloudBlock;
import com.minelittlepony.unicopia.block.cloud.NaturalCloudBlock; import com.minelittlepony.unicopia.block.cloud.NaturalCloudBlock;
import com.minelittlepony.unicopia.block.cloud.OrientedCloudBlock; import com.minelittlepony.unicopia.block.cloud.OrientedCloudBlock;
import com.minelittlepony.unicopia.block.cloud.PoreousCloudStairsBlock;
import com.minelittlepony.unicopia.block.cloud.CloudBedBlock; import com.minelittlepony.unicopia.block.cloud.CloudBedBlock;
import com.minelittlepony.unicopia.block.cloud.CloudBlock; import com.minelittlepony.unicopia.block.cloud.CloudBlock;
import com.minelittlepony.unicopia.block.cloud.SoggyCloudBlock; import com.minelittlepony.unicopia.block.cloud.SoggyCloudBlock;
import com.minelittlepony.unicopia.block.cloud.SoggyCloudSlabBlock; import com.minelittlepony.unicopia.block.cloud.SoggyCloudSlabBlock;
import com.minelittlepony.unicopia.block.cloud.SoggyCloudStairsBlock;
import com.minelittlepony.unicopia.block.cloud.UnstableCloudBlock; import com.minelittlepony.unicopia.block.cloud.UnstableCloudBlock;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.item.cloud.CloudBlockItem; import com.minelittlepony.unicopia.item.cloud.CloudBlockItem;
@ -147,29 +149,29 @@ public interface UBlocks {
() -> UBlocks.COMPACTED_CLOUD), ItemGroups.NATURAL); () -> UBlocks.COMPACTED_CLOUD), ItemGroups.NATURAL);
Block COMPACTED_CLOUD = register("compacted_cloud", new CompactedCloudBlock(Settings.copy(CLOUD))); Block COMPACTED_CLOUD = register("compacted_cloud", new CompactedCloudBlock(Settings.copy(CLOUD)));
Block CLOUD_SLAB = register("cloud_slab", new CloudSlabBlock(Settings.copy(CLOUD), true, () -> UBlocks.SOGGY_CLOUD_SLAB), ItemGroups.NATURAL); Block CLOUD_SLAB = register("cloud_slab", new CloudSlabBlock(Settings.copy(CLOUD), true, () -> UBlocks.SOGGY_CLOUD_SLAB), ItemGroups.NATURAL);
Block CLOUD_STAIRS = register("cloud_stairs", new CloudStairsBlock(CLOUD.getDefaultState(), Settings.copy(CLOUD), () -> UBlocks.SOGGY_CLOUD_STAIRS), ItemGroups.NATURAL); PoreousCloudStairsBlock CLOUD_STAIRS = register("cloud_stairs", new PoreousCloudStairsBlock(CLOUD.getDefaultState(), Settings.copy(CLOUD), () -> UBlocks.SOGGY_CLOUD_STAIRS), ItemGroups.NATURAL);
Block CLOUD_PLANKS = register("cloud_planks", new NaturalCloudBlock(Settings.copy(CLOUD).hardness(0.4F).requiresTool(), false, Block CLOUD_PLANKS = register("cloud_planks", new NaturalCloudBlock(Settings.copy(CLOUD).hardness(0.4F).requiresTool(), false,
null, null,
() -> UBlocks.COMPACTED_CLOUD_PLANKS), ItemGroups.BUILDING_BLOCKS); () -> UBlocks.COMPACTED_CLOUD_PLANKS), ItemGroups.BUILDING_BLOCKS);
Block COMPACTED_CLOUD_PLANKS = register("compacted_cloud_planks", new CompactedCloudBlock(Settings.copy(CLOUD_PLANKS))); Block COMPACTED_CLOUD_PLANKS = register("compacted_cloud_planks", new CompactedCloudBlock(Settings.copy(CLOUD_PLANKS)));
Block CLOUD_PLANK_SLAB = register("cloud_plank_slab", new CloudSlabBlock(Settings.copy(CLOUD_PLANKS), false, null), ItemGroups.BUILDING_BLOCKS); Block CLOUD_PLANK_SLAB = register("cloud_plank_slab", new CloudSlabBlock(Settings.copy(CLOUD_PLANKS), false, null), ItemGroups.BUILDING_BLOCKS);
Block CLOUD_PLANK_STAIRS = register("cloud_plank_stairs", new CloudStairsBlock(CLOUD_PLANKS.getDefaultState(), Settings.copy(CLOUD_PLANKS), null), ItemGroups.BUILDING_BLOCKS); Block CLOUD_PLANK_STAIRS = register("cloud_plank_stairs", new CloudStairsBlock(CLOUD_PLANKS.getDefaultState(), Settings.copy(CLOUD_PLANKS)), ItemGroups.BUILDING_BLOCKS);
Block CLOUD_BRICKS = register("cloud_bricks", new NaturalCloudBlock(Settings.copy(CLOUD).hardness(0.6F).requiresTool(), false, Block CLOUD_BRICKS = register("cloud_bricks", new NaturalCloudBlock(Settings.copy(CLOUD).hardness(0.6F).requiresTool(), false,
null, null,
() -> UBlocks.COMPACTED_CLOUD_BRICKS), ItemGroups.BUILDING_BLOCKS); () -> UBlocks.COMPACTED_CLOUD_BRICKS), ItemGroups.BUILDING_BLOCKS);
Block COMPACTED_CLOUD_BRICKS = register("compacted_cloud_bricks", new CompactedCloudBlock(Settings.copy(CLOUD_BRICKS))); Block COMPACTED_CLOUD_BRICKS = register("compacted_cloud_bricks", new CompactedCloudBlock(Settings.copy(CLOUD_BRICKS)));
Block CLOUD_BRICK_SLAB = register("cloud_brick_slab", new CloudSlabBlock(Settings.copy(CLOUD_BRICKS), false, null), ItemGroups.BUILDING_BLOCKS); Block CLOUD_BRICK_SLAB = register("cloud_brick_slab", new CloudSlabBlock(Settings.copy(CLOUD_BRICKS), false, null), ItemGroups.BUILDING_BLOCKS);
Block CLOUD_BRICK_STAIRS = register("cloud_brick_stairs", new CloudStairsBlock(CLOUD_BRICKS.getDefaultState(), Settings.copy(CLOUD_PLANKS), null), ItemGroups.BUILDING_BLOCKS); Block CLOUD_BRICK_STAIRS = register("cloud_brick_stairs", new CloudStairsBlock(CLOUD_BRICKS.getDefaultState(), Settings.copy(CLOUD_PLANKS)), ItemGroups.BUILDING_BLOCKS);
SoggyCloudBlock SOGGY_CLOUD = register("soggy_cloud", new SoggyCloudBlock(Settings.copy(CLOUD).hardness(0.7F), () -> UBlocks.CLOUD)); SoggyCloudBlock SOGGY_CLOUD = register("soggy_cloud", new SoggyCloudBlock(Settings.copy(CLOUD).hardness(0.7F), () -> UBlocks.CLOUD));
SoggyCloudSlabBlock SOGGY_CLOUD_SLAB = register("soggy_cloud_slab", new SoggyCloudSlabBlock(Settings.copy(SOGGY_CLOUD), () -> UBlocks.CLOUD_SLAB)); SoggyCloudSlabBlock SOGGY_CLOUD_SLAB = register("soggy_cloud_slab", new SoggyCloudSlabBlock(Settings.copy(SOGGY_CLOUD), () -> UBlocks.CLOUD_SLAB));
CloudStairsBlock SOGGY_CLOUD_STAIRS = register("soggy_cloud_stairs", new CloudStairsBlock(SOGGY_CLOUD.getDefaultState(), Settings.copy(CLOUD), null)); SoggyCloudStairsBlock SOGGY_CLOUD_STAIRS = register("soggy_cloud_stairs", new SoggyCloudStairsBlock(SOGGY_CLOUD.getDefaultState(), Settings.copy(CLOUD), () -> UBlocks.CLOUD_STAIRS));
Block DENSE_CLOUD = register("dense_cloud", new CloudBlock(Settings.create().mapColor(MapColor.GRAY).hardness(0.5F).resistance(0).sounds(BlockSoundGroup.WOOL), false), ItemGroups.NATURAL); Block DENSE_CLOUD = register("dense_cloud", new CloudBlock(Settings.create().mapColor(MapColor.GRAY).hardness(0.5F).resistance(0).sounds(BlockSoundGroup.WOOL), false), ItemGroups.NATURAL);
Block DENSE_CLOUD_SLAB = register("dense_cloud_slab", new CloudSlabBlock(Settings.copy(DENSE_CLOUD), false, null), ItemGroups.NATURAL); Block DENSE_CLOUD_SLAB = register("dense_cloud_slab", new CloudSlabBlock(Settings.copy(DENSE_CLOUD), false, null), ItemGroups.NATURAL);
Block DENSE_CLOUD_STAIRS = register("dense_cloud_stairs", new CloudStairsBlock(DENSE_CLOUD.getDefaultState(), Settings.copy(DENSE_CLOUD), null), ItemGroups.NATURAL); Block DENSE_CLOUD_STAIRS = register("dense_cloud_stairs", new CloudStairsBlock(DENSE_CLOUD.getDefaultState(), Settings.copy(DENSE_CLOUD)), ItemGroups.NATURAL);
Block CARVED_CLOUD = register("carved_cloud", new OrientedCloudBlock(Settings.copy(CLOUD).hardness(0.4F).requiresTool(), false), ItemGroups.BUILDING_BLOCKS); Block CARVED_CLOUD = register("carved_cloud", new OrientedCloudBlock(Settings.copy(CLOUD).hardness(0.4F).requiresTool(), false), ItemGroups.BUILDING_BLOCKS);
Block UNSTABLE_CLOUD = register("unstable_cloud", new UnstableCloudBlock(Settings.copy(CLOUD)), ItemGroups.NATURAL); Block UNSTABLE_CLOUD = register("unstable_cloud", new UnstableCloudBlock(Settings.copy(CLOUD)), ItemGroups.NATURAL);

View file

@ -1,7 +1,5 @@
package com.minelittlepony.unicopia.block.cloud; package com.minelittlepony.unicopia.block.cloud;
import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.EquineContext; import com.minelittlepony.unicopia.EquineContext;
@ -18,15 +16,13 @@ import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CloudStairsBlock extends StairsBlock implements Soakable { public class CloudStairsBlock extends StairsBlock {
private final CloudBlock baseBlock; private final CloudBlock baseBlock;
private final @Nullable Supplier<Soakable> soggyBlock;
public CloudStairsBlock(BlockState baseState, Settings settings, @Nullable Supplier<Soakable> soggyBlock) { public CloudStairsBlock(BlockState baseState, Settings settings) {
super(baseState, settings); super(baseState, settings);
this.baseBlock = (CloudBlock)baseState.getBlock(); this.baseBlock = (CloudBlock)baseState.getBlock();
this.soggyBlock = soggyBlock;
} }
@Override @Override
@ -92,15 +88,4 @@ public class CloudStairsBlock extends StairsBlock implements Soakable {
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return true; return true;
} }
@Nullable
@Override
public BlockState getSoggyState(int moisture) {
return soggyBlock == null ? (baseBlock instanceof Soakable s ? s.getSoggyState(moisture) : null) : soggyBlock.get().getSoggyState(moisture);
}
@Override
public int getMoisture(BlockState state) {
return baseBlock instanceof Soakable s ? s.getMoisture(state) : 0;
}
} }

View file

@ -20,21 +20,23 @@ public class PoreousCloudBlock extends CloudBlock implements Soakable {
@Nullable @Nullable
@Override @Override
public BlockState getSoggyState(int moisture) { public BlockState getStateWithMoisture(BlockState state, int moisture) {
return soggyBlock == null ? null : soggyBlock.get().getSoggyState(moisture); if (moisture <= 0) {
return Soakable.copyProperties(state, getDefaultState());
} }
return soggyBlock == null ? null : soggyBlock.get().getStateWithMoisture(state, moisture);
@Override
public int getMoisture(BlockState state) {
return 0;
} }
@Override @Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (soggyBlock != null && world.hasRain(pos) && world.isAir(pos.up())) { if (state.getBlock() instanceof Soakable soakable && world.hasRain(pos) && world.isAir(pos.up())) {
world.setBlockState(pos, Soakable.copyProperties(state, soggyBlock.get().getSoggyState(random.nextBetween(1, 5)))); @Nullable
BlockState soggyState = soakable.getStateWithMoisture(state, random.nextBetween(1, 5));
if (soggyState != null) {
world.setBlockState(pos, soggyState);
return; return;
} }
}
super.randomTick(state, world, pos, random); super.randomTick(state, world, pos, random);
} }

View file

@ -0,0 +1,26 @@
package com.minelittlepony.unicopia.block.cloud;
import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.BlockState;
public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakable {
protected final Supplier<Soakable> soggyBlock;
public PoreousCloudStairsBlock(BlockState baseState, Settings settings, Supplier<Soakable> soggyBlock) {
super(baseState, settings);
this.soggyBlock = soggyBlock;
}
@Nullable
@Override
public BlockState getStateWithMoisture(BlockState state, int moisture) {
if (moisture <= 0) {
return Soakable.copyProperties(state, getDefaultState());
}
return soggyBlock.get().getStateWithMoisture(state, moisture);
}
}

View file

@ -6,7 +6,6 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -31,9 +30,12 @@ public interface Soakable {
IntProperty MOISTURE = IntProperty.of("moisture", 1, 7); IntProperty MOISTURE = IntProperty.of("moisture", 1, 7);
Direction[] DIRECTIONS = Arrays.stream(Direction.values()).filter(d -> d != Direction.UP).toArray(Direction[]::new); Direction[] DIRECTIONS = Arrays.stream(Direction.values()).filter(d -> d != Direction.UP).toArray(Direction[]::new);
BlockState getSoggyState(int moisture); @Nullable
BlockState getStateWithMoisture(BlockState state, int moisture);
int getMoisture(BlockState state); default int getMoisture(BlockState state) {
return state.getOrEmpty(MOISTURE).orElse(0);
}
static void addMoistureParticles(BlockState state, World world, BlockPos pos, Random random) { static void addMoistureParticles(BlockState state, World world, BlockPos pos, Random random) {
if (random.nextInt(5) == 0) { if (random.nextInt(5) == 0) {
@ -46,7 +48,8 @@ public interface Soakable {
} }
} }
static ActionResult tryCollectMoisture(Block dryBlock, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { static ActionResult tryCollectMoisture(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (state.getBlock() instanceof Soakable soakable) {
ItemStack stack = player.getStackInHand(hand); ItemStack stack = player.getStackInHand(hand);
if (stack.getItem() == Items.GLASS_BOTTLE) { if (stack.getItem() == Items.GLASS_BOTTLE) {
if (!player.isCreative()) { if (!player.isCreative()) {
@ -59,57 +62,58 @@ public interface Soakable {
} }
world.playSound(player, player.getX(), player.getY(), player.getZ(), USounds.Vanilla.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1, 1); world.playSound(player, player.getX(), player.getY(), player.getZ(), USounds.Vanilla.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1, 1);
world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos); world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos);
updateMoisture(dryBlock, state, world, pos, state.get(MOISTURE) - 1); updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) - 1);
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }
}
return ActionResult.PASS; return ActionResult.PASS;
} }
static void tickMoisture(Block dryBlock, BlockState state, ServerWorld world, BlockPos pos, Random random) { static void tickMoisture(BlockState state, ServerWorld world, BlockPos pos, Random random) {
int moisture = state.get(MOISTURE); if (state.getBlock() instanceof Soakable soakable) {
int moisture = soakable.getMoisture(state);
if (world.hasRain(pos) && world.isAir(pos.up())) { if (world.hasRain(pos) && world.isAir(pos.up())) {
if (moisture < 7) { if (moisture < 7) {
world.setBlockState(pos, state.with(MOISTURE, moisture + 1)); world.setBlockState(pos, soakable.getStateWithMoisture(state, moisture + 1));
} }
} else { } else {
if (moisture > 1) { if (moisture > 1) {
BlockPos neighborPos = pos.offset(Util.getRandom(Soakable.DIRECTIONS, random)); BlockPos neighborPos = pos.offset(Util.getRandom(Soakable.DIRECTIONS, random));
BlockState neighborState = world.getBlockState(neighborPos); BlockState neighborState = world.getBlockState(neighborPos);
if (neighborState.getBlock() instanceof Soakable soakable && soakable.getMoisture(neighborState) < moisture) { if (neighborState.getBlock() instanceof Soakable neighborSoakable && neighborSoakable.getMoisture(neighborState) < moisture) {
int half = Math.max(1, moisture / 2); int half = Math.max(1, moisture / 2);
@Nullable @Nullable
BlockState newNeighborState = soakable.getSoggyState(half); BlockState newNeighborState = neighborSoakable.getStateWithMoisture(neighborState, half);
if (newNeighborState != null) { if (newNeighborState != null) {
updateMoisture(dryBlock, state, world, pos, moisture - half); updateMoisture(soakable, state, world, pos, moisture - half);
world.setBlockState(neighborPos, soakable.getSoggyState(half)); world.setBlockState(neighborPos, soakable.getStateWithMoisture(state, half));
world.emitGameEvent(null, GameEvent.BLOCK_CHANGE, neighborPos); world.emitGameEvent(null, GameEvent.BLOCK_CHANGE, neighborPos);
return; return;
} }
} }
} }
updateMoisture(dryBlock, state, world, pos, moisture - 1); updateMoisture(soakable, state, world, pos, moisture - 1);
}
} }
} }
private static void updateMoisture(Block dryBlock, BlockState state, World world, BlockPos pos, int newMoisture) { private static void updateMoisture(Soakable soakable, BlockState state, World world, BlockPos pos, int newMoisture) {
if (newMoisture <= 0) { world.setBlockState(pos, soakable.getStateWithMoisture(state, newMoisture));
world.setBlockState(pos, copyProperties(state, dryBlock.getDefaultState()));
} else {
world.setBlockState(pos, state.with(MOISTURE, newMoisture));
}
world.playSound(null, pos, SoundEvents.ENTITY_SALMON_FLOP, SoundCategory.BLOCKS, 1, (float)world.random.nextTriangular(0.5, 0.3F)); world.playSound(null, pos, SoundEvents.ENTITY_SALMON_FLOP, SoundCategory.BLOCKS, 1, (float)world.random.nextTriangular(0.5, 0.3F));
} }
@Nullable
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
static BlockState copyProperties(BlockState from, BlockState to) { static BlockState copyProperties(BlockState from, @Nullable BlockState to) {
if (to != null) {
for (Property property : from.getProperties()) { for (Property property : from.getProperties()) {
to = to.withIfExists(property, from.get(property)); to = to.withIfExists(property, from.get(property));
} }
}
return to; return to;
} }
} }

View file

@ -2,9 +2,12 @@ package com.minelittlepony.unicopia.block.cloud;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -12,6 +15,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class SoggyCloudBlock extends CloudBlock implements Soakable { public class SoggyCloudBlock extends CloudBlock implements Soakable {
@ -24,25 +28,30 @@ public class SoggyCloudBlock extends CloudBlock implements Soakable {
this.dryBlock = dryBlock; this.dryBlock = dryBlock;
} }
@Override
public BlockState getSoggyState(int moisture) {
return getDefaultState().with(MOISTURE, moisture);
}
@Override
public int getMoisture(BlockState state) {
return state.get(MOISTURE);
}
@Override @Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(MOISTURE); builder.add(MOISTURE);
} }
@Override
public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
return dryBlock.get().getPickStack(world, pos, state);
}
@Nullable
@Override
public BlockState getStateWithMoisture(BlockState state, int moisture) {
if (moisture <= 0) {
return Soakable.copyProperties(state, dryBlock.get().getDefaultState());
}
return Soakable.copyProperties(state, getDefaultState()).with(MOISTURE, moisture);
}
@Override @Override
@Deprecated @Deprecated
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return Soakable.tryCollectMoisture(dryBlock.get(), state, world, pos, player, hand, hit); return Soakable.tryCollectMoisture(state, world, pos, player, hand, hit);
} }
@Override @Override
@ -53,6 +62,6 @@ public class SoggyCloudBlock extends CloudBlock implements Soakable {
@Override @Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
Soakable.tickMoisture(dryBlock.get(), state, world, pos, random); Soakable.tickMoisture(state, world, pos, random);
} }
} }

View file

@ -2,9 +2,12 @@ package com.minelittlepony.unicopia.block.cloud;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -12,6 +15,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class SoggyCloudSlabBlock extends CloudSlabBlock { public class SoggyCloudSlabBlock extends CloudSlabBlock {
@ -24,26 +28,30 @@ public class SoggyCloudSlabBlock extends CloudSlabBlock {
this.dryBlock = dryBlock; this.dryBlock = dryBlock;
} }
@Override
public BlockState getSoggyState(int moisture) {
return getDefaultState().with(MOISTURE, moisture);
}
@Override
public int getMoisture(BlockState state) {
return state.get(MOISTURE);
}
@Override @Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder); super.appendProperties(builder);
builder.add(MOISTURE); builder.add(MOISTURE);
} }
@Override
public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
return dryBlock.get().getPickStack(world, pos, state);
}
@Nullable
@Override
public BlockState getStateWithMoisture(BlockState state, int moisture) {
if (moisture <= 0) {
return Soakable.copyProperties(state, dryBlock.get().getDefaultState());
}
return Soakable.copyProperties(state, getDefaultState()).with(MOISTURE, moisture);
}
@Override @Override
@Deprecated @Deprecated
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return Soakable.tryCollectMoisture(dryBlock.get(), state, world, pos, player, hand, hit); return Soakable.tryCollectMoisture(state, world, pos, player, hand, hit);
} }
@Override @Override
@ -54,6 +62,6 @@ public class SoggyCloudSlabBlock extends CloudSlabBlock {
@Override @Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
Soakable.tickMoisture(dryBlock.get(), state, world, pos, random); Soakable.tickMoisture(state, world, pos, random);
} }
} }

View file

@ -0,0 +1,43 @@
package com.minelittlepony.unicopia.block.cloud;
import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
public class SoggyCloudStairsBlock extends CloudStairsBlock implements Soakable {
private final Supplier<Block> dryBlock;
public SoggyCloudStairsBlock(BlockState baseState, Settings settings, Supplier<Block> dryBlock) {
super(baseState, settings);
setDefaultState(getDefaultState().with(MOISTURE, 7));
this.dryBlock = dryBlock;
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(MOISTURE);
}
@Override
public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
return dryBlock.get().getPickStack(world, pos, state);
}
@Nullable
@Override
public BlockState getStateWithMoisture(BlockState state, int moisture) {
if (moisture <= 0) {
return Soakable.copyProperties(state, dryBlock.get().getDefaultState());
}
return Soakable.copyProperties(state, getDefaultState()).with(MOISTURE, moisture);
}
}