Menger sponge, translation, fixes

This commit is contained in:
paulevsGitch 2020-12-06 13:41:24 +03:00
parent fd0d49391d
commit 1195ca4cd3
10 changed files with 195 additions and 9 deletions

View file

@ -0,0 +1,96 @@
package ru.betterend.blocks;
import java.util.Queue;
import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FluidBlock;
import net.minecraft.block.FluidDrainable;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.tag.FluidTags;
import net.minecraft.util.Pair;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import ru.betterend.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks;
public class BlockMengerSponge extends BlockBase {
public BlockMengerSponge() {
super(FabricBlockSettings.copyOf(Blocks.SPONGE));
}
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
if (absorbWater(world, pos)) {
world.setBlockState(pos, EndBlocks.MENGER_SPONGE_WET.getDefaultState());
}
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (absorbWater(world, pos)) {
return EndBlocks.MENGER_SPONGE_WET.getDefaultState();
}
return state;
}
private boolean absorbWater(WorldAccess world, BlockPos pos) {
Queue<Pair<BlockPos, Integer>> queue = Lists.newLinkedList();
queue.add(new Pair<BlockPos, Integer>(pos, 0));
int i = 0;
while (!queue.isEmpty()) {
Pair<BlockPos, Integer> pair = queue.poll();
BlockPos blockPos = (BlockPos) pair.getLeft();
int j = (Integer) pair.getRight();
Direction[] var8 = Direction.values();
int var9 = var8.length;
for (int var10 = 0; var10 < var9; ++var10) {
Direction direction = var8[var10];
BlockPos blockPos2 = blockPos.offset(direction);
BlockState blockState = world.getBlockState(blockPos2);
FluidState fluidState = world.getFluidState(blockPos2);
Material material = blockState.getMaterial();
if (fluidState.isIn(FluidTags.WATER)) {
if (blockState.getBlock() instanceof FluidDrainable && ((FluidDrainable) blockState.getBlock()).tryDrainFluid(world, blockPos2, blockState) != Fluids.EMPTY) {
++i;
if (j < 6) {
queue.add(new Pair<BlockPos, Integer>(blockPos2, j + 1));
}
}
else if (blockState.getBlock() instanceof FluidBlock) {
world.setBlockState(blockPos2, Blocks.AIR.getDefaultState(), 3);
++i;
if (j < 6) {
queue.add(new Pair<BlockPos, Integer>(blockPos2, j + 1));
}
}
else if (material == Material.UNDERWATER_PLANT || material == Material.REPLACEABLE_UNDERWATER_PLANT) {
BlockEntity blockEntity = blockState.getBlock().hasBlockEntity() ? world.getBlockEntity(blockPos2) : null;
dropStacks(blockState, world, blockPos2, blockEntity);
world.setBlockState(blockPos2, Blocks.AIR.getDefaultState(), 3);
++i;
if (j < 6) {
queue.add(new Pair<BlockPos, Integer>(blockPos2, j + 1));
}
}
}
}
if (i > 64) {
break;
}
}
return i > 0;
}
}

View file

@ -0,0 +1,76 @@
package ru.betterend.blocks;
import java.util.Random;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import ru.betterend.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks;
public class BlockMengerSpongeWet extends BlockBase {
public BlockMengerSpongeWet() {
super(FabricBlockSettings.copyOf(Blocks.WET_SPONGE));
}
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
if (world.getDimension().isUltrawarm()) {
world.setBlockState(pos, EndBlocks.MENGER_SPONGE.getDefaultState(), 3);
world.syncWorldEvent(2009, pos, 0);
world.playSound((PlayerEntity) null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 1.0F, (1.0F + world.getRandom().nextFloat() * 0.2F) * 0.7F);
}
}
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
Direction direction = Direction.random(random);
if (direction != Direction.UP) {
BlockPos blockPos = pos.offset(direction);
BlockState blockState = world.getBlockState(blockPos);
if (!state.isOpaque() || !blockState.isSideSolidFullSquare(world, blockPos, direction.getOpposite())) {
double x = (double) pos.getX();
double y = (double) pos.getY();
double z = (double) pos.getZ();
if (direction == Direction.DOWN) {
y -= 0.05;
x += random.nextDouble();
z += random.nextDouble();
}
else {
y += random.nextDouble() * 0.8;
if (direction.getAxis() == Direction.Axis.X) {
z += random.nextDouble();
if (direction == Direction.EAST) {
++x;
}
else {
x += 0.05;
}
}
else {
x += random.nextDouble();
if (direction == Direction.SOUTH) {
++z;
}
else {
z += 0.05;
}
}
}
world.addParticle(ParticleTypes.DRIPPING_WATER, x, y, z, 0, 0, 0);
}
}
}
}