From 786d2210378b26350818ad01824c5b64b2dcbf21 Mon Sep 17 00:00:00 2001 From: Cjsah <2684117397@qq.com> Date: Wed, 26 Jan 2022 07:52:55 +0800 Subject: [PATCH] update --- src/generated/resources/.cache/cache | 7 +- .../data/ironstars/dimension/moon.json | 5 +- .../data/ironstars/worldgen/biome/moon.json | 44 +++++++ .../configured_feature/ore_titanium.json | 18 +++ .../noise_settings/moon_noise_config.json | 12 -- .../worldgen/placed_feature/ore_titanium.json | 24 ++++ .../java/com/xekr/ironstars/IronStars.java | 4 + .../CopperPressurePlateBlockEntity.java | 2 +- .../TitaniumPressurePlateBlockEntity.java | 2 +- .../xekr/ironstars/mixin/ItemEntityMixin.java | 2 +- .../ironstars/mixin/LightingBoltMixin.java | 2 +- .../xekr/ironstars/registry/AllBiomes.java | 53 ++++++--- .../ironstars/registry/AllBlockEntities.java | 16 ++- .../xekr/ironstars/registry/AllBlocks.java | 75 ++++++------ .../ironstars/registry/AllDimensions.java | 4 +- .../xekr/ironstars/registry/AllEvents.java | 32 ++--- .../xekr/ironstars/registry/AllFeatures.java | 37 ++++++ .../xekr/ironstars/registry/AllFluids.java | 52 +++++---- .../com/xekr/ironstars/registry/AllItems.java | 109 +++++++++--------- .../xekr/ironstars/registry/AllSounds.java | 23 ++++ .../xekr/ironstars/world/MoonBiomeSource.java | 60 ++++++---- .../ironstars/world/MoonWorldGenerator.java | 8 +- 22 files changed, 394 insertions(+), 197 deletions(-) create mode 100644 src/generated/resources/data/ironstars/worldgen/biome/moon.json create mode 100644 src/generated/resources/data/ironstars/worldgen/configured_feature/ore_titanium.json create mode 100644 src/generated/resources/data/ironstars/worldgen/placed_feature/ore_titanium.json create mode 100644 src/main/java/com/xekr/ironstars/registry/AllFeatures.java create mode 100644 src/main/java/com/xekr/ironstars/registry/AllSounds.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index b9f9b69..1cba8b8 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -1,3 +1,6 @@ -08e56a0290a7b2bcb59afbb499abe59edef73925 data/ironstars/dimension/moon.json +59861de0d06510e486a1f004f62c6f4367e5a3ec data/ironstars/dimension/moon.json a0bb608ed4bc527c91941856da1791896ec1c016 data/ironstars/dimension_type/moon_type.json -64dab7c693513ddd3c9e48c4f485ec5076fd8944 data/ironstars/worldgen/noise_settings/moon_noise_config.json +1d8cb64db20e84954cb026351766d8325e3646d8 data/ironstars/worldgen/biome/moon.json +690ed9183cdfa4cf1fe0e330b220d6d1fc12280a data/ironstars/worldgen/configured_feature/ore_titanium.json +ffecdcf1d9f0a8b179faae56652399378acd6f67 data/ironstars/worldgen/noise_settings/moon_noise_config.json +051c1b700adc74692b778b4d5d2f61c2e8574096 data/ironstars/worldgen/placed_feature/ore_titanium.json diff --git a/src/generated/resources/data/ironstars/dimension/moon.json b/src/generated/resources/data/ironstars/dimension/moon.json index d276b2e..a274a25 100644 --- a/src/generated/resources/data/ironstars/dimension/moon.json +++ b/src/generated/resources/data/ironstars/dimension/moon.json @@ -3,12 +3,13 @@ "generator": { "wrapped_generator": { "biome_source": { - "type": "ironstars:ironstars_biomes" + "biome": "ironstars:moon", + "type": "ironstars:moon_biome_source" }, "seed": 0, "settings": "ironstars:moon_noise_config", "type": "minecraft:noise" }, - "type": "ironstars:structure_locating_wrapper" + "type": "ironstars:moon_generator" } } \ No newline at end of file diff --git a/src/generated/resources/data/ironstars/worldgen/biome/moon.json b/src/generated/resources/data/ironstars/worldgen/biome/moon.json new file mode 100644 index 0000000..38d5662 --- /dev/null +++ b/src/generated/resources/data/ironstars/worldgen/biome/moon.json @@ -0,0 +1,44 @@ +{ + "carvers": {}, + "features": [ + [], + [], + [], + [], + [], + [], + [ + "ironstars:ore_titanium" + ] + ], + "spawners": { + "monster": [], + "creature": [], + "ambient": [], + "axolotls": [], + "underground_water_creature": [], + "water_creature": [], + "water_ambient": [], + "misc": [] + }, + "spawn_costs": {}, + "forge:registry_name": "ironstars:moon", + "precipitation": "none", + "temperature": -0.5, + "downfall": 0.4, + "category": "none", + "effects": { + "mood_sound": { + "sound": "ironstars:deep_space", + "tick_delay": 6000, + "block_search_extent": 8, + "offset": 2.0 + }, + "sky_color": 0, + "foliage_color": 12303291, + "grass_color": 12303291, + "fog_color": 12303291, + "water_color": 12303291, + "water_fog_color": 12303291 + } +} \ No newline at end of file diff --git a/src/generated/resources/data/ironstars/worldgen/configured_feature/ore_titanium.json b/src/generated/resources/data/ironstars/worldgen/configured_feature/ore_titanium.json new file mode 100644 index 0000000..ba2158f --- /dev/null +++ b/src/generated/resources/data/ironstars/worldgen/configured_feature/ore_titanium.json @@ -0,0 +1,18 @@ +{ + "config": { + "targets": [ + { + "target": { + "block": "ironstars:moon_rock", + "predicate_type": "minecraft:block_match" + }, + "state": { + "Name": "ironstars:titanium_ore" + } + } + ], + "size": 10, + "discard_chance_on_air_exposure": 0.0 + }, + "type": "minecraft:ore" +} \ No newline at end of file diff --git a/src/generated/resources/data/ironstars/worldgen/noise_settings/moon_noise_config.json b/src/generated/resources/data/ironstars/worldgen/noise_settings/moon_noise_config.json index 7fb87e6..be04b75 100644 --- a/src/generated/resources/data/ironstars/worldgen/noise_settings/moon_noise_config.json +++ b/src/generated/resources/data/ironstars/worldgen/noise_settings/moon_noise_config.json @@ -31,18 +31,6 @@ "type": "minecraft:block" }, "type": "minecraft:condition" - }, - { - "if_true": { - "type": "minecraft:above_preliminary_surface" - }, - "then_run": { - "result_state": { - "Name": "ironstars:moon_soil" - }, - "type": "minecraft:block" - }, - "type": "minecraft:condition" } ], "type": "minecraft:sequence" diff --git a/src/generated/resources/data/ironstars/worldgen/placed_feature/ore_titanium.json b/src/generated/resources/data/ironstars/worldgen/placed_feature/ore_titanium.json new file mode 100644 index 0000000..d261492 --- /dev/null +++ b/src/generated/resources/data/ironstars/worldgen/placed_feature/ore_titanium.json @@ -0,0 +1,24 @@ +{ + "feature": "ironstars:ore_titanium", + "placement": [ + { + "count": 16, + "type": "minecraft:count" + }, + { + "type": "minecraft:in_square" + }, + { + "height": { + "min_inclusive": { + "above_bottom": 0 + }, + "max_inclusive": { + "above_bottom": 112 + }, + "type": "minecraft:trapezoid" + }, + "type": "minecraft:height_range" + } + ] +} \ No newline at end of file diff --git a/src/main/java/com/xekr/ironstars/IronStars.java b/src/main/java/com/xekr/ironstars/IronStars.java index 6411ec4..333199d 100644 --- a/src/main/java/com/xekr/ironstars/IronStars.java +++ b/src/main/java/com/xekr/ironstars/IronStars.java @@ -6,8 +6,10 @@ import com.xekr.ironstars.registry.AllBlockEntities; import com.xekr.ironstars.registry.AllCapabilities; import com.xekr.ironstars.registry.AllDimensions; +import com.xekr.ironstars.registry.AllFeatures; import com.xekr.ironstars.registry.AllFluids; import com.xekr.ironstars.registry.AllItems; +import com.xekr.ironstars.registry.AllSounds; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; @@ -26,10 +28,12 @@ public class IronStars { public IronStars() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(AllCapabilities::register); + AllSounds.register(bus); AllBlocks.register(bus); AllBlockEntities.register(bus); AllItems.register(bus); AllFluids.register(bus); + AllFeatures.register(); AllBiomes.register(bus); AllDimensions.init(); AnvilRecipeTypes.init(); diff --git a/src/main/java/com/xekr/ironstars/blocks/entity/CopperPressurePlateBlockEntity.java b/src/main/java/com/xekr/ironstars/blocks/entity/CopperPressurePlateBlockEntity.java index bfa13a9..6bad84c 100644 --- a/src/main/java/com/xekr/ironstars/blocks/entity/CopperPressurePlateBlockEntity.java +++ b/src/main/java/com/xekr/ironstars/blocks/entity/CopperPressurePlateBlockEntity.java @@ -12,7 +12,7 @@ public class CopperPressurePlateBlockEntity extends BlockEntity { private long times; public CopperPressurePlateBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) { - super(AllBlockEntities.COPPER_PRESSURE_PLATE.get(), pWorldPosition, pBlockState); + super(AllBlockEntities.COPPER_PRESSURE_PLATE, pWorldPosition, pBlockState); } public void tick() { diff --git a/src/main/java/com/xekr/ironstars/blocks/entity/TitaniumPressurePlateBlockEntity.java b/src/main/java/com/xekr/ironstars/blocks/entity/TitaniumPressurePlateBlockEntity.java index b1abc45..1ab3791 100644 --- a/src/main/java/com/xekr/ironstars/blocks/entity/TitaniumPressurePlateBlockEntity.java +++ b/src/main/java/com/xekr/ironstars/blocks/entity/TitaniumPressurePlateBlockEntity.java @@ -13,7 +13,7 @@ public class TitaniumPressurePlateBlockEntity extends BlockEntity { private long times; public TitaniumPressurePlateBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) { - super(AllBlockEntities.TITANIUM_PRESSURE_PLATE.get(), pWorldPosition, pBlockState); + super(AllBlockEntities.TITANIUM_PRESSURE_PLATE, pWorldPosition, pBlockState); } public void tick() { diff --git a/src/main/java/com/xekr/ironstars/mixin/ItemEntityMixin.java b/src/main/java/com/xekr/ironstars/mixin/ItemEntityMixin.java index 4d3aea1..c61b18e 100644 --- a/src/main/java/com/xekr/ironstars/mixin/ItemEntityMixin.java +++ b/src/main/java/com/xekr/ironstars/mixin/ItemEntityMixin.java @@ -16,7 +16,7 @@ public class ItemEntityMixin { @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;add(DDD)Lnet/minecraft/world/phys/Vec3;")) private Vec3 slowDown(Vec3 instance, double pX, double pY, double pZ) { ItemEntity ths = (ItemEntity) (Object) this; - if (ths.level.getBlockState(ths.blockPosition()).is(AllBlocks.MAGNET_BLOCK.get())) pY /= IronStarsConfig.ItemInMagnetGravy; + if (ths.level.getBlockState(ths.blockPosition()).is(AllBlocks.MAGNET_BLOCK)) pY /= IronStarsConfig.ItemInMagnetGravy; return instance.add(pX, pY, pZ); } diff --git a/src/main/java/com/xekr/ironstars/mixin/LightingBoltMixin.java b/src/main/java/com/xekr/ironstars/mixin/LightingBoltMixin.java index dca303e..a7e95b4 100644 --- a/src/main/java/com/xekr/ironstars/mixin/LightingBoltMixin.java +++ b/src/main/java/com/xekr/ironstars/mixin/LightingBoltMixin.java @@ -21,7 +21,7 @@ private static void toMagnet(Level world, BlockPos pos, CallbackInfo ci, BlockSt BlockState blockState = world.getBlockState(targetPos); if (!blockState.is(Blocks.IRON_BLOCK)) break; - world.setBlockAndUpdate(targetPos, AllBlocks.MAGNET_BLOCK.get().defaultBlockState()); + world.setBlockAndUpdate(targetPos, AllBlocks.MAGNET_BLOCK.defaultBlockState()); targetPos = targetPos.relative(Direction.DOWN); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllBiomes.java b/src/main/java/com/xekr/ironstars/registry/AllBiomes.java index e73b862..0c072a6 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllBiomes.java +++ b/src/main/java/com/xekr/ironstars/registry/AllBiomes.java @@ -1,36 +1,55 @@ package com.xekr.ironstars.registry; import com.xekr.ironstars.IronStars; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.AmbientMoodSettings; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeGenerationSettings; import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; +import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class AllBiomes { - private static final DeferredRegister BIOMES = DeferredRegister.create(ForgeRegistries.BIOMES, IronStars.ID); + private static final DeferredRegister REGISTRY = DeferredRegister.create(ForgeRegistries.BIOMES, IronStars.ID); -// public static final ResourceKey MOON = registerBiome("moon"); + public static final Biome MOON = registerBiome("moon", builder -> builder + .precipitation(Biome.Precipitation.NONE) + .biomeCategory(Biome.BiomeCategory.NONE) + .temperature(-0.5f) + .temperatureAdjustment(Biome.TemperatureModifier.NONE) + .downfall(0.4f) + .specialEffects(new BiomeSpecialEffects.Builder() + .skyColor(0) + .fogColor(12303291) + .waterColor(12303291) + .waterFogColor(12303291) + .grassColorOverride(12303291) + .foliageColorOverride(12303291) + .ambientMoodSound(new AmbientMoodSettings(AllSounds.DEEP_SPACE, 6000, 8, 2.0f)) + .build()) + .generationSettings(new BiomeGenerationSettings.Builder().addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, AllFeatures.PLACED_TITANIUM_ORE).build()) + .mobSpawnSettings(new MobSpawnSettings.Builder().build()) + ); - private static ResourceKey registerBiome(String name) { - BIOMES.register(name, () -> new Biome.BiomeBuilder() - .precipitation(Biome.Precipitation.NONE) - .biomeCategory(Biome.BiomeCategory.NONE) - .downfall(0) - .temperature(0) - .specialEffects(new BiomeSpecialEffects.Builder().fogColor(0).waterColor(0).waterFogColor(0).skyColor(0).build()) - .generationSettings(new BiomeGenerationSettings.Builder().build()) - .mobSpawnSettings(new MobSpawnSettings.Builder().build()) - .temperatureAdjustment(Biome.TemperatureModifier.NONE) - .build()); - return ResourceKey.create(Registry.BIOME_REGISTRY, IronStars.id(name)); + private static Biome registerBiome(String name, ReturnSelfConsumer consumer) { + Biome biome = consumer.accept(new Biome.BiomeBuilder()).build(); + REGISTRY.register(name, () -> biome); + return biome; + } + + @FunctionalInterface + interface ReturnSelfConsumer { + void block(T t); + + default T accept(T t) { + block(t); + return t; + } } public static void register(IEventBus bus) { - BIOMES.register(bus); + REGISTRY.register(bus); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllBlockEntities.java b/src/main/java/com/xekr/ironstars/registry/AllBlockEntities.java index f4128d4..c2923f5 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllBlockEntities.java +++ b/src/main/java/com/xekr/ironstars/registry/AllBlockEntities.java @@ -3,6 +3,8 @@ import com.xekr.ironstars.IronStars; import com.xekr.ironstars.blocks.entity.CopperPressurePlateBlockEntity; import com.xekr.ironstars.blocks.entity.TitaniumPressurePlateBlockEntity; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; @@ -11,13 +13,19 @@ @SuppressWarnings("ConstantConditions") public class AllBlockEntities { - private static final DeferredRegister> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, IronStars.ID); + private static final DeferredRegister> REGISTRY = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, IronStars.ID); - public static final RegistryObject> COPPER_PRESSURE_PLATE = BLOCK_ENTITIES.register("copper_pressure_plate", () -> BlockEntityType.Builder.of(CopperPressurePlateBlockEntity::new, AllBlocks.COPPER_PRESSURE_PLATE.get()).build(null)); - public static final RegistryObject> TITANIUM_PRESSURE_PLATE = BLOCK_ENTITIES.register("titanium_pressure_plate", () -> BlockEntityType.Builder.of(TitaniumPressurePlateBlockEntity::new, AllBlocks.TITANIUM_PRESSURE_PLATE.get()).build(null)); + public static final BlockEntityType COPPER_PRESSURE_PLATE = register("copper_pressure_plate", CopperPressurePlateBlockEntity::new, AllBlocks.COPPER_PRESSURE_PLATE); + public static final BlockEntityType TITANIUM_PRESSURE_PLATE = register("titanium_pressure_plate", TitaniumPressurePlateBlockEntity::new, AllBlocks.TITANIUM_PRESSURE_PLATE); + private static BlockEntityType register(String name, BlockEntityType.BlockEntitySupplier pFactory, Block... pValidBlocks) { + BlockEntityType blockEntityType = BlockEntityType.Builder.of(pFactory, pValidBlocks).build(null); + REGISTRY.register(name, () -> blockEntityType); + return blockEntityType; + } + public static void register(IEventBus bus) { - BLOCK_ENTITIES.register(bus); + REGISTRY.register(bus); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllBlocks.java b/src/main/java/com/xekr/ironstars/registry/AllBlocks.java index 0d09216..3cf201a 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllBlocks.java +++ b/src/main/java/com/xekr/ironstars/registry/AllBlocks.java @@ -2,7 +2,6 @@ import com.xekr.ironstars.blocks.*; import com.xekr.ironstars.IronStars; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockBehaviour.Properties; @@ -10,53 +9,52 @@ import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; import static net.minecraft.world.level.block.Blocks.TRIPWIRE_HOOK; public class AllBlocks { - private static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, IronStars.ID); + private static final DeferredRegister REGISTRY = DeferredRegister.create(ForgeRegistries.BLOCKS, IronStars.ID); //base - public static final RegistryObject ACCELERATOR = BLOCKS.register("accelerator", () -> new Block(defaultProperties().noOcclusion())); - public static final RegistryObject CENTRIFUGE = BLOCKS.register("centrifuge", () -> new Block(defaultProperties().noOcclusion())); - public static final RegistryObject CHEMICAL_ACCUMULATOR = BLOCKS.register("chemical_accumulator", () -> new Block(defaultProperties().noOcclusion())); - public static final RegistryObject COIL = BLOCKS.register("coil", () -> new CoilBlock(defaultProperties().noOcclusion())); - public static final RegistryObject COPPER_TRIPWIRE = BLOCKS.register("copper_tripwire", () -> new CopperTripWireBlock((TripWireHookBlock)TRIPWIRE_HOOK, BlockBehaviour.Properties.of(Material.DECORATION).noCollission()));; -// public static final RegistryObject ELECTRIC_WIRE = BLOCKS.register("electric_wire", () -> new ElectricWireBlock(getProperties())); // TODO:报错太多暂时删掉 - public static final RegistryObject INTERACTOR = BLOCKS.register("interactor", () -> new Block(defaultProperties().noOcclusion())); - public static final RegistryObject ITEM_RAIL = BLOCKS.register("item_rail", () -> new Block(defaultProperties().noOcclusion())); - public static final RegistryObject MOTOR = BLOCKS.register("motor", () -> new MotorBlock(defaultProperties().noOcclusion(), false)); - public static final RegistryObject MOTOR_LAY = BLOCKS.register("motor_lay", () -> new MotorBlock(defaultProperties().noOcclusion(), true)); - public static final RegistryObject TURBINE = BLOCKS.register("turbine", () -> new Block(defaultProperties().noOcclusion())); - public static final RegistryObject WINDMILL = BLOCKS.register("windmill", () -> new Block(defaultProperties().noOcclusion())); - public static final RegistryObject COPPER_PRESSURE_PLATE = BLOCKS.register("copper_pressure_plate", () -> new CopperPressurePlateBlock(defaultProperties().strength(0.5F).noCollission())); - public static final RegistryObject TITANIUM_PRESSURE_PLATE = BLOCKS.register("titanium_pressure_plate", () -> new TitaniumPressurePlateBlock(defaultProperties().strength(0.5F).noCollission())); - public static final RegistryObject STEEL_PRESSURE_PLATE = BLOCKS.register("steel_pressure_plate", () -> new SteelPressurePlateBlock(defaultProperties().strength(0.5F).noCollission())); - public static final RegistryObject NETHERITE_PRESSURE_PLATE = BLOCKS.register("netherite_pressure_plate", () -> new NetheritePressurePlateBlock(defaultProperties().noCollission())); - public static final RegistryObject TITANIUM_ALLOY_PRESSURE_PLATE = BLOCKS.register("titanium_alloy_pressure_plate", () -> new TitaniumAlloyPressurePlateBlock(defaultProperties().noCollission())); - public static final RegistryObject TUNGSTEN_PRESSURE_PLATE = BLOCKS.register("tungsten_pressure_plate", () -> new TungstenPressurePlateBlock(defaultProperties().strength(0.5F).noCollission())); - public static final RegistryObject MAGNET_BLOCK = BLOCKS.register("magnet_block", () -> new MagnetBlock(defaultProperties().explosionResistance(6.0F).noOcclusion())); - public static final RegistryObject SILICON_BLOCK = BLOCKS.register("silicon_block", () -> new Block(defaultProperties())); - public static final RegistryObject STEEL_BLOCK = BLOCKS.register("steel_block", () -> new Block(defaultProperties())); - public static final RegistryObject TITANIUM_ALLOY_BLOCK = BLOCKS.register("titanium_alloy_block", () -> new Block(defaultProperties())); - public static final RegistryObject TITANIUM_BLOCK = BLOCKS.register("titanium_block", () -> new Block(defaultProperties())); + public static final Block ACCELERATOR = register("accelerator", new Block(defaultProperties().noOcclusion())); + public static final Block CENTRIFUGE = register("centrifuge", new Block(defaultProperties().noOcclusion())); + public static final Block CHEMICAL_ACCUMULATOR = register("chemical_accumulator", new Block(defaultProperties().noOcclusion())); + public static final Block COIL = register("coil", new CoilBlock(defaultProperties().noOcclusion())); + public static final Block COPPER_TRIPWIRE = register("copper_tripwire", new CopperTripWireBlock((TripWireHookBlock)TRIPWIRE_HOOK, BlockBehaviour.Properties.of(Material.DECORATION).noCollission())); +// public static final Block ELECTRIC_WIRE = register("electric_wire", new ElectricWireBlock(getProperties())); // TODO:报错太多暂时删掉 + public static final Block INTERACTOR = register("interactor", new Block(defaultProperties().noOcclusion())); + public static final Block ITEM_RAIL = register("item_rail", new Block(defaultProperties().noOcclusion())); + public static final Block MOTOR = register("motor", new MotorBlock(defaultProperties().noOcclusion(), false)); + public static final Block MOTOR_LAY = register("motor_lay", new MotorBlock(defaultProperties().noOcclusion(), true)); + public static final Block TURBINE = register("turbine", new Block(defaultProperties().noOcclusion())); + public static final Block WINDMILL = register("windmill", new Block(defaultProperties().noOcclusion())); + public static final Block COPPER_PRESSURE_PLATE = register("copper_pressure_plate", new CopperPressurePlateBlock(defaultProperties().strength(0.5F).noCollission())); + public static final Block TITANIUM_PRESSURE_PLATE = register("titanium_pressure_plate", new TitaniumPressurePlateBlock(defaultProperties().strength(0.5F).noCollission())); + public static final Block STEEL_PRESSURE_PLATE = register("steel_pressure_plate", new SteelPressurePlateBlock(defaultProperties().strength(0.5F).noCollission())); + public static final Block NETHERITE_PRESSURE_PLATE = register("netherite_pressure_plate", new NetheritePressurePlateBlock(defaultProperties().noCollission())); + public static final Block TITANIUM_ALLOY_PRESSURE_PLATE = register("titanium_alloy_pressure_plate", new TitaniumAlloyPressurePlateBlock(defaultProperties().noCollission())); + public static final Block TUNGSTEN_PRESSURE_PLATE = register("tungsten_pressure_plate", new TungstenPressurePlateBlock(defaultProperties().strength(0.5F).noCollission())); + public static final Block MAGNET_BLOCK = register("magnet_block", new MagnetBlock(defaultProperties().explosionResistance(6.0F).noOcclusion())); + public static final Block SILICON_BLOCK = register("silicon_block", new Block(defaultProperties())); + public static final Block STEEL_BLOCK = register("steel_block", new Block(defaultProperties())); + public static final Block TITANIUM_ALLOY_BLOCK = register("titanium_alloy_block", new Block(defaultProperties())); + public static final Block TITANIUM_BLOCK = register("titanium_block", new Block(defaultProperties())); - public static final RegistryObject ACID = BLOCKS.register("acid", () -> new LiquidBlock(AllFluids.ACID_FLUID, liquidProperties())); - public static final RegistryObject REDSTONE = BLOCKS.register("redstone", () -> new LiquidBlock(AllFluids.REDSTONE_FLUID, liquidProperties())); - public static final RegistryObject FUSION_FUEL = BLOCKS.register("fusion_fuel", () -> new LiquidBlock(AllFluids.FUSION_FUEL_FLUID, liquidProperties())); + public static final LiquidBlock ACID = register("acid", new LiquidBlock(AllFluids.ACID_FLUID, liquidProperties())); + public static final LiquidBlock REDSTONE = register("redstone", new LiquidBlock(AllFluids.REDSTONE_FLUID, liquidProperties())); + public static final LiquidBlock FUSION_FUEL = register("fusion_fuel", new LiquidBlock(AllFluids.FUSION_FUEL_FLUID, liquidProperties())); //deco - public static final RegistryObject STEEL_TILES = BLOCKS.register("steel_tiles", () -> new Block(defaultProperties(Material.STONE).sound(SoundType.STONE))); - public static final RegistryObject FISH_TANK = BLOCKS.register("fish_tank", () -> new FishTankBlock(defaultProperties().noOcclusion())); + public static final Block STEEL_TILES = register("steel_tiles", new Block(defaultProperties(Material.STONE).sound(SoundType.STONE))); + public static final Block FISH_TANK = register("fish_tank", new FishTankBlock(defaultProperties().noOcclusion())); //ship //alien - public static final RegistryObject MOON_DUST = BLOCKS.register("moon_dust", () -> new MoonDustBlock(defaultProperties(Material.CLAY).sound(SoundType.SAND).noOcclusion())); - public static final RegistryObject MOON_ROCK = BLOCKS.register("moon_rock", () -> new Block(defaultProperties().sound(SoundType.STONE))); - public static final RegistryObject MOON_SOIL = BLOCKS.register("moon_soil", () -> new Block(defaultProperties(Material.CLAY).sound(SoundType.ROOTS))); - public static final RegistryObject TITANIUM_ORE = BLOCKS.register("titanium_ore", () -> new Block(defaultProperties(Material.STONE).sound(SoundType.STONE))); + public static final Block MOON_DUST = register("moon_dust", new MoonDustBlock(defaultProperties(Material.CLAY).sound(SoundType.SAND).noOcclusion())); + public static final Block MOON_ROCK = register("moon_rock", new Block(defaultProperties().sound(SoundType.STONE))); + public static final Block MOON_SOIL = register("moon_soil", new Block(defaultProperties(Material.CLAY).sound(SoundType.ROOTS))); + public static final Block TITANIUM_ORE = register("titanium_ore", new Block(defaultProperties(Material.STONE).sound(SoundType.STONE))); private static Properties defaultProperties() { return defaultProperties(Material.METAL); @@ -70,7 +68,12 @@ private static Properties liquidProperties() { return Properties.of(Material.WATER).noCollission().strength(100.0F).noDrops(); } + private static T register(String name, T block) { + REGISTRY.register(name, () -> block); + return block; + } + public static void register(IEventBus bus) { - BLOCKS.register(bus); + REGISTRY.register(bus); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllDimensions.java b/src/main/java/com/xekr/ironstars/registry/AllDimensions.java index 0565dbb..3097807 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllDimensions.java +++ b/src/main/java/com/xekr/ironstars/registry/AllDimensions.java @@ -8,9 +8,9 @@ public class AllDimensions { public static long seed; public static void init() { - Registry.register(Registry.BIOME_SOURCE, IronStars.id("ironstars_biomes"), MoonBiomeSource.CODEC); + Registry.register(Registry.BIOME_SOURCE, IronStars.id("moon_biome_source"), MoonBiomeSource.CODEC); - Registry.register(Registry.CHUNK_GENERATOR, IronStars.id("structure_locating_wrapper"), MoonChunkGenerator.CODEC); + Registry.register(Registry.CHUNK_GENERATOR, IronStars.id("moon_generator"), MoonChunkGenerator.CODEC); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllEvents.java b/src/main/java/com/xekr/ironstars/registry/AllEvents.java index e3dcf77..9f101e1 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllEvents.java +++ b/src/main/java/com/xekr/ironstars/registry/AllEvents.java @@ -8,7 +8,6 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.data.DataGenerator; import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -27,9 +26,8 @@ public static void onCommandRegister(RegisterCommandsEvent event) { @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) static class ModBusGlobal { // mod管线全局事件 @SubscribeEvent - public static void gatherData(GatherDataEvent event) { //TODO 不好使 + public static void gatherData(GatherDataEvent event) { DataGenerator generator = event.getGenerator(); - ExistingFileHelper helper = event.getExistingFileHelper(); generator.addProvider(new MoonWorldGenerator(generator)); } } @@ -37,24 +35,26 @@ public static void gatherData(GatherDataEvent event) { //TODO 不好使 static class ModBusClient { // mod管线客户端事件 @SubscribeEvent public static void onRenderTypeSetup(FMLClientSetupEvent event) { - ItemBlockRenderTypes.setRenderLayer(AllBlocks.ACCELERATOR.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.CENTRIFUGE.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.CHEMICAL_ACCUMULATOR.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.FISH_TANK.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.INTERACTOR.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.ITEM_RAIL.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.MOON_DUST.get(), RenderType.cutout()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.MAGNET_BLOCK.get(), RenderType.cutout()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.MOTOR.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.MOTOR_LAY.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.TURBINE.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.WINDMILL.get(), RenderType.cutoutMipped()); - ItemBlockRenderTypes.setRenderLayer(AllBlocks.COPPER_TRIPWIRE.get(), RenderType.translucentMovingBlock()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.ACCELERATOR, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.CENTRIFUGE, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.CHEMICAL_ACCUMULATOR, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.FISH_TANK, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.INTERACTOR, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.ITEM_RAIL, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.MOON_DUST, RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.MAGNET_BLOCK, RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.MOTOR, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.MOTOR_LAY, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.TURBINE, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.WINDMILL, RenderType.cutoutMipped()); + ItemBlockRenderTypes.setRenderLayer(AllBlocks.COPPER_TRIPWIRE, RenderType.translucentMovingBlock()); // Fluids ItemBlockRenderTypes.setRenderLayer(AllFluids.ACID_FLUID.get(), RenderType.translucent()); ItemBlockRenderTypes.setRenderLayer(AllFluids.ACID_FLUID_FLOWING.get(), RenderType.translucent()); ItemBlockRenderTypes.setRenderLayer(AllFluids.REDSTONE_FLUID.get(), RenderType.translucent()); ItemBlockRenderTypes.setRenderLayer(AllFluids.REDSTONE_FLUID_FLOWING.get(), RenderType.translucent()); + ItemBlockRenderTypes.setRenderLayer(AllFluids.FUSION_FUEL_FLUID.get(), RenderType.translucent()); + ItemBlockRenderTypes.setRenderLayer(AllFluids.FUSION_FUEL_FLUID_FLOWING.get(), RenderType.translucent()); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllFeatures.java b/src/main/java/com/xekr/ironstars/registry/AllFeatures.java new file mode 100644 index 0000000..6526002 --- /dev/null +++ b/src/main/java/com/xekr/ironstars/registry/AllFeatures.java @@ -0,0 +1,37 @@ +package com.xekr.ironstars.registry; + +import com.xekr.ironstars.IronStars; +import net.minecraft.core.Registry; +import net.minecraft.data.BuiltinRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.VerticalAnchor; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; +import net.minecraft.world.level.levelgen.placement.CountPlacement; +import net.minecraft.world.level.levelgen.placement.HeightRangePlacement; +import net.minecraft.world.level.levelgen.placement.InSquarePlacement; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest; +import net.minecraft.world.level.levelgen.structure.templatesystem.RuleTest; + +import java.util.List; + +public class AllFeatures { + private static final RuleTest MOON_ORE_REPLACEABLES = new BlockMatchTest(AllBlocks.MOON_ROCK); + private static final List ORE_TITANIUM_TARGET_LIST = List.of(OreConfiguration.target(MOON_ORE_REPLACEABLES, AllBlocks.TITANIUM_ORE.defaultBlockState())); + + public static final ConfiguredFeature TITANIUM_ORE = registerConfiguredFeature(IronStars.id("ore_titanium"), Feature.ORE.configured(new OreConfiguration(ORE_TITANIUM_TARGET_LIST, 10))); + public static final PlacedFeature PLACED_TITANIUM_ORE = registerPlacedFeature(IronStars.id("ore_titanium"), TITANIUM_ORE.placed(List.of(CountPlacement.of(16), InSquarePlacement.spread(), HeightRangePlacement.triangle(VerticalAnchor.aboveBottom(0), VerticalAnchor.aboveBottom(112))))); + + + private static > T registerConfiguredFeature(ResourceLocation id, T feature) { + return Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, feature); + } + + private static PlacedFeature registerPlacedFeature(ResourceLocation id, PlacedFeature feature) { + return Registry.register(BuiltinRegistries.PLACED_FEATURE, id, feature); + } + + public static void register() {} +} diff --git a/src/main/java/com/xekr/ironstars/registry/AllFluids.java b/src/main/java/com/xekr/ironstars/registry/AllFluids.java index 68e2fe5..5d02873 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllFluids.java +++ b/src/main/java/com/xekr/ironstars/registry/AllFluids.java @@ -1,38 +1,48 @@ package com.xekr.ironstars.registry; import com.xekr.ironstars.IronStars; -import com.xekr.ironstars.fluids.NormalFluid; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.material.Fluid; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fluids.FluidAttributes; +import net.minecraftforge.fluids.ForgeFlowingFluid; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; +import java.util.function.Supplier; + public class AllFluids { - public static final ResourceLocation ACID_TEXTURE = new ResourceLocation("block/water_still"); - public static final ResourceLocation FLOWING_ACID_TEXTURE = new ResourceLocation("block/water_flow"); - public static final ResourceLocation REDSTONE_TEXTURE = new ResourceLocation("block/lava_still"); - public static final ResourceLocation FLOWING_REDSTONE_TEXTURE = new ResourceLocation("block/lava_flow"); - public static final ResourceLocation FUSION_FUEL_TEXTURE = new ResourceLocation("block/lava_still"); - public static final ResourceLocation FLOWING_FUSION_FUEL_TEXTURE = new ResourceLocation("block/lava_flow"); - - public static final DeferredRegister FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, IronStars.ID); - - public static RegistryObject ACID_FLUID = FLUIDS.register("acid_fluid", () -> new NormalFluid.Source(AllFluids.acidPROPERTIES)); - public static RegistryObject ACID_FLUID_FLOWING = FLUIDS.register("acid_fluid_flowing", () -> new NormalFluid.Flowing(AllFluids.acidPROPERTIES)); - public static RegistryObject REDSTONE_FLUID = FLUIDS.register("redstone_fluid", () -> new NormalFluid.Source(AllFluids.redPROPERTIES)); - public static RegistryObject REDSTONE_FLUID_FLOWING = FLUIDS.register("redstone_fluid_flowing", () -> new NormalFluid.Flowing(AllFluids.redPROPERTIES)); - public static RegistryObject FUSION_FUEL_FLUID = FLUIDS.register("fusion_fuel_fluid", () -> new NormalFluid.Source(AllFluids.ffPROPERTIES)); - public static RegistryObject FUSION_FUEL_FLUID_FLOWING = FLUIDS.register("fusion_fuel_fluid_flowing", () -> new NormalFluid.Flowing(AllFluids.ffPROPERTIES)); - - public static NormalFluid.Properties acidPROPERTIES = new NormalFluid.Properties(ACID_FLUID, ACID_FLUID_FLOWING, FluidAttributes.builder(ACID_TEXTURE, FLOWING_ACID_TEXTURE).color(0xAAa5d439).density(4000).viscosity(4000)).bucket(AllItems.ACID_BUCKET).block(AllBlocks.ACID).slopeFindDistance(3).explosionResistance(100F); - public static NormalFluid.Properties redPROPERTIES = new NormalFluid.Properties(REDSTONE_FLUID, REDSTONE_FLUID_FLOWING, FluidAttributes.builder(REDSTONE_TEXTURE, FLOWING_REDSTONE_TEXTURE).color(0xBBdc143c).density(4000).viscosity(4000)).bucket(AllItems.REDSTONE_BUCKET).block(AllBlocks.REDSTONE).slopeFindDistance(3).explosionResistance(100F); - public static NormalFluid.Properties ffPROPERTIES = new NormalFluid.Properties(FUSION_FUEL_FLUID, FUSION_FUEL_FLUID_FLOWING, FluidAttributes.builder(FUSION_FUEL_TEXTURE, FLOWING_FUSION_FUEL_TEXTURE).color(0xBB48d1cc).density(4000).viscosity(4000)).bucket(AllItems.FUSION_FUEL_BUCKET).block(AllBlocks.FUSION_FUEL).slopeFindDistance(3).explosionResistance(100F); + private static final ResourceLocation WATER_STILL = new ResourceLocation("block/water_still"); + private static final ResourceLocation WATER_FLOW = new ResourceLocation("block/water_flow"); + private static final ResourceLocation LAVA_STILL = new ResourceLocation("block/lava_still"); + private static final ResourceLocation LAVA_FLOW = new ResourceLocation("block/lava_flow"); + + private static final DeferredRegister REGISTRY = DeferredRegister.create(ForgeRegistries.FLUIDS, IronStars.ID); + + public static final RegistryObject ACID_FLUID = REGISTRY.register("acid_fluid", () -> new ForgeFlowingFluid.Source(AllFluids.ACID_PROPERTIES)); + public static final RegistryObject ACID_FLUID_FLOWING = REGISTRY.register("acid_fluid_flowing", () -> new ForgeFlowingFluid.Flowing(AllFluids.ACID_PROPERTIES)); + public static final RegistryObject REDSTONE_FLUID = REGISTRY.register("redstone_fluid", () -> new ForgeFlowingFluid.Source(AllFluids.RED_PROPERTIES)); + public static final RegistryObject REDSTONE_FLUID_FLOWING = REGISTRY.register("redstone_fluid_flowing", () -> new ForgeFlowingFluid.Flowing(AllFluids.RED_PROPERTIES)); + public static final RegistryObject FUSION_FUEL_FLUID = REGISTRY.register("fusion_fuel_fluid", () -> new ForgeFlowingFluid.Source(AllFluids.FUSION_FUEL_PROPERTIES)); + public static final RegistryObject FUSION_FUEL_FLUID_FLOWING = REGISTRY.register("fusion_fuel_fluid_flowing", () -> new ForgeFlowingFluid.Flowing(AllFluids.FUSION_FUEL_PROPERTIES)); + + private static final ForgeFlowingFluid.Properties ACID_PROPERTIES = new Properties(ACID_FLUID, ACID_FLUID_FLOWING, WATER_STILL, WATER_FLOW, 0xaaa5d439, AllItems.ACID_BUCKET, AllBlocks.ACID); + private static final ForgeFlowingFluid.Properties RED_PROPERTIES = new Properties(REDSTONE_FLUID, REDSTONE_FLUID_FLOWING, LAVA_STILL, LAVA_FLOW, 0xbbdc143c, AllItems.REDSTONE_BUCKET, AllBlocks.REDSTONE); + private static final ForgeFlowingFluid.Properties FUSION_FUEL_PROPERTIES = new Properties(FUSION_FUEL_FLUID, FUSION_FUEL_FLUID_FLOWING, LAVA_STILL, LAVA_FLOW,0xbb48d1cc, AllItems.FUSION_FUEL_BUCKET, AllBlocks.FUSION_FUEL); + + + static class Properties extends ForgeFlowingFluid.Properties { + public Properties(Supplier still, Supplier flowing, ResourceLocation still_id, ResourceLocation flowing_id, int color, Supplier bucket, LiquidBlock block) { + super(still, flowing, FluidAttributes.builder(still_id, flowing_id).color(color).density(4000).viscosity(4000)); + this.bucket(bucket).block(() -> block).slopeFindDistance(3).explosionResistance(100f); + } + } public static void register(IEventBus bus) { - FLUIDS.register(bus); + REGISTRY.register(bus); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllItems.java b/src/main/java/com/xekr/ironstars/registry/AllItems.java index 06d428b..84d2006 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllItems.java +++ b/src/main/java/com/xekr/ironstars/registry/AllItems.java @@ -4,7 +4,6 @@ import com.xekr.ironstars.item.BreathingHelmet; import com.xekr.ironstars.item.WrenchItem; import net.minecraft.world.item.*; -import net.minecraft.world.level.block.Blocks; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; @@ -14,67 +13,67 @@ @SuppressWarnings("unused") public class AllItems { - private static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, IronStars.ID); + private static final DeferredRegister REGISTRY = DeferredRegister.create(ForgeRegistries.ITEMS, IronStars.ID); //base - public static final RegistryObject ACCELERATOR = ITEMS.register("accelerator", () -> new BlockItem(AllBlocks.ACCELERATOR.get(), getProperties())); - public static final RegistryObject CENTRIFUGE = ITEMS.register("centrifuge", () -> new BlockItem(AllBlocks.CENTRIFUGE.get(), getProperties())); - public static final RegistryObject CHEMICAL_ACCUMULATOR = ITEMS.register("chemical_accumulator", () -> new BlockItem(AllBlocks.CHEMICAL_ACCUMULATOR.get(), getProperties())); - public static final RegistryObject COIL = ITEMS.register("coil", () -> new BlockItem(AllBlocks.COIL.get(), getProperties())); - public static final RegistryObject COPPER_WIRE = ITEMS.register("copper_wire", () -> new ItemNameBlockItem(AllBlocks.COPPER_TRIPWIRE.get(), getProperties())); -// public static final RegistryObject ELECTRIC_WIRE = ITEMS.register("electric_wire", () -> new BlockItem(IBlocks.ELECTRIC_WIRE.get(), getProperties())); - public static final RegistryObject INTERACTOR = ITEMS.register("interactor", () -> new BlockItem(AllBlocks.INTERACTOR.get(), getProperties())); - public static final RegistryObject ITEM_RAIL = ITEMS.register("item_rail", () -> new BlockItem(AllBlocks.ITEM_RAIL.get(), getProperties())); - public static final RegistryObject MOTOR = ITEMS.register("motor", () -> new BlockItem(AllBlocks.MOTOR.get(), getProperties())); - public static final RegistryObject MOTOR_LAY = ITEMS.register("motor_lay", () -> new BlockItem(AllBlocks.MOTOR_LAY.get(), getProperties())); - public static final RegistryObject TURBINE = ITEMS.register("turbine", () -> new BlockItem(AllBlocks.TURBINE.get(), getProperties())); - public static final RegistryObject WINDMILL = ITEMS.register("windmill", () -> new BlockItem(AllBlocks.WINDMILL.get(), getProperties())); - public static final RegistryObject COPPER_PRESSURE_PLATE = ITEMS.register("copper_pressure_plate", () -> new BlockItem(AllBlocks.COPPER_PRESSURE_PLATE.get(), getProperties())); - public static final RegistryObject TITANIUM_PRESSURE_PLATE = ITEMS.register("titanium_pressure_plate", () -> new BlockItem(AllBlocks.TITANIUM_PRESSURE_PLATE.get(), getProperties())); - public static final RegistryObject STEEL_PRESSURE_PLATE = ITEMS.register("steel_pressure_plate", () -> new BlockItem(AllBlocks.STEEL_PRESSURE_PLATE.get(), getProperties())); - public static final RegistryObject NETHERITE_PRESSURE_PLATE = ITEMS.register("netherite_pressure_plate", () -> new BlockItem(AllBlocks.NETHERITE_PRESSURE_PLATE.get(), getProperties().fireResistant())); - public static final RegistryObject TITANIUM_ALLOY_PRESSURE_PLATE = ITEMS.register("titanium_alloy_pressure_plate", () -> new BlockItem(AllBlocks.TITANIUM_ALLOY_PRESSURE_PLATE.get(), getProperties().fireResistant())); - public static final RegistryObject TUNGSTEN_PRESSURE_PLATE = ITEMS.register("tungsten_pressure_plate", () -> new BlockItem(AllBlocks.TUNGSTEN_PRESSURE_PLATE.get(), getProperties().fireResistant())); - public static final RegistryObject MAGNET_BLOCK = ITEMS.register("magnet_block", () -> new BlockItem(AllBlocks.MAGNET_BLOCK.get(), getProperties())); - public static final RegistryObject SILICON_BLOCK = ITEMS.register("silicon_block", () -> new BlockItem(AllBlocks.SILICON_BLOCK.get(), getProperties())); - public static final RegistryObject STEEL_BLOCK = ITEMS.register("steel_block", () -> new BlockItem(AllBlocks.STEEL_BLOCK.get(), getProperties())); - public static final RegistryObject TITANIUM_ALLOY_BLOCK = ITEMS.register("titanium_alloy_block", () -> new BlockItem(AllBlocks.TITANIUM_ALLOY_BLOCK.get(), getProperties())); - public static final RegistryObject TITANIUM_BLOCK = ITEMS.register("titanium_block", () -> new BlockItem(AllBlocks.TITANIUM_BLOCK.get(), getProperties())); + public static final RegistryObject ACCELERATOR = REGISTRY.register("accelerator", () -> new BlockItem(AllBlocks.ACCELERATOR, getProperties())); + public static final RegistryObject CENTRIFUGE = REGISTRY.register("centrifuge", () -> new BlockItem(AllBlocks.CENTRIFUGE, getProperties())); + public static final RegistryObject CHEMICAL_ACCUMULATOR = REGISTRY.register("chemical_accumulator", () -> new BlockItem(AllBlocks.CHEMICAL_ACCUMULATOR, getProperties())); + public static final RegistryObject COIL = REGISTRY.register("coil", () -> new BlockItem(AllBlocks.COIL, getProperties())); + public static final RegistryObject COPPER_WIRE = REGISTRY.register("copper_wire", () -> new ItemNameBlockItem(AllBlocks.COPPER_TRIPWIRE, getProperties())); +// public static final RegistryObject ELECTRIC_WIRE = REGISTRY.register("electric_wire", () -> new BlockItem(IBlocks.ELECTRIC_WIRE, getProperties())); + public static final RegistryObject INTERACTOR = REGISTRY.register("interactor", () -> new BlockItem(AllBlocks.INTERACTOR, getProperties())); + public static final RegistryObject ITEM_RAIL = REGISTRY.register("item_rail", () -> new BlockItem(AllBlocks.ITEM_RAIL, getProperties())); + public static final RegistryObject MOTOR = REGISTRY.register("motor", () -> new BlockItem(AllBlocks.MOTOR, getProperties())); + public static final RegistryObject MOTOR_LAY = REGISTRY.register("motor_lay", () -> new BlockItem(AllBlocks.MOTOR_LAY, getProperties())); + public static final RegistryObject TURBINE = REGISTRY.register("turbine", () -> new BlockItem(AllBlocks.TURBINE, getProperties())); + public static final RegistryObject WINDMILL = REGISTRY.register("windmill", () -> new BlockItem(AllBlocks.WINDMILL, getProperties())); + public static final RegistryObject COPPER_PRESSURE_PLATE = REGISTRY.register("copper_pressure_plate", () -> new BlockItem(AllBlocks.COPPER_PRESSURE_PLATE, getProperties())); + public static final RegistryObject TITANIUM_PRESSURE_PLATE = REGISTRY.register("titanium_pressure_plate", () -> new BlockItem(AllBlocks.TITANIUM_PRESSURE_PLATE, getProperties())); + public static final RegistryObject STEEL_PRESSURE_PLATE = REGISTRY.register("steel_pressure_plate", () -> new BlockItem(AllBlocks.STEEL_PRESSURE_PLATE, getProperties())); + public static final RegistryObject NETHERITE_PRESSURE_PLATE = REGISTRY.register("netherite_pressure_plate", () -> new BlockItem(AllBlocks.NETHERITE_PRESSURE_PLATE, getProperties().fireResistant())); + public static final RegistryObject TITANIUM_ALLOY_PRESSURE_PLATE = REGISTRY.register("titanium_alloy_pressure_plate", () -> new BlockItem(AllBlocks.TITANIUM_ALLOY_PRESSURE_PLATE, getProperties().fireResistant())); + public static final RegistryObject TUNGSTEN_PRESSURE_PLATE = REGISTRY.register("tungsten_pressure_plate", () -> new BlockItem(AllBlocks.TUNGSTEN_PRESSURE_PLATE, getProperties().fireResistant())); + public static final RegistryObject MAGNET_BLOCK = REGISTRY.register("magnet_block", () -> new BlockItem(AllBlocks.MAGNET_BLOCK, getProperties())); + public static final RegistryObject SILICON_BLOCK = REGISTRY.register("silicon_block", () -> new BlockItem(AllBlocks.SILICON_BLOCK, getProperties())); + public static final RegistryObject STEEL_BLOCK = REGISTRY.register("steel_block", () -> new BlockItem(AllBlocks.STEEL_BLOCK, getProperties())); + public static final RegistryObject TITANIUM_ALLOY_BLOCK = REGISTRY.register("titanium_alloy_block", () -> new BlockItem(AllBlocks.TITANIUM_ALLOY_BLOCK, getProperties())); + public static final RegistryObject TITANIUM_BLOCK = REGISTRY.register("titanium_block", () -> new BlockItem(AllBlocks.TITANIUM_BLOCK, getProperties())); //deco - public static final RegistryObject STEEL_TILES = ITEMS.register("steel_tiles", () -> new BlockItem(AllBlocks.STEEL_TILES.get(), getProperties(DECO))); - public static final RegistryObject FISH_TANK = ITEMS.register("fish_tank", () -> new BlockItem(AllBlocks.FISH_TANK.get(), getProperties(DECO))); + public static final RegistryObject STEEL_TILES = REGISTRY.register("steel_tiles", () -> new BlockItem(AllBlocks.STEEL_TILES, getProperties(DECO))); + public static final RegistryObject FISH_TANK = REGISTRY.register("fish_tank", () -> new BlockItem(AllBlocks.FISH_TANK, getProperties(DECO))); //ship //alien - public static final RegistryObject MOON_ROCK = ITEMS.register("moon_rock", () -> new BlockItem(AllBlocks.MOON_ROCK.get(), getProperties(ALIEN))); - public static final RegistryObject MOON_SOIL = ITEMS.register("moon_soil", () -> new BlockItem(AllBlocks.MOON_SOIL.get(), getProperties(ALIEN))); - public static final RegistryObject MOON_DUST = ITEMS.register("moon_dust", () -> new BlockItem(AllBlocks.MOON_DUST.get(), getProperties(ALIEN))); - public static final RegistryObject TITANIUM_ORE = ITEMS.register("titanium_ore", () -> new BlockItem(AllBlocks.TITANIUM_ORE.get(), getProperties(ALIEN))); + public static final RegistryObject MOON_ROCK = REGISTRY.register("moon_rock", () -> new BlockItem(AllBlocks.MOON_ROCK, getProperties(ALIEN))); + public static final RegistryObject MOON_SOIL = REGISTRY.register("moon_soil", () -> new BlockItem(AllBlocks.MOON_SOIL, getProperties(ALIEN))); + public static final RegistryObject MOON_DUST = REGISTRY.register("moon_dust", () -> new BlockItem(AllBlocks.MOON_DUST, getProperties(ALIEN))); + public static final RegistryObject TITANIUM_ORE = REGISTRY.register("titanium_ore", () -> new BlockItem(AllBlocks.TITANIUM_ORE, getProperties(ALIEN))); //base - public static final RegistryObject WRENCH = ITEMS.register("wrench", () -> new WrenchItem(getProperties())); - public static final RegistryObject ACID_BUCKET = ITEMS.register("acid_bucket",() -> new BucketItem(AllFluids.ACID_FLUID, getProperties().craftRemainder(Items.BUCKET).stacksTo(1))); - public static final RegistryObject REDSTONE_BUCKET = ITEMS.register("redstone_bucket",() -> new BucketItem(AllFluids.REDSTONE_FLUID, getProperties().craftRemainder(Items.BUCKET).stacksTo(1))); - public static final RegistryObject FUSION_FUEL_BUCKET = ITEMS.register("fusion_fuel_bucket",() -> new BucketItem(AllFluids.FUSION_FUEL_FLUID, getProperties().craftRemainder(Items.BUCKET).stacksTo(1))); + public static final RegistryObject WRENCH = REGISTRY.register("wrench", () -> new WrenchItem(getProperties())); + public static final RegistryObject ACID_BUCKET = REGISTRY.register("acid_bucket",() -> new BucketItem(AllFluids.ACID_FLUID, getProperties().craftRemainder(Items.BUCKET).stacksTo(1))); + public static final RegistryObject REDSTONE_BUCKET = REGISTRY.register("redstone_bucket",() -> new BucketItem(AllFluids.REDSTONE_FLUID, getProperties().craftRemainder(Items.BUCKET).stacksTo(1))); + public static final RegistryObject FUSION_FUEL_BUCKET = REGISTRY.register("fusion_fuel_bucket",() -> new BucketItem(AllFluids.FUSION_FUEL_FLUID, getProperties().craftRemainder(Items.BUCKET).stacksTo(1))); - public static final RegistryObject ACID_BOTTLE = ITEMS.register("acid_bottle",() -> new Item(getProperties().craftRemainder(Items.GLASS_BOTTLE).stacksTo(16))); + public static final RegistryObject ACID_BOTTLE = REGISTRY.register("acid_bottle",() -> new Item(getProperties().craftRemainder(Items.GLASS_BOTTLE).stacksTo(16))); - public static final RegistryObject CHIP = ITEMS.register("chip", () -> new Item(getProperties())); - public static final RegistryObject CIRCUIT_BOARD = ITEMS.register("circuit_board", () -> new Item(getProperties())); + public static final RegistryObject CHIP = REGISTRY.register("chip", () -> new Item(getProperties())); + public static final RegistryObject CIRCUIT_BOARD = REGISTRY.register("circuit_board", () -> new Item(getProperties())); - public static final RegistryObject HARDENED_RESIN = ITEMS.register("hardened_resin", () -> new Item(getProperties())); - public static final RegistryObject MAGNET = ITEMS.register("magnet", () -> new Item(getProperties())); - public static final RegistryObject RESIN = ITEMS.register("resin", () -> new Item(getProperties())); - public static final RegistryObject SILICON = ITEMS.register("silicon", () -> new Item(getProperties())); - public static final RegistryObject STEEL_INGOT = ITEMS.register("steel_ingot", () -> new Item(getProperties())); - public static final RegistryObject STICKY_RESIN = ITEMS.register("sticky_resin", () -> new Item(getProperties())); - public static final RegistryObject TITANIUM_ALLOY_INGOT = ITEMS.register("titanium_alloy_ingot", () -> new Item(getProperties())); - public static final RegistryObject TITANIUM_INGOT = ITEMS.register("titanium_ingot", () -> new Item(getProperties())); - public static final RegistryObject PEARL_FRAGMENT = ITEMS.register("pearl_fragment", () -> new Item(getProperties())); - public static final RegistryObject PURE_CRYSTAL = ITEMS.register("pure_crystal", () -> new Item(getProperties())); - public static final RegistryObject SPACE_CRYSTAL = ITEMS.register("space_crystal", () -> new Item(getProperties())); - public static final RegistryObject REMOTE_CONTROL = ITEMS.register("remote_control", () -> new Item(getProperties())); - public static final RegistryObject BREATHING_HELMET = ITEMS.register("breathing_helmet", () -> new BreathingHelmet(getProperties())); + public static final RegistryObject HARDENED_RESIN = REGISTRY.register("hardened_resin", () -> new Item(getProperties())); + public static final RegistryObject MAGNET = REGISTRY.register("magnet", () -> new Item(getProperties())); + public static final RegistryObject RESIN = REGISTRY.register("resin", () -> new Item(getProperties())); + public static final RegistryObject SILICON = REGISTRY.register("silicon", () -> new Item(getProperties())); + public static final RegistryObject STEEL_INGOT = REGISTRY.register("steel_ingot", () -> new Item(getProperties())); + public static final RegistryObject STICKY_RESIN = REGISTRY.register("sticky_resin", () -> new Item(getProperties())); + public static final RegistryObject TITANIUM_ALLOY_INGOT = REGISTRY.register("titanium_alloy_ingot", () -> new Item(getProperties())); + public static final RegistryObject TITANIUM_INGOT = REGISTRY.register("titanium_ingot", () -> new Item(getProperties())); + public static final RegistryObject PEARL_FRAGMENT = REGISTRY.register("pearl_fragment", () -> new Item(getProperties())); + public static final RegistryObject PURE_CRYSTAL = REGISTRY.register("pure_crystal", () -> new Item(getProperties())); + public static final RegistryObject SPACE_CRYSTAL = REGISTRY.register("space_crystal", () -> new Item(getProperties())); + public static final RegistryObject REMOTE_CONTROL = REGISTRY.register("remote_control", () -> new Item(getProperties())); + public static final RegistryObject BREATHING_HELMET = REGISTRY.register("breathing_helmet", () -> new BreathingHelmet(getProperties())); //deco //ship //alien @@ -87,7 +86,13 @@ private static Item.Properties getProperties(CreativeModeTab tab) { return new Item.Properties().tab(tab); } + // forge方块注册有延迟, 物品只能以supplier形式存在, 否则BlockItem会NPE + private static T register(String name, T item) { + REGISTRY.register(name, () -> item); + return item; + } + public static void register(IEventBus bus) { - ITEMS.register(bus); + REGISTRY.register(bus); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllSounds.java b/src/main/java/com/xekr/ironstars/registry/AllSounds.java new file mode 100644 index 0000000..200634b --- /dev/null +++ b/src/main/java/com/xekr/ironstars/registry/AllSounds.java @@ -0,0 +1,23 @@ +package com.xekr.ironstars.registry; + +import com.xekr.ironstars.IronStars; +import net.minecraft.sounds.SoundEvent; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; + +public class AllSounds { + private static final DeferredRegister REGISTRY = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, IronStars.ID); + + public static final SoundEvent DEEP_SPACE = register("deep_space"); + + private static SoundEvent register(String name) { + SoundEvent sound = new SoundEvent(IronStars.id(name)); + REGISTRY.register(name, () -> sound); + return sound; + } + + public static void register(IEventBus bus) { + REGISTRY.register(bus); + } +} diff --git a/src/main/java/com/xekr/ironstars/world/MoonBiomeSource.java b/src/main/java/com/xekr/ironstars/world/MoonBiomeSource.java index 0107370..7b54097 100644 --- a/src/main/java/com/xekr/ironstars/world/MoonBiomeSource.java +++ b/src/main/java/com/xekr/ironstars/world/MoonBiomeSource.java @@ -1,38 +1,34 @@ package com.xekr.ironstars.world; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Sets; import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import com.xekr.ironstars.registry.AllDimensions; -import net.minecraft.core.Registry; -import net.minecraft.data.worldgen.biome.OverworldBiomes; -import net.minecraft.resources.RegistryLookupCodec; -import net.minecraft.resources.ResourceKey; +import net.minecraft.core.BlockPos; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; +import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.Optional; +import java.util.Random; +import java.util.Set; +import java.util.function.Predicate; +import java.util.function.Supplier; -public class MoonBiomeSource extends BiomeSource { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - Codec.LONG.fieldOf("seed").stable().orElseGet(() -> AllDimensions.seed).forGetter(obj -> obj.seed), - RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter(provider -> provider.registry) - ).apply(instance, instance.stable(MoonBiomeSource::new))); +public class MoonBiomeSource extends BiomeSource implements BiomeManager.NoiseBiomeSource { + public static final Codec CODEC = Biome.CODEC.fieldOf("biome") + .xmap(MoonBiomeSource::new, obj -> () -> obj.biome).stable().codec(); - private static final List> BIOMES = ImmutableList.of(Biomes.DESERT); + private final Biome biome; - private final Registry registry; - private final long seed; - - public MoonBiomeSource(long seed, Registry registryIn) { - super(BIOMES.stream().map(ResourceKey::location).map(registryIn::getOptional).filter(Optional::isPresent).map(opt -> opt::get)); - this.seed = seed; - this.registry = registryIn; + private MoonBiomeSource(Supplier biome) { + this(biome.get()); } + public MoonBiomeSource(Biome biome) { + super(ImmutableList.of(biome)); + this.biome = biome; + } @Override protected Codec codec() { return CODEC; @@ -40,11 +36,27 @@ protected Codec codec() { @Override public BiomeSource withSeed(long pSeed) { - return new MoonBiomeSource(pSeed, this.registry); + return this; } @Override public Biome getNoiseBiome(int p_186735_, int p_186736_, int p_186737_, Climate.Sampler p_186738_) { - return OverworldBiomes.desert(); + return this.biome; + } + + @Override + public Biome getNoiseBiome(int pX, int pY, int pZ) { + return this.biome; + } + + @Nullable + @Override + public BlockPos findBiomeHorizontal(int x, int y, int z, int radius, int blockCheckInterval, Predicate predicate, Random random, boolean bl, Climate.Sampler sampler) { + return predicate.test(this.biome) ? bl ? new BlockPos(x, y, z) : new BlockPos(x-radius+random.nextInt(radius*2+1), y, z-radius+random.nextInt(radius*2+1)) : null; + } + + @Override + public Set getBiomesWithin(int p_186705_, int p_186706_, int p_186707_, int p_186708_, Climate.Sampler p_186709_) { + return Sets.newHashSet(this.biome); } } diff --git a/src/main/java/com/xekr/ironstars/world/MoonWorldGenerator.java b/src/main/java/com/xekr/ironstars/world/MoonWorldGenerator.java index b335cd2..ce02d28 100644 --- a/src/main/java/com/xekr/ironstars/world/MoonWorldGenerator.java +++ b/src/main/java/com/xekr/ironstars/world/MoonWorldGenerator.java @@ -10,8 +10,8 @@ import com.mojang.serialization.Lifecycle; import com.xekr.ironstars.IronStars; import com.xekr.ironstars.IronStarsUtil; +import com.xekr.ironstars.registry.AllBiomes; import com.xekr.ironstars.registry.AllBlocks; -import net.minecraft.core.MappedRegistry; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.data.BuiltinRegistries; @@ -193,7 +193,7 @@ private Map getDimensions() { false, new TerrainShaper(CubicSpline.constant(0.0F), CubicSpline.constant(0.0F), CubicSpline.constant(0.0F)) ), - AllBlocks.MOON_ROCK.get().defaultBlockState(), + AllBlocks.MOON_ROCK.defaultBlockState(), Blocks.WATER.defaultBlockState(), tfSurface(), 0, @@ -206,9 +206,7 @@ private Map getDimensions() { ); this.getOrCreateInRegistry(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY, IronStars.id("moon_noise_config"), () -> dimensionSettings); - - - NoiseBasedChunkGenerator chunkGen = new NoiseBasedChunkGenerator(RegistryAccess.builtin().registryOrThrow(Registry.NOISE_REGISTRY), new MoonBiomeSource(0L, new MappedRegistry<>(Registry.BIOME_REGISTRY, Lifecycle.experimental())), 0L, () -> dimensionSettings); + NoiseBasedChunkGenerator chunkGen = new NoiseBasedChunkGenerator(RegistryAccess.builtin().registryOrThrow(Registry.NOISE_REGISTRY), new MoonBiomeSource(AllBiomes.MOON), 0L, () -> dimensionSettings); final DimensionType dimensionType = DimensionType.create( OptionalLong.empty(),