Fixes
This commit is contained in:
parent
a968b9bb23
commit
8beabd0f96
18 changed files with 176 additions and 63 deletions
|
@ -12,7 +12,9 @@ import net.minecraft.state.property.BooleanProperty;
|
|||
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.blocks.basis.BlockBase;
|
||||
import ru.betterend.registry.BlockRegistry;
|
||||
|
||||
public class BlockBlueVineLantern extends BlockBase {
|
||||
public static final BooleanProperty NATURAL = BooleanProperty.of("natural");
|
||||
|
@ -22,9 +24,14 @@ public class BlockBlueVineLantern extends BlockBase {
|
|||
this.setDefaultState(this.stateManager.getDefaultState().with(NATURAL, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
return state.get(NATURAL) ? world.getBlockState(pos.down()).getBlock() == BlockRegistry.BLUE_VINE : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
if (state.get(NATURAL) && world.isAir(pos.down())) {
|
||||
if (!canPlaceAt(state, world, pos)) {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -2,18 +2,19 @@ package ru.betterend.blocks;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.BlockPlantWithStages;
|
||||
import ru.betterend.blocks.basis.BlockGlowingFur;
|
||||
import ru.betterend.blocks.basis.BlockPlantWithAge;
|
||||
import ru.betterend.registry.BlockRegistry;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class BlockBlueVineSeed extends BlockPlantWithStages {
|
||||
public class BlockBlueVineSeed extends BlockPlantWithAge {
|
||||
@Override
|
||||
public void grow(ServerWorld world, Random random, BlockPos pos) {
|
||||
public void grow(StructureWorldAccess world, Random random, BlockPos pos) {
|
||||
int height = MHelper.randRange(2, 5, random);
|
||||
int h = BlocksHelper.upRay(world, pos, height + 2);
|
||||
if (h < height + 1) {
|
||||
|
@ -27,7 +28,7 @@ public class BlockBlueVineSeed extends BlockPlantWithStages {
|
|||
placeLantern(world, pos.up(height + 1));
|
||||
}
|
||||
|
||||
private void placeLantern(ServerWorld world, BlockPos pos) {
|
||||
private void placeLantern(StructureWorldAccess world, BlockPos pos) {
|
||||
BlocksHelper.setWithoutUpdate(world, pos, BlockRegistry.BLUE_VINE_LANTERN.getDefaultState().with(BlockBlueVineLantern.NATURAL, true));
|
||||
for (Direction dir: BlocksHelper.HORIZONTAL) {
|
||||
BlockPos p = pos.offset(dir);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ru.betterend.blocks;
|
||||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
@ -15,6 +15,7 @@ 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;
|
||||
|
@ -30,24 +31,24 @@ import net.minecraft.util.shape.VoxelShapes;
|
|||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.blocks.basis.BlockBaseNotFull;
|
||||
import ru.betterend.client.ERenderLayer;
|
||||
import ru.betterend.client.IRenderTypeable;
|
||||
import ru.betterend.registry.BlockRegistry;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class BlockGlowingFur extends BlockBaseNotFull 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;
|
||||
|
||||
public BlockGlowingFur(int dropChance) {
|
||||
public BlockGlowingFur(ItemConvertible drop, int dropChance) {
|
||||
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.sounds(BlockSoundGroup.WET_GRASS)
|
||||
.lightLevel(15)
|
||||
.breakByHand(true)
|
||||
.noCollision());
|
||||
this.drop = drop;
|
||||
this.dropChance = dropChance;
|
||||
}
|
||||
|
||||
|
@ -102,7 +103,7 @@ public class BlockGlowingFur extends BlockBaseNotFull implements IRenderTypeable
|
|||
return Lists.newArrayList(new ItemStack(this));
|
||||
}
|
||||
else if (MHelper.RANDOM.nextInt(dropChance) == 0) {
|
||||
return Lists.newArrayList(new ItemStack(BlockRegistry.MOSSY_GLOWSHROOM_SAPLING));
|
||||
return Lists.newArrayList(new ItemStack(drop));
|
||||
}
|
||||
else {
|
||||
return Lists.newArrayList();
|
|
@ -8,8 +8,9 @@ import net.minecraft.server.world.ServerWorld;
|
|||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
|
||||
public abstract class BlockPlantWithStages extends BlockPlant {
|
||||
public abstract class BlockPlantWithAge extends BlockPlant {
|
||||
public static final IntProperty AGE = IntProperty.of("age", 0, 4);
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +18,7 @@ public abstract class BlockPlantWithStages extends BlockPlant {
|
|||
stateManager.add(AGE);
|
||||
}
|
||||
|
||||
public abstract void grow(ServerWorld world, Random random, BlockPos pos);
|
||||
public abstract void grow(StructureWorldAccess world, Random random, BlockPos pos);
|
||||
|
||||
@Override
|
||||
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
|
|
@ -1,27 +1,29 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
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.AbstractBlock;
|
||||
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.block.entity.BlockEntity;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
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.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.client.ERenderLayer;
|
||||
|
@ -41,24 +43,23 @@ public class BlockUpDownPlant extends BlockBaseNotFull implements IRenderTypeabl
|
|||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
Vec3d vec3d = state.getModelOffset(view, pos);
|
||||
return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBlock.OffsetType getOffsetType() {
|
||||
return AbstractBlock.OffsetType.XZ;
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
BlockState down = world.getBlockState(pos.down());
|
||||
return isTerrain(down);
|
||||
BlockState up = world.getBlockState(pos.up());
|
||||
return (isTerrain(down) || down.getBlock() == this) && (isSupport(up, world, pos) || up.getBlock() == this);
|
||||
}
|
||||
|
||||
protected boolean isTerrain(BlockState state) {
|
||||
return state.isIn(BlockTagRegistry.END_GROUND);
|
||||
}
|
||||
|
||||
protected boolean isSupport(BlockState state, WorldView world, BlockPos pos) {
|
||||
return sideCoversSmallSquare(world, pos.up(), Direction.UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
|
@ -85,4 +86,10 @@ public class BlockUpDownPlant extends BlockBaseNotFull implements IRenderTypeabl
|
|||
public ERenderLayer getRenderLayer() {
|
||||
return ERenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockState state, BlockEntity blockEntity, ItemStack stack) {
|
||||
super.afterBreak(world, player, pos, state, blockEntity, stack);
|
||||
world.updateNeighbor(pos, Blocks.AIR, pos.down());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue