-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ZhuRuoLing-refactor/multiblock_crafting' into refactor/…
…multiblock_crafting
- Loading branch information
Showing
431 changed files
with
13,763 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
common/src/main/java/dev/dubhe/anvilcraft/block/EmberAnvilBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package dev.dubhe.anvilcraft.block; | ||
|
||
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; | ||
import dev.dubhe.anvilcraft.init.ModMenuTypes; | ||
import dev.dubhe.anvilcraft.inventory.EmberAnvilMenu; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.stats.Stats; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.MenuProvider; | ||
import net.minecraft.world.SimpleMenuProvider; | ||
import net.minecraft.world.entity.item.FallingBlockEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.ContainerLevelAccess; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.AnvilBlock; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
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 org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class EmberAnvilBlock extends AnvilBlock implements IHammerRemovable, EmberBlock { | ||
private static final VoxelShape BASE = Block.box(2.0, 0.0, 2.0, 14.0, 4.0, 14.0); | ||
private static final VoxelShape X_LEG1 = Block.box(4.0, 4.0, 5.0, 12.0, 10.0, 11.0); | ||
private static final VoxelShape X_TOP = Block.box(0.0, 10.0, 3.0, 16.0, 16.0, 13.0); | ||
private static final VoxelShape Z_LEG1 = Block.box(5.0, 4.0, 4.0, 11.0, 10.0, 12.0); | ||
private static final VoxelShape Z_TOP = Block.box(3.0, 10.0, 0.0, 13.0, 16.0, 16.0); | ||
private static final VoxelShape X_AXIS_AABB = Shapes.or(BASE, X_LEG1, X_TOP); | ||
private static final VoxelShape Z_AXIS_AABB = Shapes.or(BASE, Z_LEG1, Z_TOP); | ||
private static final Component CONTAINER_TITLE = Component.translatable("container.repair"); | ||
|
||
@Getter | ||
@Setter | ||
private BlockState checkBlockState; | ||
|
||
public EmberAnvilBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public @NotNull VoxelShape getShape( | ||
@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull CollisionContext context | ||
) { | ||
Direction direction = state.getValue(FACING); | ||
if (direction.getAxis() == Direction.Axis.X) { | ||
return X_AXIS_AABB; | ||
} | ||
return Z_AXIS_AABB; | ||
} | ||
|
||
@SuppressWarnings("UnreachableCode") | ||
@Override | ||
public @NotNull InteractionResult use( | ||
@NotNull BlockState state, @NotNull Level level, | ||
@NotNull BlockPos pos, @NotNull Player player, | ||
@NotNull InteractionHand hand, @NotNull BlockHitResult hit | ||
) { | ||
if (level.isClientSide) return InteractionResult.SUCCESS; | ||
ModMenuTypes.open((ServerPlayer) player, state.getMenuProvider(level, pos)); | ||
player.awardStat(Stats.INTERACT_WITH_ANVIL); | ||
return InteractionResult.CONSUME; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public MenuProvider getMenuProvider(@Nonnull BlockState state, @Nonnull Level level, @Nonnull BlockPos pos) { | ||
return new SimpleMenuProvider((i, inventory, player) -> | ||
new EmberAnvilMenu(i, inventory, ContainerLevelAccess.create(level, pos)), CONTAINER_TITLE); | ||
} | ||
|
||
@Override | ||
protected void falling(@NotNull FallingBlockEntity entity) { | ||
entity.setHurtsEntities(2.0f, 80); | ||
} | ||
|
||
@Override | ||
public boolean isRandomlyTicking(@NotNull BlockState state) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void randomTick( | ||
@NotNull BlockState state, | ||
@NotNull ServerLevel level, | ||
@NotNull BlockPos pos, | ||
@NotNull RandomSource random | ||
) { | ||
if (random.nextDouble() <= 0.5) { | ||
tryAbsorbWater(level, pos); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
common/src/main/java/dev/dubhe/anvilcraft/block/EmberBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package dev.dubhe.anvilcraft.block; | ||
|
||
import dev.dubhe.anvilcraft.init.ModFluidTags; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.BucketPickup; | ||
import net.minecraft.world.level.block.LiquidBlock; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.material.FluidState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* 余烬金属系方块 | ||
*/ | ||
public interface EmberBlock { | ||
BlockState getCheckBlockState(); | ||
|
||
void setCheckBlockState(BlockState blockState); | ||
|
||
/** | ||
* 尝试吸水 | ||
*/ | ||
default void tryAbsorbWater(@NotNull Level level, @NotNull BlockPos pos) { | ||
if (this.removeFluidBreadthFirstSearch(level, pos)) { | ||
level.levelEvent(2001, pos, Block.getId(getCheckBlockState())); | ||
level.playSound(null, pos, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 1f, 1f); | ||
} | ||
} | ||
|
||
private boolean removeFluidBreadthFirstSearch(Level level, BlockPos pos) { | ||
return BlockPos.breadthFirstTraversal(pos, 6, 65, (posx, consumer) -> { | ||
|
||
for (Direction direction : Direction.values()) { | ||
consumer.accept(posx.relative(direction)); | ||
} | ||
|
||
}, (checkedPos) -> { | ||
if (checkedPos.equals(pos)) { | ||
return true; | ||
} else { | ||
BlockState blockState = level.getBlockState(checkedPos); | ||
FluidState fluidState = level.getFluidState(checkedPos); | ||
if (!fluidState.is(ModFluidTags.MENGER_SPONGE_CAN_ABSORB)) { | ||
return false; | ||
} else { | ||
Block block = blockState.getBlock(); | ||
if (block instanceof BucketPickup bucketPickup) { | ||
if (!bucketPickup.pickupBlock(level, checkedPos, blockState).isEmpty()) { | ||
setCheckBlockState(blockState); | ||
return true; | ||
} | ||
} | ||
|
||
if (blockState.getBlock() instanceof LiquidBlock) { | ||
level.setBlock(checkedPos, Blocks.AIR.defaultBlockState(), 3); | ||
} else { | ||
if (!blockState.is(Blocks.KELP) | ||
&& !blockState.is(Blocks.KELP_PLANT) | ||
&& !blockState.is(Blocks.SEAGRASS) | ||
&& !blockState.is(Blocks.TALL_SEAGRASS)) { | ||
return false; | ||
} | ||
|
||
BlockEntity blockEntity = blockState.hasBlockEntity() ? level.getBlockEntity(checkedPos) : null; | ||
Block.dropResources(blockState, level, checkedPos, blockEntity); | ||
level.setBlock(checkedPos, Blocks.AIR.defaultBlockState(), 3); | ||
} | ||
setCheckBlockState(blockState); | ||
return true; | ||
} | ||
} | ||
}) > 1; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
common/src/main/java/dev/dubhe/anvilcraft/block/EmberGrindstone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package dev.dubhe.anvilcraft.block; | ||
|
||
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; | ||
import dev.dubhe.anvilcraft.init.ModMenuTypes; | ||
import dev.dubhe.anvilcraft.inventory.EmberGrindstoneMenu; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.stats.Stats; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.MenuProvider; | ||
import net.minecraft.world.SimpleMenuProvider; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.ContainerLevelAccess; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.GrindstoneBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class EmberGrindstone extends GrindstoneBlock implements IHammerRemovable, EmberBlock { | ||
|
||
private static final Component CONTAINER_TITLE = Component.translatable("container.grindstone_title"); | ||
@Getter | ||
@Setter | ||
private BlockState checkBlockState; | ||
|
||
public EmberGrindstone(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@SuppressWarnings("UnreachableCode") | ||
@Override | ||
public @NotNull InteractionResult use( | ||
@NotNull BlockState state, @NotNull Level level, | ||
@NotNull BlockPos pos, @NotNull Player player, | ||
@NotNull InteractionHand hand, @NotNull BlockHitResult hit | ||
) { | ||
if (level.isClientSide) return InteractionResult.SUCCESS; | ||
ModMenuTypes.open((ServerPlayer) player, state.getMenuProvider(level, pos)); | ||
player.awardStat(Stats.INTERACT_WITH_GRINDSTONE); | ||
return InteractionResult.CONSUME; | ||
} | ||
|
||
@Override | ||
public MenuProvider getMenuProvider(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos) { | ||
return new SimpleMenuProvider((i, inventory, player) -> | ||
new EmberGrindstoneMenu(i, inventory, ContainerLevelAccess.create(level, pos)), CONTAINER_TITLE); | ||
} | ||
|
||
@Override | ||
public boolean isRandomlyTicking(@NotNull BlockState state) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void randomTick( | ||
@NotNull BlockState state, | ||
@NotNull ServerLevel level, | ||
@NotNull BlockPos pos, | ||
@NotNull RandomSource random | ||
) { | ||
if (random.nextDouble() <= 0.5) { | ||
tryAbsorbWater(level, pos); | ||
} | ||
} | ||
} | ||
|
39 changes: 39 additions & 0 deletions
39
common/src/main/java/dev/dubhe/anvilcraft/block/EmberMetalBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.dubhe.anvilcraft.block; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class EmberMetalBlock extends Block implements EmberBlock { | ||
private final double waterAbsorptionChance; | ||
@Getter | ||
@Setter | ||
private BlockState checkBlockState; | ||
|
||
public EmberMetalBlock(Properties properties, double waterAbsorptionChance) { | ||
super(properties); | ||
this.waterAbsorptionChance = waterAbsorptionChance; | ||
} | ||
|
||
@Override | ||
public boolean isRandomlyTicking(@NotNull BlockState state) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void randomTick( | ||
@NotNull BlockState state, | ||
@NotNull ServerLevel level, | ||
@NotNull BlockPos pos, | ||
@NotNull RandomSource random | ||
) { | ||
if (random.nextDouble() <= waterAbsorptionChance) { | ||
tryAbsorbWater(level, pos); | ||
} | ||
} | ||
} |
Oops, something went wrong.