-
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 pull request #863 from dmzz-yyhyy/mineral_fountain
冲击桩和矿物涌泉, 增加地核碎片对应矿物、物品、方块, 增加虚空物质对应矿物、物品、方块, 增加各金属对应粗矿、粗矿块、深板岩矿及配方
- Loading branch information
Showing
462 changed files
with
11,049 additions
and
394 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
28 changes: 28 additions & 0 deletions
28
common/src/main/java/dev/dubhe/anvilcraft/api/heatable/HeatableBlockManager.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,28 @@ | ||
package dev.dubhe.anvilcraft.api.heatable; | ||
|
||
import dev.dubhe.anvilcraft.block.RedhotMetalBlock; | ||
import dev.dubhe.anvilcraft.init.ModBlocks; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
|
||
import java.util.HashMap; | ||
|
||
public class HeatableBlockManager { | ||
private static final HashMap<Block, Block> heatableBlockMap = new HashMap<>(); | ||
|
||
public static void register(Block block, RedhotMetalBlock hotBlock) { | ||
heatableBlockMap.put(block, hotBlock); | ||
} | ||
|
||
public static Block getHotBlock(Block block) { | ||
if (!heatableBlockMap.containsKey(block)) return null; | ||
return heatableBlockMap.get(block); | ||
} | ||
|
||
static { | ||
register(Blocks.NETHERITE_BLOCK, ModBlocks.REDHOT_NETHERITE.get()); | ||
register(ModBlocks.HEATED_NETHERITE.get(), ModBlocks.REDHOT_NETHERITE.get()); | ||
register(ModBlocks.TUNGSTEN_BLOCK.get(), ModBlocks.REDHOT_TUNGSTEN.get()); | ||
register(ModBlocks.HEATED_TUNGSTEN.get(), ModBlocks.REDHOT_TUNGSTEN.get()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
common/src/main/java/dev/dubhe/anvilcraft/block/ImpactPileBlock.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,75 @@ | ||
package dev.dubhe.anvilcraft.block; | ||
|
||
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; | ||
import dev.dubhe.anvilcraft.init.ModBlocks; | ||
import net.minecraft.core.BlockPos; | ||
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.Blocks; | ||
import net.minecraft.world.level.block.RenderShape; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
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; | ||
|
||
public class ImpactPileBlock extends Block implements IHammerRemovable { | ||
private static final VoxelShape SHAPE = Shapes.or( | ||
Block.box(5, 14, 5, 11, 16, 11), | ||
Block.box(7, 0, 7, 9, 2, 9), | ||
Block.box(6, 2, 6, 10, 14, 10) | ||
); | ||
|
||
public ImpactPileBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public @NotNull VoxelShape getShape( | ||
@NotNull BlockState state, | ||
@NotNull BlockGetter level, | ||
@NotNull BlockPos pos, | ||
@NotNull CollisionContext context | ||
) { | ||
return SHAPE; | ||
} | ||
|
||
@Override | ||
public @NotNull RenderShape getRenderShape(@NotNull BlockState state) { | ||
return RenderShape.MODEL; | ||
} | ||
|
||
public void impact(Level level, BlockPos blockPos) { | ||
Check warning on line 43 in common/src/main/java/dev/dubhe/anvilcraft/block/ImpactPileBlock.java
|
||
level.destroyBlock(blockPos, false); | ||
level.destroyBlock(blockPos.above(), false); | ||
for (int x = blockPos.getX() - 1; x <= blockPos.getX() + 1; x++) { | ||
for (int z = blockPos.getZ() - 1; z <= blockPos.getZ() + 1; z++) { | ||
for (int y = level.getMinBuildHeight(); y <= level.getMinBuildHeight() + 5; y++) { | ||
BlockPos pos = new BlockPos(x, y, z); | ||
level.destroyBlock(new BlockPos(x, y, z), true); | ||
if (y <= level.getMinBuildHeight() + 1) | ||
level.setBlockAndUpdate(pos, Blocks.BEDROCK.defaultBlockState()); | ||
} | ||
} | ||
} | ||
for (int y = level.getMinBuildHeight() + 2; y <= level.getMinBuildHeight() + 3; y++) { | ||
BlockPos pos = new BlockPos(blockPos.getX(), y, blockPos.getZ()); | ||
if (y == level.getMinBuildHeight() + 2) { | ||
level.setBlockAndUpdate(pos.north().west(), Blocks.LAVA.defaultBlockState()); | ||
level.setBlockAndUpdate(pos.north().east(), Blocks.LAVA.defaultBlockState()); | ||
level.setBlockAndUpdate(pos.south().west(), Blocks.LAVA.defaultBlockState()); | ||
level.setBlockAndUpdate(pos.south().east(), Blocks.LAVA.defaultBlockState()); | ||
} | ||
level.setBlockAndUpdate(pos, Blocks.BEDROCK.defaultBlockState()); | ||
level.setBlockAndUpdate(pos.north(), Blocks.BEDROCK.defaultBlockState()); | ||
level.setBlockAndUpdate(pos.south(), Blocks.BEDROCK.defaultBlockState()); | ||
level.setBlockAndUpdate(pos.west(), Blocks.BEDROCK.defaultBlockState()); | ||
level.setBlockAndUpdate(pos.east(), Blocks.BEDROCK.defaultBlockState()); | ||
} | ||
level.setBlockAndUpdate( | ||
new BlockPos(blockPos.getX(), | ||
level.getMinBuildHeight() + 4, blockPos.getZ()), ModBlocks.MINERAL_FOUNTAIN.getDefaultState() | ||
); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
common/src/main/java/dev/dubhe/anvilcraft/block/MineralFountainBlock.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,44 @@ | ||
package dev.dubhe.anvilcraft.block; | ||
|
||
import dev.dubhe.anvilcraft.block.entity.MineralFountainBlockEntity; | ||
import dev.dubhe.anvilcraft.init.ModBlockEntities; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.BaseEntityBlock; | ||
import net.minecraft.world.level.block.RenderShape; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityTicker; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MineralFountainBlock extends BaseEntityBlock { | ||
|
||
public MineralFountainBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { | ||
return new MineralFountainBlockEntity(pos, state); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker( | ||
@NotNull Level level, | ||
@NotNull BlockState state, | ||
@NotNull BlockEntityType<T> blockEntityType | ||
) { | ||
if (level.isClientSide) return null; | ||
return createTickerHelper(blockEntityType, ModBlockEntities.MINERAL_FOUNTAIN.get(), | ||
(level1, pos, state1, entity) -> entity.tick()); | ||
} | ||
|
||
@Override | ||
public @NotNull RenderShape getRenderShape(@NotNull BlockState state) { | ||
return RenderShape.MODEL; | ||
} | ||
} |
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
127 changes: 127 additions & 0 deletions
127
common/src/main/java/dev/dubhe/anvilcraft/block/entity/MineralFountainBlockEntity.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,127 @@ | ||
package dev.dubhe.anvilcraft.block.entity; | ||
|
||
import dev.dubhe.anvilcraft.api.heatable.HeatableBlockManager; | ||
import dev.dubhe.anvilcraft.init.ModBlockEntities; | ||
import dev.dubhe.anvilcraft.init.ModBlockTags; | ||
import dev.dubhe.anvilcraft.init.ModBlocks; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.LiquidBlock; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
|
||
public class MineralFountainBlockEntity extends BlockEntity { | ||
private static final HashMap<ResourceLocation, HashMap<Block, Float>> CHANGE_MAP = new HashMap<>() {{ | ||
put(new ResourceLocation("overworld"), new HashMap<>() {{ | ||
put(ModBlocks.VOID_STONE.get(), 0.01f); | ||
put(ModBlocks.EARTH_CORE_SHARD_ORE.get(), 0.01f); | ||
} | ||
}); | ||
put(new ResourceLocation("the_nether"), new HashMap<>() {{ | ||
put(ModBlocks.VOID_STONE.get(), 0f); | ||
put(ModBlocks.EARTH_CORE_SHARD_ORE.get(), 0.2f); | ||
} | ||
}); | ||
put(new ResourceLocation("the_end"), new HashMap<>() {{ | ||
put(ModBlocks.VOID_STONE.get(), 0.2f); | ||
put(ModBlocks.EARTH_CORE_SHARD_ORE.get(), 0f); | ||
} | ||
}); | ||
}}; | ||
private int tickCount = 0; | ||
|
||
public MineralFountainBlockEntity(BlockPos pos, BlockState blockState) { | ||
super(ModBlockEntities.MINERAL_FOUNTAIN.get(), pos, blockState); | ||
} | ||
|
||
public static @NotNull MineralFountainBlockEntity createBlockEntity( | ||
BlockEntityType<?> type, BlockPos pos, BlockState blockState | ||
) { | ||
return new MineralFountainBlockEntity(type, pos, blockState); | ||
} | ||
|
||
private MineralFountainBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) { | ||
super(type, pos, blockState); | ||
} | ||
|
||
/** | ||
* 矿物泉涌tick | ||
*/ | ||
public void tick() { | ||
if (level == null) return; | ||
tickCount++; | ||
if (tickCount < 20) return; | ||
tickCount = 0; | ||
BlockState aroundBlock = getAroundBlock(); | ||
// 冷却检查 | ||
if (aroundBlock.is(Blocks.BLUE_ICE) | ||
|| aroundHas(Blocks.BEDROCK) | ||
|| aroundHas(ModBlocks.MINERAL_FOUNTAIN.get())) { | ||
level.destroyBlock(getBlockPos(), false); | ||
level.setBlockAndUpdate(getBlockPos(), Blocks.BEDROCK.defaultBlockState()); | ||
return; | ||
} | ||
// 高度检查 | ||
if (level.getMinBuildHeight() > getBlockPos().getY() || getBlockPos().getY() > level.getMinBuildHeight() + 5) | ||
return; | ||
// 底层基岩检查 | ||
BlockPos checkPos = getBlockPos(); | ||
while (checkPos.getY() > level.getMinBuildHeight()) { | ||
checkPos = checkPos.below(); | ||
if (!level.getBlockState(checkPos).is(Blocks.BEDROCK)) return; | ||
} | ||
BlockState aboveBlock = level.getBlockState(getBlockPos().above()); | ||
// 岩浆处理 | ||
if (aroundBlock.is(Blocks.LAVA)) { | ||
if (aboveBlock.is(Blocks.AIR)) { | ||
level.setBlockAndUpdate(getBlockPos().above(), Blocks.LAVA.defaultBlockState()); | ||
return; | ||
} | ||
Block hotBlock = HeatableBlockManager.getHotBlock(aboveBlock.getBlock()); | ||
if (hotBlock == null) return; | ||
level.setBlockAndUpdate(getBlockPos().above(), hotBlock.defaultBlockState()); | ||
} else if (aroundBlock.is(ModBlockTags.DEEPSLATE_METAL) && aboveBlock.is(Blocks.DEEPSLATE)) { | ||
HashMap<Block, Float> changeMap = CHANGE_MAP.containsKey(level.dimension().location()) | ||
? CHANGE_MAP.get(level.dimension().location()) | ||
: CHANGE_MAP.get(new ResourceLocation("overworld")); | ||
for (Block block : changeMap.keySet()) { | ||
if (level.getRandom().nextDouble() <= changeMap.get(block)) { | ||
level.setBlockAndUpdate(getBlockPos().above(), block.defaultBlockState()); | ||
return; | ||
} | ||
} | ||
level.setBlockAndUpdate(getBlockPos().above(), aroundBlock); | ||
} | ||
} | ||
|
||
private BlockState getAroundBlock() { | ||
if (level == null) return Blocks.AIR.defaultBlockState(); | ||
BlockState blockState = level.getBlockState(getBlockPos().south()); | ||
if (blockState.is(Blocks.LAVA) && blockState.getValue(LiquidBlock.LEVEL) > 0) | ||
return Blocks.AIR.defaultBlockState(); | ||
for (Direction direction : new Direction[]{Direction.NORTH, Direction.WEST, Direction.EAST}) { | ||
BlockState checkBlockState = level.getBlockState(getBlockPos().relative(direction)); | ||
if (!checkBlockState.is(blockState.getBlock())) | ||
return Blocks.AIR.defaultBlockState(); | ||
if (checkBlockState.is(Blocks.LAVA) && checkBlockState.getValue(LiquidBlock.LEVEL) > 0) | ||
return Blocks.AIR.defaultBlockState(); | ||
} | ||
return blockState; | ||
} | ||
|
||
private boolean aroundHas(Block block) { | ||
if (level == null) return false; | ||
for (Direction direction : new Direction[]{Direction.SOUTH, Direction.NORTH, Direction.WEST, Direction.EAST}) { | ||
if (level.getBlockState(getBlockPos().relative(direction)).is(block)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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
Oops, something went wrong.