-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6b70e4
commit 3b79469
Showing
9 changed files
with
181 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/net/zepalesque/zenith/loot/condition/ConditionLootModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.zepalesque.zenith.loot.condition; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; | ||
import net.zepalesque.zenith.api.condition.Condition; | ||
|
||
import java.util.Optional; | ||
|
||
public class ConditionLootModule implements LootItemCondition { | ||
|
||
public static Codec<ConditionLootModule> CODEC = RecordCodecBuilder.create( | ||
builder -> builder | ||
.group(Condition.CODEC.fieldOf("condition").forGetter(module -> module.condition)) | ||
.apply(builder, ConditionLootModule::new)); | ||
|
||
private final Holder<Condition<?>> condition; | ||
|
||
public ConditionLootModule(Holder<Condition<?>> condition) | ||
{ | ||
this.condition = condition; | ||
} | ||
|
||
public LootItemConditionType getType() { | ||
return ZenithLootConditions.LOOT_MODULE.get(); | ||
} | ||
|
||
public boolean test(LootContext lootContext) { | ||
Optional<Condition<?>> optional = this.condition.unwrap().right(); | ||
return optional.isEmpty() || optional.get().test(); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/zepalesque/zenith/loot/condition/ZenithLootConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.zepalesque.zenith.loot.condition; | ||
|
||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import net.zepalesque.zenith.Zenith; | ||
|
||
public class ZenithLootConditions { | ||
|
||
public static final DeferredRegister<LootItemConditionType> LOOT_CONDITIONS = DeferredRegister.create(BuiltInRegistries.LOOT_CONDITION_TYPE, Zenith.MODID); | ||
|
||
public static final DeferredHolder<LootItemConditionType, LootItemConditionType> LOOT_MODULE = | ||
LOOT_CONDITIONS.register("when", () -> new LootItemConditionType(ConditionLootModule.CODEC)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/net/zepalesque/zenith/world/placement/ConditionPlacementModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.zepalesque.zenith.world.placement; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.levelgen.placement.PlacementContext; | ||
import net.minecraft.world.level.levelgen.placement.PlacementFilter; | ||
import net.minecraft.world.level.levelgen.placement.PlacementModifierType; | ||
import net.zepalesque.zenith.api.condition.Condition; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Optional; | ||
|
||
public class ConditionPlacementModule extends PlacementFilter { | ||
|
||
public static Codec<ConditionPlacementModule> CODEC = RecordCodecBuilder.create( | ||
builder -> builder | ||
.group(Condition.CODEC.fieldOf("condition").forGetter(module -> module.condition)) | ||
.apply(builder, ConditionPlacementModule::new)); | ||
|
||
public final Holder<Condition<?>> condition; | ||
|
||
private ConditionPlacementModule(Holder<Condition<?>> pCondition) { | ||
this.condition = pCondition; | ||
} | ||
|
||
public static ConditionPlacementModule of(Holder<Condition<?>> condition) { | ||
return new ConditionPlacementModule(condition); | ||
} | ||
|
||
protected boolean shouldPlace(@Nonnull PlacementContext context, @Nonnull RandomSource random, @Nonnull BlockPos pos) { | ||
Optional<Condition<?>> optional = this.condition.unwrap().right(); | ||
return optional.isEmpty() || optional.get().test(); | ||
} | ||
|
||
@Nonnull | ||
public PlacementModifierType<?> type() { | ||
return ZenithPlacementModifiers.PLACEMENT_MODULE.get(); | ||
} | ||
} | ||
|
||
|
15 changes: 15 additions & 0 deletions
15
src/main/java/net/zepalesque/zenith/world/placement/ZenithPlacementModifiers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.zepalesque.zenith.world.placement; | ||
|
||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.level.levelgen.placement.PlacementModifierType; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import net.zepalesque.zenith.Zenith; | ||
|
||
public class ZenithPlacementModifiers { | ||
|
||
public static final DeferredRegister<PlacementModifierType<?>> FILTERS = DeferredRegister.create(BuiltInRegistries.PLACEMENT_MODIFIER_TYPE, Zenith.MODID); | ||
|
||
public static final DeferredHolder<PlacementModifierType<?>, PlacementModifierType<ConditionPlacementModule>> PLACEMENT_MODULE = | ||
FILTERS.register("when", () -> () -> ConditionPlacementModule.CODEC); | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/net/zepalesque/zenith/world/state/ConditionalStateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package net.zepalesque.zenith.world.state; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider; | ||
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType; | ||
import net.zepalesque.zenith.api.condition.Condition; | ||
|
||
import java.util.Optional; | ||
|
||
public class ConditionalStateProvider extends BlockStateProvider { | ||
private final BlockStateProvider base; | ||
private final Holder<Condition<?>> condition; | ||
private final BlockStateProvider alternative; | ||
|
||
public static final Codec<ConditionalStateProvider> CODEC = RecordCodecBuilder.create((condition) -> | ||
condition.group( | ||
BlockStateProvider.CODEC.fieldOf("base").forGetter((alt) -> alt.base), | ||
Condition.CODEC.fieldOf("condition").forGetter((alt) -> alt.condition), | ||
BlockStateProvider.CODEC.fieldOf("alternative").forGetter((alt) -> alt.alternative)) | ||
.apply(condition, ConditionalStateProvider::new)); | ||
|
||
public ConditionalStateProvider(BlockStateProvider base, Holder<Condition<?>> condition, BlockStateProvider alternative) { | ||
this.base = base; | ||
this.condition = condition; | ||
this.alternative = alternative; | ||
} | ||
|
||
@Override | ||
public BlockState getState(RandomSource random, BlockPos pos) { | ||
Optional<Condition<?>> optional = this.condition.unwrap().right(); | ||
boolean test = optional.isEmpty() || optional.get().test(); | ||
return (test ? this.base : this.alternative).getState(random, pos); | ||
} | ||
protected BlockStateProviderType<?> type() { | ||
return ZenithStateProviders.CONDITIONAL_STATE.get(); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/zepalesque/zenith/world/state/ZenithStateProviders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.zepalesque.zenith.world.state; | ||
|
||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import net.zepalesque.zenith.Zenith; | ||
|
||
public class ZenithStateProviders { | ||
|
||
public static final DeferredRegister<BlockStateProviderType<?>> PROVIDERS = DeferredRegister.create(Registries.BLOCK_STATE_PROVIDER_TYPE, Zenith.MODID); | ||
|
||
public static DeferredHolder<BlockStateProviderType<?>, BlockStateProviderType<ConditionalStateProvider>> CONDITIONAL_STATE = | ||
PROVIDERS.register("conditional_state", () -> new BlockStateProviderType<>(ConditionalStateProvider.CODEC)); | ||
} |