|
2 | 2 |
|
3 | 3 | import java.util.LinkedHashMap; |
4 | 4 | import java.util.Map; |
| 5 | +import java.util.Random; |
5 | 6 | import net.minecraft.block.Block; |
6 | 7 | import net.minecraft.block.BlockFlowingFluid; |
| 8 | +import net.minecraft.block.SoundType; |
7 | 9 | import net.minecraft.block.material.Material; |
8 | 10 | import net.minecraft.block.state.IBlockState; |
9 | 11 | import net.minecraft.fluid.FlowingFluid; |
|
16 | 18 | import net.minecraft.init.Items; |
17 | 19 | import net.minecraft.util.BlockRenderLayer; |
18 | 20 | import net.minecraft.util.ResourceLocation; |
| 21 | +import net.minecraft.util.IItemProvider; |
| 22 | +import net.minecraft.util.math.BlockPos; |
19 | 23 | import net.minecraft.util.registry.IRegistry; |
| 24 | +import net.minecraft.world.IWorldReader; |
| 25 | +import net.minecraft.world.World; |
20 | 26 | import net.minecraftforge.api.distmarker.Dist; |
21 | 27 | import net.minecraftforge.api.distmarker.OnlyIn; |
22 | 28 | import net.minecraftforge.common.ToolType; |
23 | 29 | import net.minecraftforge.event.RegistryEvent; |
24 | 30 | import net.minecraftforge.eventbus.api.SubscribeEvent; |
25 | 31 | import net.minecraftforge.fml.common.Mod; |
| 32 | +import net.minecraftforge.registries.ForgeRegistries; |
26 | 33 | import zone.moddev.mc.baseminerals.BaseMinerals; |
27 | 34 |
|
28 | 35 | /** Registry names are kept from the 1.10–1.12 builds. */ |
@@ -58,12 +65,12 @@ private static void initializeFluids() { |
58 | 65 | public static void registerBlocks(RegistryEvent.Register<Block> event) { |
59 | 66 | initializeFluids(); |
60 | 67 | for (String name : MATERIALS) { |
61 | | - putBlock(event, name + "_block", new MineralBlock(false)); |
62 | | - if (!"silicon".equals(name)) putBlock(event, name + "_ore", new MineralBlock(true)); |
| 68 | + putBlock(event, name + "_block", new MineralBlock(name, false)); |
| 69 | + if (!"silicon".equals(name)) putBlock(event, name + "_ore", new MineralBlock(name, true)); |
63 | 70 | } |
64 | 71 | MOLTEN.forEach((name, molten) -> { |
65 | 72 | molten.block = new BlockFlowingFluid(molten.source, Block.Properties.create(Material.LAVA) |
66 | | - .doesNotBlockMovement().hardnessAndResistance(100.0F).variableOpacity()) {}; |
| 73 | + .doesNotBlockMovement().hardnessAndResistance(100.0F).lightValue(10).variableOpacity()) {}; |
67 | 74 | putBlock(event, name, molten.block); |
68 | 75 | }); |
69 | 76 | } |
@@ -109,14 +116,44 @@ static final class Molten { |
109 | 116 |
|
110 | 117 | private static final class MineralBlock extends Block { |
111 | 118 | private final boolean ore; |
| 119 | + private final int harvestLevel; |
| 120 | + private final ResourceLocation powder; |
112 | 121 |
|
113 | | - MineralBlock(boolean ore) { |
114 | | - super(Block.Properties.create(Material.ROCK).hardnessAndResistance(3.0F, 5.0F)); |
| 122 | + MineralBlock(String material, boolean ore) { |
| 123 | + super(properties(material, ore)); |
115 | 124 | this.ore = ore; |
| 125 | + this.harvestLevel = isMetal(material) ? 2 : 1; |
| 126 | + this.powder = ore && !isMetal(material) ? id(material + "_powder") : null; |
| 127 | + } |
| 128 | + |
| 129 | + private static boolean isMetal(String material) { |
| 130 | + return "lithium".equals(material) || "silicon".equals(material); |
| 131 | + } |
| 132 | + |
| 133 | + private static Block.Properties properties(String material, boolean ore) { |
| 134 | + boolean metal = isMetal(material); |
| 135 | + float hardness = ore ? 5.0F : metal ? 16.0F : 10.0F; |
| 136 | + // The old library stored resistance at five times Minecraft's exposed value. |
| 137 | + float resistance = (metal ? 4.0F : 1.0F) * (ore ? 0.75F : 1.0F); |
| 138 | + return Block.Properties.create(metal && !ore ? Material.IRON : Material.ROCK) |
| 139 | + .sound(metal && !ore ? SoundType.METAL : SoundType.STONE) |
| 140 | + .hardnessAndResistance(hardness, resistance); |
116 | 141 | } |
117 | 142 |
|
118 | 143 | @Override public ToolType getHarvestTool(IBlockState state) { return ToolType.PICKAXE; } |
119 | | - @Override public int getHarvestLevel(IBlockState state) { return 1; } |
| 144 | + @Override public int getHarvestLevel(IBlockState state) { return harvestLevel; } |
| 145 | + @Override public IItemProvider getItemDropped(IBlockState state, World world, BlockPos pos, int fortune) { |
| 146 | + return powder == null ? this : ForgeRegistries.ITEMS.getValue(powder); |
| 147 | + } |
| 148 | + @Override public int quantityDropped(IBlockState state, Random random) { |
| 149 | + return getItemsToDropCount(state, 0, null, BlockPos.ORIGIN, random); |
| 150 | + } |
| 151 | + @Override public int getItemsToDropCount(IBlockState state, int fortune, World world, BlockPos pos, Random random) { |
| 152 | + return powder == null ? 1 : 2 + random.nextInt(3 + fortune); |
| 153 | + } |
| 154 | + @Override public boolean isBeaconBase(IBlockState state, IWorldReader world, BlockPos pos, BlockPos beacon) { |
| 155 | + return !ore; |
| 156 | + } |
120 | 157 | @Override @OnlyIn(Dist.CLIENT) |
121 | 158 | public BlockRenderLayer getRenderLayer() { |
122 | 159 | return ore ? BlockRenderLayer.CUTOUT_MIPPED : BlockRenderLayer.SOLID; |
|
0 commit comments