Skip to content

Commit

Permalink
Merge pull request #863 from dmzz-yyhyy/mineral_fountain
Browse files Browse the repository at this point in the history
冲击桩和矿物涌泉, 增加地核碎片对应矿物、物品、方块, 增加虚空物质对应矿物、物品、方块, 增加各金属对应粗矿、粗矿块、深板岩矿及配方
  • Loading branch information
Gu-ZT authored Jun 8, 2024
2 parents 25a3222 + d4f533e commit ab6b77b
Show file tree
Hide file tree
Showing 462 changed files with 11,049 additions and 394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void addThermoBlock(BlockPos blockPos, BlockState state) {
register(ThermoEntry.always(2, ModBlocks.URANIUM_BLOCK.get()));

register(ThermoEntry.simple(4, Blocks.LAVA, Blocks.OBSIDIAN));
register(ThermoEntry.simple(4, Blocks.MAGMA_BLOCK, Blocks.NETHERITE_BLOCK));
register(ThermoEntry.simple(4, Blocks.MAGMA_BLOCK, Blocks.NETHERRACK));
register(ThermoEntry.simple(4, Blocks.LAVA_CAULDRON, ModBlocks.OBSIDIDAN_CAULDRON.get()));

register(ThermoEntry.predicate(4, CampfireBlock::isLitCampfire, t -> t.setValue(CampfireBlock.LIT, false)));
Expand Down
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());
}
}
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

View workflow job for this annotation

GitHub Actions / checkstyle

[Checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /home/runner/work/AnvilCraft/AnvilCraft/common/src/main/java/dev/dubhe/anvilcraft/block/ImpactPileBlock.java:43:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
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()
);
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public void emitLaser(Direction direction) {
BlockState irradiateBlock = level.getBlockState(irradiateBlockPos);
List<ItemStack> drops = Block.getDrops(irradiateBlock, serverLevel, irradiateBlockPos,
level.getBlockEntity(irradiateBlockPos));
int coldDown = levelToTimeMap.containsKey(Math.min(16, laserLevel))
? levelToTimeMap.get(Math.min(16, laserLevel)) * 20 : Integer.MAX_VALUE;
int coldDown = levelToTimeMap.containsKey(Math.min(16, laserLevel) / 4)
? levelToTimeMap.get(Math.min(16, laserLevel) / 4) * 20 : Integer.MAX_VALUE;
if (tickCount >= coldDown) {
tickCount = 0;
if (irradiateBlock.is(ModBlockTags.FORGE_ORES) || irradiateBlock.is(ModBlockTags.ORES)) {
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.data.generator.AnvilCraftDatagen;
import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe;
import dev.dubhe.anvilcraft.init.ModBlocks;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.world.item.Item;
Expand All @@ -25,6 +26,13 @@ public static void init(RegistrateRecipeProvider provider) {
itemInject(Items.RAW_COPPER_BLOCK, 3, Blocks.DEEPSLATE, Blocks.DEEPSLATE_COPPER_ORE, provider);
itemInject(Items.GOLD_INGOT, 2, Blocks.NETHERRACK, Blocks.NETHER_GOLD_ORE, provider);
itemInject(Items.GOLD_INGOT, Blocks.BLACKSTONE, Blocks.GILDED_BLACKSTONE, provider);
itemInject(ModBlocks.RAW_ZINC.asItem(), Blocks.DEEPSLATE, ModBlocks.DEEPSLATE_ZINC_ORE.get(), provider);
itemInject(ModBlocks.RAW_TIN.asItem(), Blocks.DEEPSLATE, ModBlocks.DEEPSLATE_TIN_ORE.get(), provider);
itemInject(ModBlocks.RAW_TITANIUM.asItem(), Blocks.DEEPSLATE, ModBlocks.DEEPSLATE_TITANIUM_ORE.get(), provider);
itemInject(ModBlocks.RAW_TUNGSTEN.asItem(), Blocks.DEEPSLATE, ModBlocks.DEEPSLATE_TUNGSTEN_ORE.get(), provider);
itemInject(ModBlocks.RAW_LEAD.asItem(), Blocks.DEEPSLATE, ModBlocks.DEEPSLATE_LEAD_ORE.get(), provider);
itemInject(ModBlocks.RAW_SILVER.asItem(), Blocks.DEEPSLATE, ModBlocks.DEEPSLATE_SILVER_ORE.get(), provider);
itemInject(ModBlocks.RAW_URANIUM.asItem(), Blocks.DEEPSLATE, ModBlocks.DEEPSLATE_URANIUM_ORE.get(), provider);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public static void init(RegistrateRecipeProvider provider) {
timeWarp(new RecipeItem(ModBlocks.END_DUST), new RecipeItem(Items.END_STONE));
timeWarp(new RecipeItem(ModItems.LIME_POWDER, 8), new RecipeItem(Items.CALCITE));
timeWarp(new RecipeItem(ModItems.NETHERITE_CRYSTAL_NUCLEUS), new RecipeItem(Items.ANCIENT_DEBRIS));
timeWarp(new RecipeItem(ModBlocks.ZINC_BLOCK), new RecipeItem(ModItems.RAW_ZINC, 3));
timeWarp(new RecipeItem(ModBlocks.TIN_BLOCK), new RecipeItem(ModItems.RAW_TIN, 3));
timeWarp(new RecipeItem(ModBlocks.TITANIUM_BLOCK), new RecipeItem(ModItems.RAW_TITANIUM, 3));
timeWarp(new RecipeItem(ModBlocks.TUNGSTEN_BLOCK), new RecipeItem(ModItems.RAW_TUNGSTEN, 3));
timeWarp(new RecipeItem(ModBlocks.LEAD_BLOCK), new RecipeItem(ModItems.RAW_LEAD, 3));
timeWarp(new RecipeItem(ModBlocks.SILVER_BLOCK), new RecipeItem(ModItems.RAW_SILVER, 3));
timeWarp(new RecipeItem(ModBlocks.URANIUM_BLOCK), new RecipeItem(ModItems.RAW_URANIUM, 3));

AnvilRecipe.Builder.create(RecipeCategory.MISC)
.icon(Items.WITHER_ROSE)
Expand Down
Loading

0 comments on commit ab6b77b

Please sign in to comment.