Skip to content

Commit

Permalink
Properly register features (apparently this got missed in the post-1.…
Browse files Browse the repository at this point in the history
…12 update). Replace `AtChunk` with `Placement.NOOP`. Fix a number of small errors in `PredicateDeserializer` and add tests for various different combinations of predicates, fixes #55.
  • Loading branch information
alcatrazEscapee committed Jul 1, 2020
1 parent a28f657 commit 8fa0ede
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 46 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ Biome and Dimension rules both can be a string, an array, or an object. The synt

\*One exception is that biomes have the `"type": "tag"` ability, which dimensions do not.

A biome / dimension rule entry can be a single string (which will match the single id provided), or it can be a json object. If it is an object, it requires a `type` property. Valid types are:
A biome / dimension rule entry can be a single string (which will match the single id provided), or it can be a json object, or it can be a list of objects (which will function the same as the `or` type below). If it is an object, it requires a `type` property. Valid types are:

- `tag`: [Biomes only] Matches any tags found under `biomes`, which can be a string or string list
- `and`: Matches all conditions found within the `biomes` sub-entry.
- `not`: Inverts the condition found within the `biomes` sub-entry.
- `and`: Matches all conditions found within the `biomes` sub-entry. `biomes` must be a list of conditions to match.
- `or`: Matches any condition found within the `biomes` sub-entry. `biomes` must be a list of conditions to match.
- `not`: Inverts the condition found within the `biomes` sub-entry.

The Simplest Example:
```json
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/alcatrazescapee/oreveins/OreVeins.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.placement.IPlacementConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DeferredWorkQueue;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -20,9 +22,8 @@
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.ForgeRegistries;

import com.alcatrazescapee.oreveins.world.AtChunk;
import com.alcatrazescapee.oreveins.world.ModFeatures;
import com.alcatrazescapee.oreveins.world.VanillaFeatureManager;
import com.alcatrazescapee.oreveins.world.VeinsFeature;

import static com.alcatrazescapee.oreveins.OreVeins.MOD_ID;

Expand All @@ -41,7 +42,11 @@ public OreVeins()
Config.register();

// Register event handlers
FMLJavaModLoadingContext.get().getModEventBus().register(this);
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

modEventBus.register(this);
ModFeatures.FEATURES.register(modEventBus);

MinecraftForge.EVENT_BUS.register(ForgeEventHandler.INSTANCE);
}

Expand All @@ -55,7 +60,7 @@ public void setup(final FMLCommonSetupEvent event)
// Forge fix your stuff and either make not deprecate it or add an alternative.
DeferredWorkQueue.runLater(() -> {
ForgeRegistries.BIOMES.forEach(biome -> {
ConfiguredFeature<?, ?> feature = new VeinsFeature().withConfiguration(new NoFeatureConfig()).withPlacement(new AtChunk().configure(IPlacementConfig.NO_PLACEMENT_CONFIG));
ConfiguredFeature<?, ?> feature = ModFeatures.VEINS.get().withConfiguration(new NoFeatureConfig()).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG));
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, feature);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext
case "or":
return createCollectionRule(JSONUtils.getJsonArray(obj, collectionName), context, true);
case "not":
T innerRule = context.deserialize(JSONUtils.getJsonObject(obj, collectionName), elementType);
T innerRule = context.deserialize(obj.get(collectionName), elementType);
innerRule.test(null);
return createPredicate(item -> !innerRule.test(item));
default:
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/com/alcatrazescapee/oreveins/world/AtChunk.java

This file was deleted.

20 changes: 20 additions & 0 deletions src/main/java/com/alcatrazescapee/oreveins/world/ModFeatures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Part of the Realistic Ore Veins Mod by AlcatrazEscapee
* Work under Copyright. See the project LICENSE.md for details.
*/

package com.alcatrazescapee.oreveins.world;

import net.minecraft.world.gen.feature.Feature;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

import static com.alcatrazescapee.oreveins.OreVeins.MOD_ID;

public class ModFeatures
{
public static final DeferredRegister<Feature<?>> FEATURES = new DeferredRegister<>(ForgeRegistries.FEATURES, MOD_ID);

public static final RegistryObject<VeinsFeature> VEINS = FEATURES.register("veins", VeinsFeature::new);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "sphere",
"ore": "minecraft:white_wool",
"stone": "minecraft:stone",
"biomes": {
"type": "and",
"biomes": [
{"type": "tag", "biomes": "hot"},
{"type": "tag", "biomes": "dry"}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "sphere",
"ore": "minecraft:white_wool",
"stone": "minecraft:stone",
"biomes": {
"type": "not",
"biomes": {
"type": "not",
"biomes": [
"minecraft:plains"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "sphere",
"ore": "minecraft:white_wool",
"stone": "minecraft:stone",
"biomes": {
"type": "not",
"biomes": {
"type": "or",
"biomes": [
"minecraft:plains",
"minecraft:forest"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "sphere",
"ore": "minecraft:white_wool",
"stone": "minecraft:stone",
"biomes": {
"type": "or",
"biomes": [
"minecraft:plains",
"minecraft:forest"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "sphere",
"ore": "minecraft:white_wool",
"stone": "minecraft:stone",
"biomes": [
"minecraft:plains",
"minecraft:forest"
]
}

0 comments on commit 8fa0ede

Please sign in to comment.