Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,11 @@ protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos,
if (context.isHoldingItem(state.getBlock().asItem()) || context.isHoldingItem(ModBlocks.DEFLECTION_RING.asItem())) {
return Shapes.block();
}
return getPreciseShape(state);
return super.getShape(state, level, pos, context);
}

@Override
protected VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return getPreciseShape(state);
}

private static VoxelShape getPreciseShape(BlockState state) {
public VoxelShape getPartShape(BlockState state) {
Direction.Axis axis = state.getValue(FACING).getAxis();
if (isChannelPart(state.getValue(HALF), axis)) return Shapes.empty();
return COLLISION_SHAPES.get(axis).get(state.getValue(HALF));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,11 @@ protected VoxelShape getShape(
if (context.isHoldingItem(state.getBlock().asItem()) || context.isHoldingItem(ModBlocks.ACCELERATION_RING.asItem())) {
return Shapes.block();
}
return getPreciseShape(state);
return super.getShape(state, level, pos, context);
}

@Override
protected VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return getPreciseShape(state);
}

private static VoxelShape getPreciseShape(BlockState state) {
public VoxelShape getPartShape(BlockState state) {
return COLLISION_SHAPES.get(state.getValue(FACING).getAxis()).get(state.getValue(HALF));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.common.NeoForge;
Expand Down Expand Up @@ -198,12 +197,7 @@ public GiantAnvilBlock(Properties properties) {
}

@Override
public VoxelShape getShape(
BlockState state,
BlockGetter level,
BlockPos pos,
CollisionContext context
) {
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(HALF)) {
case MID_E -> MID_E;
case MID_W -> MID_W;
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/dev/dubhe/anvilcraft/block/LargeCakeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,17 @@ public LargeCakeBlock(Properties properties) {
this.registerDefaultState(this.stateDefinition.any().setValue(HALF, Cube3x3PartHalf.BOTTOM_CENTER));
}

/**
大蛋糕可以逐格吃掉而不是整体破坏,因此每一格只显示自己那一格的轮廓,
而不是像其它多方块那样显示整个结构的轮廓。
*/
@Override
public VoxelShape getShape(
BlockState state,
BlockGetter level,
BlockPos pos,
CollisionContext context) {
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return this.getPartShape(state);
}

@Override
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(HALF)) {
case TOP_CENTER -> TOP_CENTER;
case TOP_E -> TOP_E;
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/dev/dubhe/anvilcraft/block/LargeCauldronBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,15 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
Cube3x3PartHalf part = state.getValue(HALF);
if (part.getOffsetY() == 2 && context.isHoldingItem(ModBlocks.GIANT_ANVIL.asItem())) {
if (state.getValue(HALF).getOffsetY() == 2 && context.isHoldingItem(ModBlocks.GIANT_ANVIL.asItem())) {
return Shapes.block();
}
return SHAPES.get(part);
return super.getShape(state, level, pos, context);
}

@Override
public VoxelShape getPartShape(BlockState state) {
return SHAPES.get(state.getValue(HALF));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -223,15 +222,10 @@ protected boolean propagatesSkylightDown(BlockState state, BlockGetter level, Bl
}

@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
public VoxelShape getPartShape(BlockState state) {
return COLLISION_SHAPES.get(state.getValue(FACING)).get(state.getValue(HALF));
}

@Override
protected VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return this.getShape(state, level, pos, context);
}

@Override
public boolean change(Player player, BlockPos blockPos, Level level, ItemStack anvilHammer) {
this.change(blockPos, level, (state) -> state.cycle(FACING));
Expand Down
15 changes: 4 additions & 11 deletions src/main/java/dev/dubhe/anvilcraft/block/OverseerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import dev.dubhe.anvilcraft.block.state.Vertical3PartHalf;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
Expand All @@ -21,7 +20,6 @@
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
Expand All @@ -30,9 +28,9 @@ public class OverseerBlock
extends SimpleMultiPartBlock<Vertical3PartHalf>
implements IHammerRemovable, IHasMultiBlock, EntityBlock {
private static final VoxelShape OVERSEER_BOTTOM =
Shapes.or(Block.box(0, 0, 0, 16, 4, 16), Block.box(2, 8, 2, 14, 48, 14));
private static final VoxelShape OVERSEER_MID = OVERSEER_BOTTOM.move(0, -1, 0);
private static final VoxelShape OVERSEER_TOP = OVERSEER_BOTTOM.move(0, -2, 0);
Shapes.or(Block.box(0, 0, 0, 16, 4, 16), Block.box(2, 8, 2, 14, 16, 14));
private static final VoxelShape OVERSEER_MID = Block.box(2, 0, 2, 14, 16, 14);
private static final VoxelShape OVERSEER_TOP = Block.box(2, 0, 2, 14, 16, 14);
public static final int MAX_LEVEL = 4;
public static final EnumProperty<Vertical3PartHalf> HALF = EnumProperty.create("half", Vertical3PartHalf.class);
public static final IntegerProperty LEVEL = IntegerProperty.create("level", 0, MAX_LEVEL);
Expand Down Expand Up @@ -77,12 +75,7 @@ public RenderShape getRenderShape(BlockState state) {
}

@Override
public VoxelShape getShape(
BlockState state,
BlockGetter level,
BlockPos pos,
CollisionContext context
) {
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(HALF)) {
case TOP -> OVERSEER_TOP;
case MID -> OVERSEER_MID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ private RedstoneWireNetworkManager() {
public static void topologyChanged(Level level, BlockPos pos) {
if (level instanceof ServerLevel serverLevel) {
// 客户端只消费同步后的方块状态,拓扑的权威计算必须集中在服务端。
state(serverLevel).requestTopologyUpdate(pos.asLong());
LevelNetworks state = state(serverLevel);
// 导线放置会在邻居更新前同步建网,先记录已有侦测器才能避免其错过首次索引。
state.rememberAdjacentObservers(pos);
state.requestTopologyUpdate(pos.asLong());
}
}

Expand Down Expand Up @@ -594,6 +597,16 @@ private void rememberObserver(BlockPos observerPos) {
this.observerChunks.add(ChunkPos.asLong(observerPos.getX() >> 4, observerPos.getZ() >> 4));
}

/** 记录导线六个相邻位置中的侦测器,供当前拓扑重建时建立观察索引。 */
private void rememberAdjacentObservers(BlockPos wirePos) {
for (Direction direction : Direction.values()) {
BlockPos observerPos = wirePos.relative(direction);
if (this.level.hasChunkAt(observerPos) && this.level.getBlockState(observerPos).is(Blocks.OBSERVER)) {
this.rememberObserver(observerPos);
}
}
}

/** 更新一个可能的侦测器位置与当前网络的对应关系。 */
private void refreshObserver(Network network, BlockPos observerPos, BlockState observerState) {
long packedObserverPos = observerPos.asLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
Expand All @@ -24,7 +23,6 @@
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -86,11 +84,7 @@ public RenderShape getRenderShape(BlockState state) {
}

@Override
public VoxelShape getShape(
BlockState state,
BlockGetter level,
BlockPos pos,
CollisionContext context) {
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(HALF)) {
case BOTTOM -> TRANSMISSION_POLE_BASE;
case MID_UPPER, MID_LOWER -> TRANSMISSION_POLE_MID;
Expand Down Expand Up @@ -171,10 +165,10 @@ protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState o
}

@Override
public void onRemove(Level level, BlockPos pos, BlockState state) {
public void onPlace(Level level, BlockPos pos, BlockState state) {
}

@Override
public void onPlace(Level level, BlockPos pos, BlockState state) {
public void onRemove(Level level, BlockPos pos, BlockState state) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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.block.Block;
import net.minecraft.world.level.block.RenderShape;
Expand All @@ -36,7 +35,6 @@
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.network.PacketDistributor;
Expand Down Expand Up @@ -96,11 +94,7 @@ public RenderShape getRenderShape(BlockState state) {
}

@Override
public VoxelShape getShape(
BlockState state,
BlockGetter level,
BlockPos pos,
CollisionContext context) {
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(HALF)) {
case BOTTOM -> BOTTOM_SHAPE;
case MID_LOWER -> LOWER_SHAPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,17 @@ public Collection<BlockState> getBottomStates() {

// Shapes

/**
交易站的底部方块本身就带有上方那一格的轮廓,上方方块则不显示轮廓,
因此保持原样,不显示由基类拼出的整体轮廓。
*/
@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return this.getPartShape(state);
}

@Override
public VoxelShape getPartShape(BlockState state) {
if (state.getValue(HALF) == DirectionVertical2PartHalf.TOP) return Shapes.empty();
return switch (state.getValue(FACING)) {
case NORTH -> NORTH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import dev.dubhe.anvilcraft.init.block.ModBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
Expand All @@ -23,7 +22,6 @@
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -84,16 +82,11 @@ public RenderShape getRenderShape(BlockState state) {
}

@Override
public VoxelShape getShape(
BlockState state,
BlockGetter level,
BlockPos pos,
CollisionContext context
) {
public VoxelShape getPartShape(BlockState state) {
if (state.getValue(HALF) == Vertical3PartHalf.BOTTOM) return TRANSMISSION_POLE_BASE;
if (state.getValue(HALF) == Vertical3PartHalf.MID) return TRANSMISSION_POLE_MID;
if (state.getValue(HALF) == Vertical3PartHalf.TOP) return TRANSMISSION_POLE_TOP;
return super.getShape(state, level, pos, context);
return super.getPartShape(state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public CelestialForgingAnvilAmplifierBlock(Properties properties) {
}

@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(FACING)) {
case NORTH -> switch (state.getValue(HALF)) {
case BOTTOM_WS -> NORTH_TIP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

Expand Down Expand Up @@ -127,7 +126,7 @@ public CelestialForgingAnvilBlock(Properties properties) {
}

@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(HALF)) {
case BOTTOM_CENTER -> Shapes.block();
case BOTTOM_W -> BOTTOM_W;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,14 @@ protected boolean propagatesSkylightDown(BlockState state, BlockGetter level, Bl

@Override
protected VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
if (state.getValue(HALF) == DirectionGate331PartHalf.BOTTOM_CENTER || state.getValue(HALF) == DirectionGate331PartHalf.MID_CENTER) {
if (context == CollisionContext.empty()) {
return this.getShape(state, level, pos, context);
}
return Shapes.empty();
}
return this.getShape(state, level, pos, context);
DirectionGate331PartHalf part = state.getValue(HALF);
boolean gateway = part == DirectionGate331PartHalf.BOTTOM_CENTER || part == DirectionGate331PartHalf.MID_CENTER;
if (gateway && context != CollisionContext.empty()) return Shapes.empty();
return super.getCollisionShape(state, level, pos, context);
}

@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(CelestialForgingAnvilPortalBlock.HALF)) {
case BOTTOM_CENTER -> switch (state.getValue(CelestialForgingAnvilPortalBlock.FACING)) {
case NORTH -> BOTTOM_CENTER_NORTH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.api.distmarker.Dist;
Expand Down Expand Up @@ -203,7 +202,7 @@ public InteractionResult use(

// region VoxelShapes
@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
public VoxelShape getPartShape(BlockState state) {
return switch (state.getValue(HALF)) {
case BOTTOM_CENTER -> BOTTOM_CENTER;
case BOTTOM_W -> BOTTOM_W;
Expand Down
Loading
Loading