Skip to content

Commit

Permalink
Oriented basalt ores (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 authored Jan 23, 2025
2 parents 446edcc + 3c895ef commit 1e01683
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider;
import net.minecraft.data.client.BlockStateModelGenerator;
import net.minecraft.data.client.ItemModelGenerator;
import net.minecraft.data.client.TexturedModel;

public class UniversalOresModelProvider extends FabricModelProvider {
public UniversalOresModelProvider(FabricDataOutput output) {
Expand All @@ -17,9 +18,8 @@ public void generateBlockStateModels(BlockStateModelGenerator gen) {
for (var ores : UniversalOresBlocks.OVERWORLD_ORE_BLOCKS) {
ores.forEach(gen::registerSimpleCubeAll);
}
for (var ores : UniversalOresBlocks.NETHER_ORE_BLOCKS) {
ores.forEach(gen::registerSimpleCubeAll);
}
UniversalOresBlocks.BLACKSTONE_ORES.forEach(gen::registerSimpleCubeAll);
UniversalOresBlocks.BASALT_ORES.forEach(block -> gen.registerAxisRotated(block, TexturedModel.CUBE_COLUMN));
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fr/hugman/universal_ores/UniversalOres.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.hugman.universal_ores;

import com.google.common.reflect.Reflection;
import fr.hugman.universal_ores.block.UniversalOresBlockTypes;
import fr.hugman.universal_ores.block.UniversalOresBlocks;
import fr.hugman.universal_ores.itemgroup.UniversalOresItemGroupAdditions;
import net.fabricmc.api.ModInitializer;
Expand All @@ -11,6 +12,7 @@ public class UniversalOres implements ModInitializer {

@Override
public void onInitialize() {
Reflection.initialize(UniversalOresBlockTypes.class);
Reflection.initialize(UniversalOresBlocks.class);
UniversalOresItemGroupAdditions.appendItemGroups();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fr.hugman.universal_ores.block;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.block.PillarBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.intprovider.IntProvider;

public class DropExperienceRotatedPillarBlock extends PillarBlock {
public static final MapCodec<DropExperienceRotatedPillarBlock> CODEC = RecordCodecBuilder.mapCodec(
instance -> instance.group(IntProvider.createValidatingCodec(0, 10).fieldOf("experience").forGetter(block -> block.experienceDropped), createSettingsCodec())
.apply(instance, DropExperienceRotatedPillarBlock::new)
);

private final IntProvider experienceDropped;

@Override
public MapCodec<? extends DropExperienceRotatedPillarBlock> getCodec() {
return CODEC;
}

public DropExperienceRotatedPillarBlock(IntProvider experienceDropped, Settings settings) {
super(settings);
this.experienceDropped = experienceDropped;
}


@Override
protected void onStacksDropped(BlockState state, ServerWorld world, BlockPos pos, ItemStack tool, boolean dropExperience) {
super.onStacksDropped(state, world, pos, tool, dropExperience);
if (dropExperience) {
this.dropExperienceWhenMined(world, pos, tool, this.experienceDropped);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.hugman.universal_ores.block;

import com.mojang.serialization.MapCodec;
import fr.hugman.universal_ores.UniversalOres;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

public class UniversalOresBlockTypes {
public static final MapCodec<DropExperienceRotatedPillarBlock> DROP_EXPERIENCE_ROTATED_PILLAR = register("drop_experience_rotated_pillar", DropExperienceRotatedPillarBlock.CODEC);

public static MapCodec<DropExperienceRotatedPillarBlock> register(String id, MapCodec<DropExperienceRotatedPillarBlock> codec) {
return Registry.register(Registries.BLOCK_TYPE, UniversalOres.id(id), codec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class UniversalOresBlocks {
private static final Function<AbstractBlock.Settings, Block> DIAMOND_ORE = s -> new ExperienceDroppingBlock(UniformIntProvider.create(3, 7), s);
private static final Function<AbstractBlock.Settings, Block> NETHER_GOLD_ORE = s -> new ExperienceDroppingBlock(UniformIntProvider.create(0, 1), s.sounds(BlockSoundGroup.NETHER_GOLD_ORE));
private static final Function<AbstractBlock.Settings, Block> QUARTZ_ORE = s -> new ExperienceDroppingBlock(UniformIntProvider.create(2, 5), s.sounds(BlockSoundGroup.NETHER_ORE));
private static final Function<AbstractBlock.Settings, Block> NETHER_GOLD_ORE_PILLAR = s -> new DropExperienceRotatedPillarBlock(UniformIntProvider.create(0, 1), s.sounds(BlockSoundGroup.NETHER_GOLD_ORE));
private static final Function<AbstractBlock.Settings, Block> QUARTZ_ORE_PILLAR = s -> new DropExperienceRotatedPillarBlock(UniformIntProvider.create(2, 5), s.sounds(BlockSoundGroup.NETHER_ORE));

private static final Supplier<AbstractBlock.Settings> GRANITE = () -> AbstractBlock.Settings.copyShallow(Blocks.GRANITE).strength(3.0F, 3.0F);
private static final Supplier<AbstractBlock.Settings> DIORITE = () -> AbstractBlock.Settings.copyShallow(Blocks.DIORITE).strength(3.0F, 3.0F);
Expand All @@ -41,7 +43,7 @@ public class UniversalOresBlocks {
public static final OverworldOreBlocks TUFF_ORES = registerOverworldOres("tuff", TUFF);
public static final OverworldOreBlocks CALCITE_ORES = registerOverworldOres("calcite", CALCITE);
public static final NetherOreBlocks BLACKSTONE_ORES = registerNetherOres("blackstone", BLACKSTONE);
public static final NetherOreBlocks BASALT_ORES = registerNetherOres("basalt", BASALT);
public static final NetherOreBlocks BASALT_ORES = registerNetherPillarOres("basalt", BASALT);

public static final OverworldOreBlocks[] OVERWORLD_ORE_BLOCKS = new OverworldOreBlocks[]{GRANITE_ORES, DIORITE_ORES, ANDESITE_ORES, TUFF_ORES, CALCITE_ORES};
public static final NetherOreBlocks[] NETHER_ORE_BLOCKS = new NetherOreBlocks[]{BLACKSTONE_ORES, BASALT_ORES};
Expand Down Expand Up @@ -79,6 +81,13 @@ private static NetherOreBlocks registerNetherOres(String prefix, Supplier<Abstra
);
}

private static NetherOreBlocks registerNetherPillarOres(String prefix, Supplier<AbstractBlock.Settings> settingsSupplier) {
return new NetherOreBlocks(
register(prefix + "_gold_ore", NETHER_GOLD_ORE_PILLAR, settingsSupplier),
register(prefix + "_quartz_ore", QUARTZ_ORE_PILLAR, settingsSupplier)
);
}

private static Block register(String key, Function<AbstractBlock.Settings, Block> factory, Supplier<AbstractBlock.Settings> supplier) {
return register(keyOf(key), factory, supplier.get());
}
Expand Down

0 comments on commit 1e01683

Please sign in to comment.