Continue mapping migration
This commit is contained in:
parent
99ade39404
commit
f03fd03bd0
499 changed files with 12567 additions and 12723 deletions
|
@ -6,39 +6,39 @@ import java.util.Random;
|
|||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.block.ShapeContext;
|
||||
import net.minecraft.world.entity.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemPlacementContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.BlockMirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.betterend.blocks.basis.BlockBase;
|
||||
import ru.betterend.client.render.ERenderLayer;
|
||||
import ru.betterend.entity.SilkMothEntity;
|
||||
|
@ -50,24 +50,23 @@ import ru.betterend.util.MHelper;
|
|||
|
||||
public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
|
||||
public static final BooleanProperty ACTIVE = BlockProperties.ACTIVE;
|
||||
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING;
|
||||
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
||||
public static final IntegerProperty FULLNESS = BlockProperties.FULLNESS;
|
||||
private static final VoxelShape TOP = createCuboidShape(6, 0, 6, 10, 16, 10);
|
||||
private static final VoxelShape BOTTOM = createCuboidShape(0, 0, 0, 16, 16, 16);
|
||||
|
||||
private static final VoxelShape TOP = box(6, 0, 6, 10, 16, 10);
|
||||
private static final VoxelShape BOTTOM = box(0, 0, 0, 16, 16, 16);
|
||||
|
||||
public SilkMothNestBlock() {
|
||||
super(FabricBlockSettings.of(Material.WOOL).hardness(0.5F).resistance(0.1F).sounds(SoundType.WOOL).nonOpaque()
|
||||
.ticksRandomly());
|
||||
this.setDefaultState(getDefaultState().with(ACTIVE, true).with(FULLNESS, 0));
|
||||
super(FabricBlockSettings.of(Material.WOOL).hardness(0.5F).resistance(0.1F).sound(SoundType.WOOL).noOcclusion().randomTicks());
|
||||
this.registerDefaultState(defaultBlockState().setValue(ACTIVE, true).setValue(FULLNESS, 0));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
|
||||
stateManager.add(ACTIVE, FACING, FULLNESS);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
||||
return state.getValue(ACTIVE) ? BOTTOM : TOP;
|
||||
}
|
||||
|
||||
|
@ -75,54 +74,53 @@ public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
|
|||
public ERenderLayer getRenderLayer() {
|
||||
return ERenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
Direction dir = ctx.getPlayerFacing().getOpposite();
|
||||
return this.defaultBlockState().with(FACING, dir);
|
||||
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
||||
Direction dir = ctx.getHorizontalDirection().getOpposite();
|
||||
return this.defaultBlockState().setValue(FACING, dir);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
|
||||
BlockPos pos, BlockPos neighborPos) {
|
||||
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
|
||||
if (!state.getValue(ACTIVE)) {
|
||||
if (sideCoversSmallSquare(world, pos.up(), Direction.DOWN)
|
||||
|| world.getBlockState(pos.up()).isIn(BlockTags.LEAVES)) {
|
||||
if (canSupportCenter(world, pos.above(), Direction.DOWN) || world.getBlockState(pos.above()).is(BlockTags.LEAVES)) {
|
||||
return state;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return Blocks.AIR.defaultBlockState();
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||
return BlocksHelper.rotateHorizontal(state, rotation, FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, BlockMirror mirror) {
|
||||
public BlockState mirror(BlockState state, Mirror mirror) {
|
||||
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
return state.getValue(ACTIVE) ? Collections.singletonList(new ItemStack(this)) : Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBreak(Level world, BlockPos pos, BlockState state, Player player) {
|
||||
public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) {
|
||||
if (!state.getValue(ACTIVE) && player.isCreative()) {
|
||||
BlocksHelper.setWithUpdate(world, pos.below(), Blocks.AIR);
|
||||
}
|
||||
BlockState up = world.getBlockState(pos.up());
|
||||
if (up.is(this) && !up.get(ACTIVE)) {
|
||||
BlocksHelper.setWithUpdate(world, pos.up(), Blocks.AIR);
|
||||
BlockState up = world.getBlockState(pos.above());
|
||||
if (up.is(this) && !up.getValue(ACTIVE)) {
|
||||
BlocksHelper.setWithUpdate(world, pos.above(), Blocks.AIR);
|
||||
}
|
||||
super.onBreak(world, pos, state, player);
|
||||
super.playerWillDestroy(world, pos, state, player);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
|
||||
if (!state.getValue(ACTIVE)) {
|
||||
|
@ -136,44 +134,40 @@ public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
|
|||
if (!world.getBlockState(spawn).isAir()) {
|
||||
return;
|
||||
}
|
||||
int count = world.getEntitiesByType(EndEntities.SILK_MOTH, new Box(pos).expand(16), (entity) -> {
|
||||
return true;
|
||||
}).size();
|
||||
int count = world.getEntities(EndEntities.SILK_MOTH, new AABB(pos).inflate(16), (entity) -> { return true; }).size();
|
||||
if (count > 6) {
|
||||
return;
|
||||
}
|
||||
SilkMothEntity moth = new SilkMothEntity(EndEntities.SILK_MOTH, world);
|
||||
moth.refreshPositionAndAngles(spawn.getX() + 0.5, spawn.getY() + 0.5, spawn.getZ() + 0.5, dir.asRotation(), 0);
|
||||
moth.setVelocity(new Vec3d(dir.getOffsetX() * 0.4, 0, dir.getOffsetZ() * 0.4));
|
||||
moth.moveTo(spawn.getX() + 0.5, spawn.getY() + 0.5, spawn.getZ() + 0.5, dir.toYRot(), 0);
|
||||
moth.setDeltaMovement(new Vec3(dir.getStepX() * 0.4, 0, dir.getStepZ() * 0.4));
|
||||
moth.setHive(world, pos);
|
||||
world.spawnEntity(moth);
|
||||
world.playLocalSound(null, pos, SoundEvents.BLOCK_BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1);
|
||||
world.addFreshEntity(moth);
|
||||
world.playSound(null, pos, SoundEvents.BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand,
|
||||
BlockHitResult hit) {
|
||||
if (hand == Hand.MAIN_HAND) {
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
if (stack.getItem().isIn(FabricToolTags.SHEARS) && state.getValue(ACTIVE)
|
||||
&& state.getValue(FULLNESS) == 3) {
|
||||
BlocksHelper.setWithUpdate(world, pos, state.with(FULLNESS, 0));
|
||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
||||
if (hand == InteractionHand.MAIN_HAND) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.getItem().is(FabricToolTags.SHEARS) && state.getValue(ACTIVE) && state.getValue(FULLNESS) == 3) {
|
||||
BlocksHelper.setWithUpdate(world, pos, state.setValue(FULLNESS, 0));
|
||||
Direction dir = state.getValue(FACING);
|
||||
double px = pos.getX() + dir.getOffsetX() + 0.5;
|
||||
double py = pos.getY() + dir.getOffsetY() + 0.5;
|
||||
double pz = pos.getZ() + dir.getOffsetZ() + 0.5;
|
||||
double px = pos.getX() + dir.getStepX() + 0.5;
|
||||
double py = pos.getY() + dir.getStepY() + 0.5;
|
||||
double pz = pos.getZ() + dir.getStepZ() + 0.5;
|
||||
ItemStack drop = new ItemStack(EndItems.SILK_FIBER, MHelper.randRange(1, 4, world.getRandom()));
|
||||
ItemEntity entity = new ItemEntity(world, px, py, pz, drop);
|
||||
world.spawnEntity(entity);
|
||||
world.addFreshEntity(entity);
|
||||
drop = new ItemStack(EndItems.SILK_MOTH_MATRIX, MHelper.randRange(1, 3, world.getRandom()));
|
||||
entity = new ItemEntity(world, px, py, pz, drop);
|
||||
world.spawnEntity(entity);
|
||||
world.addFreshEntity(entity);
|
||||
if (!player.isCreative()) {
|
||||
stack.setDamage(stack.getDamage() + 1);
|
||||
stack.setDamageValue(stack.getDamageValue() + 1);
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return ActionResult.FAIL;
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue