From e5179598e309dc86935ba0ec6a73ba04db8d77cd Mon Sep 17 00:00:00 2001 From: tterrag Date: Sat, 3 Oct 2020 17:12:32 -0400 Subject: [PATCH] Get things running, fix forge/mc dependencies and extendo grip --- src/main/java/com/simibubi/create/Create.java | 7 ++- .../curiosities/tools/ExtendoGripItem.java | 44 +++++++++---------- .../create/foundation/config/CWorldGen.java | 12 ----- .../foundation/worldgen/AllWorldFeatures.java | 27 +++++------- .../foundation/worldgen/ChanceOreFeature.java | 12 ++--- .../worldgen/CountedOreFeature.java | 20 ++++++--- .../create/foundation/worldgen/IFeature.java | 4 +- .../foundation/worldgen/OreFeature.java | 12 +++-- src/main/resources/META-INF/mods.toml | 7 +-- 9 files changed, 74 insertions(+), 71 deletions(-) diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index ff091b66a..59f1484e3 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -36,6 +36,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.BiomeLoadingEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.DistExecutor; @@ -81,6 +82,7 @@ public class Create { AllMovementBehaviours.register(); modEventBus.addListener(Create::init); + MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, Create::onBiomeLoad); modEventBus.addGenericListener(IRecipeSerializer.class, AllRecipeTypes::register); modEventBus.addGenericListener(ContainerType.class, AllContainerTypes::register); modEventBus.addGenericListener(ParticleType.class, AllParticleTypes::register); @@ -107,7 +109,10 @@ public class Create { AllPackets.registerPackets(); AllTriggers.register(); - AllWorldFeatures.reload(); + } + + public static void onBiomeLoad(BiomeLoadingEvent event) { + AllWorldFeatures.reload(event); } public static CreateRegistrate registrate() { diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java index bc4b35552..da452fb1e 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.curiosities.tools; import java.util.UUID; -import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.advancement.AllTriggers; @@ -22,7 +22,7 @@ import net.minecraft.item.Item; import net.minecraft.item.Rarity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.DamageSource; -import net.minecraft.util.ResourceLocation; +import net.minecraft.util.LazyValue; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.util.math.MathHelper; @@ -41,22 +41,23 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @EventBusSubscriber public class ExtendoGripItem extends Item { - static Multimap rangeModifier; - static Multimap doubleRangeModifier; + static LazyValue> rangeModifier = + new LazyValue>(() -> + // Holding an ExtendoGrip + ImmutableMultimap.of( + ForgeMod.REACH_DISTANCE.get(), + new AttributeModifier(UUID.fromString("7f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier", 3, + AttributeModifier.Operation.ADDITION)) + ); - static { - // Holding an ExtendoGrip - rangeModifier = HashMultimap.create(); - rangeModifier.put(ForgeMod.REACH_DISTANCE.get(), - new AttributeModifier(UUID.fromString("7f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier", 3, - AttributeModifier.Operation.ADDITION)); - - // Holding two ExtendoGrips o.O - doubleRangeModifier = HashMultimap.create(); - doubleRangeModifier.put(ForgeMod.REACH_DISTANCE.get(), - new AttributeModifier(UUID.fromString("8f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier", 5, - AttributeModifier.Operation.ADDITION)); - } + static LazyValue> doubleRangeModifier = + new LazyValue>(() -> + // Holding two ExtendoGrips o.O + ImmutableMultimap.of( + ForgeMod.REACH_DISTANCE.get(), + new AttributeModifier(UUID.fromString("8f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier", 5, + AttributeModifier.Operation.ADDITION)) + ); public ExtendoGripItem(Properties properties) { super(properties.maxStackSize(1) @@ -85,13 +86,13 @@ public class ExtendoGripItem extends Item { if (holdingExtendo != wasHoldingExtendo) { if (!holdingExtendo) { - player.getAttributes().removeModifiers(rangeModifier); + player.getAttributes().removeModifiers(rangeModifier.getValue()); persistentData.remove(marker); } else { if (player instanceof ServerPlayerEntity) AllTriggers.EXTENDO.trigger((ServerPlayerEntity) player); player.getAttributes() - .addTemporaryModifiers(rangeModifier); + .addTemporaryModifiers(rangeModifier.getValue()); persistentData.putBoolean(marker, true); } } @@ -99,13 +100,13 @@ public class ExtendoGripItem extends Item { if (holdingDualExtendo != wasHoldingDualExtendo) { if (!holdingDualExtendo) { player.getAttributes() - .removeModifiers(doubleRangeModifier); + .removeModifiers(doubleRangeModifier.getValue()); persistentData.remove(dualMarker); } else { if (player instanceof ServerPlayerEntity) AllTriggers.GIGA_EXTENDO.trigger((ServerPlayerEntity) player); player.getAttributes() - .addTemporaryModifiers(doubleRangeModifier); + .addTemporaryModifiers(doubleRangeModifier.getValue()); persistentData.putBoolean(dualMarker, true); } } @@ -147,7 +148,6 @@ public class ExtendoGripItem extends Item { mc.pointedEntity = entity1; } } - } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/config/CWorldGen.java b/src/main/java/com/simibubi/create/foundation/config/CWorldGen.java index 666f5fe63..f90afb0a0 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CWorldGen.java +++ b/src/main/java/com/simibubi/create/foundation/config/CWorldGen.java @@ -14,18 +14,6 @@ public class CWorldGen extends ConfigBase { AllWorldFeatures.fillConfig(builder); } - @Override - public void onReload() { - AllWorldFeatures.reload(); - super.onReload(); - } - - @Override - public void onLoad() { - AllWorldFeatures.reload(); - super.onLoad(); - } - @Override public String getName() { return "worldgen.v" + AllWorldFeatures.forcedUpdateVersion; diff --git a/src/main/java/com/simibubi/create/foundation/worldgen/AllWorldFeatures.java b/src/main/java/com/simibubi/create/foundation/worldgen/AllWorldFeatures.java index 0c0584684..3f2647e13 100644 --- a/src/main/java/com/simibubi/create/foundation/worldgen/AllWorldFeatures.java +++ b/src/main/java/com/simibubi/create/foundation/worldgen/AllWorldFeatures.java @@ -17,6 +17,7 @@ import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.Biome.Category; import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.world.BiomeLoadingEvent; import net.minecraftforge.registries.ForgeRegistries; public enum AllWorldFeatures { @@ -43,32 +44,24 @@ public enum AllWorldFeatures { public static final int forcedUpdateVersion = 1; public IFeature feature; - private Map> featureInstances; AllWorldFeatures(IFeature feature) { this.feature = feature; - this.featureInstances = new HashMap<>(); this.feature.setId(Lang.asId(name())); } - public static void reload() { + public static void reload(BiomeLoadingEvent event) { for (AllWorldFeatures entry : AllWorldFeatures.values()) { - for (Biome biome : ForgeRegistries.BIOMES) { + if (event.getName() == Biomes.THE_VOID.getRegistryName()) + continue; + if (event.getCategory() == Category.NETHER) + continue; - if (biome.getRegistryName() == Biomes.THE_VOID.getRegistryName()) - continue; - if (biome.getCategory() == Category.NETHER) - continue; + Optional> createFeature = entry.feature.createFeature(event); + if (!createFeature.isPresent()) + continue; - if (entry.featureInstances.containsKey(biome)) - biome.getFeatures(entry.feature.getGenerationStage()).remove(entry.featureInstances.remove(biome)); - Optional> createFeature = entry.feature.createFeature(biome); - if (!createFeature.isPresent()) - continue; - - entry.featureInstances.put(biome, createFeature.get()); - biome.addFeature(entry.feature.getGenerationStage(), createFeature.get()); - } + event.getGeneration().feature(entry.feature.getGenerationStage(), createFeature.get()); } // // Debug contained ore features diff --git a/src/main/java/com/simibubi/create/foundation/worldgen/ChanceOreFeature.java b/src/main/java/com/simibubi/create/foundation/worldgen/ChanceOreFeature.java index 815517bcc..9778826fa 100644 --- a/src/main/java/com/simibubi/create/foundation/worldgen/ChanceOreFeature.java +++ b/src/main/java/com/simibubi/create/foundation/worldgen/ChanceOreFeature.java @@ -5,10 +5,10 @@ import org.apache.commons.lang3.tuple.Pair; import com.tterrag.registrate.util.nullness.NonNullSupplier; import net.minecraft.block.Block; -import net.minecraft.world.gen.placement.ChanceRangeConfig; +import net.minecraft.world.gen.placement.ChanceConfig; import net.minecraft.world.gen.placement.Placement; -public class ChanceOreFeature extends OreFeature { +public class ChanceOreFeature extends OreFeature { private ConfigFloat clusterChance; @@ -23,9 +23,9 @@ public class ChanceOreFeature extends OreFeature { } @Override - protected Pair, ChanceRangeConfig> getPlacement() { - return Pair.of(Placement.CHANCE_RANGE, - new ChanceRangeConfig(clusterChance.getF(), minHeight.get(), 0, maxHeight.get() - minHeight.get())); + protected Pair, ChanceConfig> getPlacement() { + return Pair.of(Placement.CHANCE, + // TODO 1.16 worldgen verify this + new ChanceConfig((int) (1 / clusterChance.getF()))); } - } diff --git a/src/main/java/com/simibubi/create/foundation/worldgen/CountedOreFeature.java b/src/main/java/com/simibubi/create/foundation/worldgen/CountedOreFeature.java index 128acec63..99cfc02c4 100644 --- a/src/main/java/com/simibubi/create/foundation/worldgen/CountedOreFeature.java +++ b/src/main/java/com/simibubi/create/foundation/worldgen/CountedOreFeature.java @@ -1,14 +1,19 @@ package com.simibubi.create.foundation.worldgen; +import java.util.Optional; + import org.apache.commons.lang3.tuple.Pair; import com.tterrag.registrate.util.nullness.NonNullSupplier; import net.minecraft.block.Block; -import net.minecraft.world.gen.placement.CountRangeConfig; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.placement.IPlacementConfig; +import net.minecraft.world.gen.placement.NoPlacementConfig; import net.minecraft.world.gen.placement.Placement; +import net.minecraftforge.event.world.BiomeLoadingEvent; -public class CountedOreFeature extends OreFeature { +public class CountedOreFeature extends OreFeature { private ConfigInt clusterCount; @@ -23,9 +28,14 @@ public class CountedOreFeature extends OreFeature { } @Override - protected Pair, CountRangeConfig> getPlacement() { - return Pair.of(Placement.COUNT_RANGE, - new CountRangeConfig(clusterCount.get(), minHeight.get(), 0, maxHeight.get() - minHeight.get())); + protected Pair, NoPlacementConfig> getPlacement() { + return Pair.of(Placement.NOPE, IPlacementConfig.NO_PLACEMENT_CONFIG); } + @Override + public Optional> createFeature(BiomeLoadingEvent biome) { + return super.createFeature(biome) + // TODO 1.16 worldgen verify this + .map(cf -> cf.repeat(clusterCount.get())); + } } diff --git a/src/main/java/com/simibubi/create/foundation/worldgen/IFeature.java b/src/main/java/com/simibubi/create/foundation/worldgen/IFeature.java index f4137500b..930ef6790 100644 --- a/src/main/java/com/simibubi/create/foundation/worldgen/IFeature.java +++ b/src/main/java/com/simibubi/create/foundation/worldgen/IFeature.java @@ -2,10 +2,10 @@ package com.simibubi.create.foundation.worldgen; import java.util.Optional; -import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.GenerationStage.Decoration; import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.world.BiomeLoadingEvent; public interface IFeature { @@ -13,7 +13,7 @@ public interface IFeature { public void addToConfig(ForgeConfigSpec.Builder builder); - public Optional> createFeature(Biome biome); + public Optional> createFeature(BiomeLoadingEvent biome); public Decoration getGenerationStage(); diff --git a/src/main/java/com/simibubi/create/foundation/worldgen/OreFeature.java b/src/main/java/com/simibubi/create/foundation/worldgen/OreFeature.java index 30ee3f7da..7d99d9843 100644 --- a/src/main/java/com/simibubi/create/foundation/worldgen/OreFeature.java +++ b/src/main/java/com/simibubi/create/foundation/worldgen/OreFeature.java @@ -17,7 +17,9 @@ import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.OreFeatureConfig; import net.minecraft.world.gen.placement.IPlacementConfig; import net.minecraft.world.gen.placement.Placement; +import net.minecraft.world.gen.placement.TopSolidRangeConfig; import net.minecraftforge.common.ForgeConfigSpec.Builder; +import net.minecraftforge.event.world.BiomeLoadingEvent; public abstract class OreFeature extends ConfigBase implements IFeature { @@ -58,7 +60,7 @@ public abstract class OreFeature extends ConfigBase } @Override - public Optional> createFeature(Biome biome) { + public Optional> createFeature(BiomeLoadingEvent biome) { if (specificCategory != null && biome.getCategory() != specificCategory) return Optional.empty(); if (!canGenerate()) @@ -68,8 +70,12 @@ public abstract class OreFeature extends ConfigBase ConfiguredFeature createdFeature = Feature.ORE .configure(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, block.get() .getDefaultState(), clusterSize.get())) - .createDecoratedFeature(placement.getKey() - .configure(placement.getValue())); + .decorate(placement.getKey() + .configure(placement.getValue())) + .decorate(Placement.RANGE + // TODO 1.16 worldgen verify this + .configure(new TopSolidRangeConfig(minHeight.get(), 0, maxHeight.get() - minHeight.get()))) + .spreadHorizontally(); return Optional.of(createdFeature); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 3b69e270c..5c2d1bfe9 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,6 +1,7 @@ modLoader="javafml" -loaderVersion="[28,)" +loaderVersion="[34,)" #issueTrackerURL="" +license="MIT" [[mods]] modId="create" @@ -14,13 +15,13 @@ Technology that empowers the player.''' [[dependencies.create]] modId="forge" mandatory=true - versionRange="[31.2.0,)" + versionRange="[34.0.0,)" ordering="NONE" side="BOTH" [[dependencies.create]] modId="minecraft" mandatory=true - versionRange="[1.15.2,1.16)" + versionRange="[1.16.3,1.17)" ordering="NONE" side="BOTH" \ No newline at end of file