Sulphur, brimstone

This commit is contained in:
paulevsGitch 2020-11-29 23:35:59 +03:00
parent bf7e665b36
commit 44371da207
25 changed files with 317 additions and 63 deletions

View file

@ -0,0 +1,70 @@
package ru.betterend.blocks;
import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.MaterialColor;
import net.minecraft.fluid.Fluids;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import ru.betterend.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks;
import ru.betterend.util.BlocksHelper;
public class BlockBrimstone extends BlockBase {
public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVATED;
public BlockBrimstone() {
super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(MaterialColor.BROWN).ticksRandomly());
setDefaultState(stateManager.getDefaultState().with(ACTIVATED, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
stateManager.add(ACTIVATED);
}
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
boolean deactivate = true;
for (Direction dir: BlocksHelper.DIRECTIONS) {
if (world.getFluidState(pos.offset(dir)).getFluid().equals(Fluids.WATER)) {
deactivate = false;
break;
}
}
if (state.get(ACTIVATED)) {
if (deactivate) {
world.setBlockState(pos, getDefaultState().with(ACTIVATED, false));
}
else if (state.get(ACTIVATED)) {
Direction dir = BlocksHelper.randomDirection(random);
BlockPos side = pos.offset(dir);
BlockState sideState = world.getBlockState(side);
if (sideState.getBlock() instanceof BlockSulphurCrystal) {
if (sideState.get(BlockSulphurCrystal.AGE) < 2) {
int age = sideState.get(BlockSulphurCrystal.AGE) + 1;
world.setBlockState(side, sideState.with(BlockSulphurCrystal.AGE, age));
}
}
else if (sideState.isAir() || !sideState.getFluidState().isEmpty()) {
boolean water = sideState.getFluidState().getFluid().equals(Fluids.WATER);
BlockState crystal = EndBlocks.SULPHUR_CRYSTAL.getDefaultState()
.with(BlockSulphurCrystal.FACING, dir)
.with(BlockSulphurCrystal.WATERLOGGED, water)
.with(BlockSulphurCrystal.AGE, 0);
world.setBlockState(side, crystal);
}
}
}
else if (!deactivate && !state.get(ACTIVATED)) {
world.setBlockState(pos, getDefaultState().with(ACTIVATED, true));
}
}
}

View file

@ -0,0 +1,86 @@
package ru.betterend.blocks;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.FluidFillable;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.Waterloggable;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import ru.betterend.blocks.basis.BlockAttached;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
public class BlockSulphurCrystal extends BlockAttached implements IRenderTypeable, Waterloggable, FluidFillable {
public static final IntProperty AGE = IntProperty.of("age", 0, 2);
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public BlockSulphurCrystal() {
super(FabricBlockSettings.of(Material.STONE)
.materialColor(MaterialColor.YELLOW)
.breakByTool(FabricToolTags.PICKAXES)
.sounds(BlockSoundGroup.GLASS)
.requiresTool()
.noCollision());
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
super.appendProperties(stateManager);
stateManager.add(AGE, WATERLOGGED);
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
return state.get(AGE) < 2 ? Collections.emptyList() : Lists.newArrayList(new ItemStack(this));
}
@Override
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
return !state.get(WATERLOGGED);
}
@Override
public boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) {
return !state.get(WATERLOGGED);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
WorldView worldView = ctx.getWorld();
BlockPos blockPos = ctx.getBlockPos();
boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER;
return super.getPlacementState(ctx).with(WATERLOGGED, water);
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.getDefaultState();
}
}

View file

@ -0,0 +1,75 @@
package ru.betterend.blocks.basis;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import ru.betterend.util.BlocksHelper;
public abstract class BlockAttached extends BlockBaseNotFull {
public BlockAttached(Settings settings) {
super(settings);
}
public static final DirectionProperty FACING = Properties.FACING;
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
stateManager.add(FACING);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockState blockState = this.getDefaultState();
WorldView worldView = ctx.getWorld();
BlockPos blockPos = ctx.getBlockPos();
Direction[] directions = ctx.getPlacementDirections();
for (int i = 0; i < directions.length; ++i) {
Direction direction = directions[i];
Direction direction2 = direction.getOpposite();
blockState = (BlockState) blockState.with(FACING, direction2);
if (blockState.canPlaceAt(worldView, blockPos)) {
return blockState;
}
}
return null;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
Direction direction = (Direction) state.get(FACING);
BlockPos blockPos = pos.offset(direction.getOpposite());
return sideCoversSmallSquare(world, blockPos, direction) || world.getBlockState(blockPos).isIn(BlockTags.LEAVES);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.getDefaultState();
}
else {
return state;
}
}
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING);
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
}
}

View file

@ -8,40 +8,27 @@ import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.block.ShapeContext;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
public class BlockFur extends BlockBaseNotFull implements IRenderTypeable {
public class BlockFur extends BlockAttached implements IRenderTypeable {
private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
public static final DirectionProperty FACING = Properties.FACING;
private final ItemConvertible drop;
private final int dropChance;
@ -65,51 +52,12 @@ public class BlockFur extends BlockBaseNotFull implements IRenderTypeable {
this.drop = drop;
this.dropChance = dropChance;
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
stateManager.add(FACING);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
return BOUNDING_SHAPES.get(state.get(FACING));
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockState blockState = this.getDefaultState();
WorldView worldView = ctx.getWorld();
BlockPos blockPos = ctx.getBlockPos();
Direction[] directions = ctx.getPlacementDirections();
for (int i = 0; i < directions.length; ++i) {
Direction direction = directions[i];
Direction direction2 = direction.getOpposite();
blockState = (BlockState) blockState.with(FACING, direction2);
if (blockState.canPlaceAt(worldView, blockPos)) {
return blockState;
}
}
return null;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
Direction direction = (Direction) state.get(FACING);
BlockPos blockPos = pos.offset(direction.getOpposite());
return sideCoversSmallSquare(world, blockPos, direction) || world.getBlockState(blockPos).isIn(BlockTags.LEAVES);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.getDefaultState();
}
else {
return state;
}
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.get(LootContextParameters.TOOL);
@ -129,16 +77,6 @@ public class BlockFur extends BlockBaseNotFull implements IRenderTypeable {
return ERenderLayer.CUTOUT;
}
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING);
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
}
static {
BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 0.5, 1.0));
BOUNDING_SHAPES.put(Direction.DOWN, VoxelShapes.cuboid(0.0, 0.5, 0.0, 1.0, 1.0, 1.0));