Skip to content

Commit

Permalink
Fixes #25, Remove Infested Stone
Browse files Browse the repository at this point in the history
  • Loading branch information
UnRealDinnerbone committed Nov 13, 2023
1 parent 0ffb065 commit 2055bed
Show file tree
Hide file tree
Showing 30 changed files with 102 additions and 195 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 3.4.1
### 3.4.2

- Fix Bug with stacking portals
- Added support for debris
- Fix Crash on fabric
- Removed Infested Stone for spawning
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import dev.nanite.mlp.tasks.SingleOutputJar

plugins {
id("dev.nanite.mlp") version("0.0.3")
id("java")
Expand Down Expand Up @@ -107,7 +105,7 @@ publishMods {

def curseForgeOptions = curseforgeOptions {
accessToken = providers.environmentVariable("CURSE_TOKEN")
projectId = project.property("curse_id")
projectId = project.property("curse_id")
minecraftVersions.add("${minecraft_version}")
requires {
slug = "trenzalore"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@
import com.unrealdinnerbone.trenzalore.lib.CreativeTabs;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import org.jetbrains.annotations.ApiStatus;

import java.util.List;
import java.util.function.BiFunction;
Expand Down
6 changes: 2 additions & 4 deletions common/src/main/java/com/unrealdinnerbone/jamd/OresCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration;
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;

public record OresCodec(int oreSize, float discardChance, List<PlacementModifier> modifiers, List<OreConfiguration.TargetBlockState> targets) {
public record OresCodec(int oreSize, float discardChance, List<PlacementModifier> modifiers,
List<OreConfiguration.TargetBlockState> targets) {
public static final Codec<OresCodec> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("ore_size").forGetter(OresCodec::oreSize),
Codec.FLOAT.fieldOf("discard_on_air_chance").forGetter(OresCodec::discardChance),
Expand Down
44 changes: 25 additions & 19 deletions common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.features.OreFeatures;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class WorldType {
private final Path configPath;

private final TagKey<Biome> biomeTag;

public WorldType(String name, RegistryEntry<Block> block, RegistryEntry<BlockItem> item, RegistryEntry<BlockEntityType<PortalTileEntity>> blockEntity, TagKey<Biome> biomeTag) {
this.name = name;
this.key = KeySet.of(new ResourceLocation(JAMD.MOD_ID, name));
Expand Down Expand Up @@ -107,32 +109,36 @@ public void export(MinecraftServer server) throws IllegalStateException, IOExcep
for (PlacementModifier modifier : placementModifiers) {
DataResult<JsonElement> dataResult = PlacementModifier.CODEC.encodeStart(JsonOps.INSTANCE, modifier);
Optional<JsonElement> result = dataResult.result();
if(result.isEmpty()) {
if (result.isEmpty()) {
LOGGER.error("Failed to encode: {}", dataResult.error().get().message());
}
}
DataResult<JsonElement> json = PlacedFeature.DIRECT_CODEC.encodeStart(JsonOps.INSTANCE, placedFeature);
if (json.result().isPresent()) {
try {
JsonElement jsonElement = json.result().get();
JsonObject jsonObject = jsonElement.getAsJsonObject();
JsonObject feature = jsonObject.getAsJsonObject("feature");
String featureType = GsonHelper.getAsString(feature, "type");
FeatureTypeRegistry.getFeatureType(featureType).ifPresent(iFeatureTypeCompact -> {
try {
oresCodecs.add(iFeatureTypeCompact.getOreCodec(GsonHelper.getAsJsonObject(feature, "config"), placementModifiers));
}catch (Exception e) {
LOGGER.error("Failed to parse ore", e);
}
});
} catch (JsonSyntaxException e) {
LOGGER.error("Skipping ore", e);
}
//Todo better way to do this
if (!placedFeature.feature().is(OreFeatures.ORE_INFESTED)) {
DataResult<JsonElement> json = PlacedFeature.DIRECT_CODEC.encodeStart(JsonOps.INSTANCE, placedFeature);
if (json.result().isPresent()) {
try {
JsonElement jsonElement = json.result().get();
JsonObject jsonObject = jsonElement.getAsJsonObject();
JsonObject feature = jsonObject.getAsJsonObject("feature");
String featureType = GsonHelper.getAsString(feature, "type");
FeatureTypeRegistry.getFeatureType(featureType).ifPresent(iFeatureTypeCompact -> {
try {
oresCodecs.add(iFeatureTypeCompact.getOreCodec(GsonHelper.getAsJsonObject(feature, "config"), placementModifiers));
} catch (Exception e) {
LOGGER.error("Failed to parse ore", e);
}
});
} catch (JsonSyntaxException e) {
LOGGER.error("Skipping ore", e);
}

}
}

DataResult<JsonElement> result = ConfigCodec.CODEC.encodeStart(JsonOps.INSTANCE, new ConfigCodec(1, oresCodecs));
if (result.result().isPresent()) {
if(!Files.exists(JAMD.CONFIG_FOLDER)) {
if (!Files.exists(JAMD.CONFIG_FOLDER)) {
Files.createDirectories(JAMD.CONFIG_FOLDER);
}
Files.writeString(configPath, GSON.toJson(result.result().get()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.unrealdinnerbone.jamd.api;

import com.unrealdinnerbone.jamd.api.IFeatureTypeCompact;
import com.unrealdinnerbone.jamd.compact.MinecraftOreCompact;
import com.unrealdinnerbone.trenzalore.api.platform.Services;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -11,17 +9,16 @@
import java.util.Optional;
import java.util.function.Supplier;

public class FeatureTypeRegistry
{
public class FeatureTypeRegistry {
private static final Logger LOGGER = LogManager.getLogger();
public static final List<IFeatureTypeCompact<?>> FEATURES = new ArrayList<>();

public static void register(String modId, Supplier<IFeatureTypeCompact<?>> featureTypeCompact) {
if(Services.PLATFORM.isModLoaded(modId)) {
if (Services.PLATFORM.isModLoaded(modId)) {
IFeatureTypeCompact<?> iFeatureTypeCompact = featureTypeCompact.get();
LOGGER.debug("Registering Feature {} for {}", iFeatureTypeCompact.getFeatureType(), modId);
FEATURES.add(iFeatureTypeCompact);
}else {
} else {
LOGGER.debug("Skipping Feature for {} as mod is not loaded", modId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

import java.util.List;

public interface IFeatureTypeCompact<T>
{
public interface IFeatureTypeCompact<T> {

default OresCodec getOreCodec(JsonObject config, List<PlacementModifier> modifiers) throws IllegalArgumentException {
DataResult<T> parse = getCodec().parse(JsonOps.INSTANCE, config);
if(parse.error().isPresent()) {
if (parse.error().isPresent()) {
throw new IllegalArgumentException(parse.error().get().message());
} else {
return parse(parse.result().get(), modifiers);
Expand All @@ -28,7 +27,7 @@ default OresCodec getOreCodec(JsonObject config, List<PlacementModifier> modifie
Codec<T> getCodec();

/**
* @param value the parsed ore config codec
* @param value the parsed ore config codec
* @param placementModifiers the placement modifiers to create ore codec
* @return the ore codec
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.unrealdinnerbone.jamd.block;

import com.unrealdinnerbone.jamd.JAMDRegistry;
import com.unrealdinnerbone.jamd.WorldType;
import com.unrealdinnerbone.jamd.block.base.PortalBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

public class EndPortalBlock extends PortalBlock {

Expand All @@ -15,6 +10,4 @@ public EndPortalBlock() {
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import com.unrealdinnerbone.jamd.JAMDRegistry;
import com.unrealdinnerbone.jamd.block.base.PortalBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

public class NetherPortalBlock extends PortalBlock {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import com.unrealdinnerbone.jamd.JAMDRegistry;
import com.unrealdinnerbone.jamd.block.base.PortalBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

public class OverworldPortalBlock extends PortalBlock {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
package com.unrealdinnerbone.jamd.block.base;

import com.unrealdinnerbone.jamd.JAMDRegistry;
import com.unrealdinnerbone.jamd.WorldType;
import com.unrealdinnerbone.jamd.util.TelerportUtils;
import com.unrealdinnerbone.trenzalore.api.registry.RegistryEntry;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;

public abstract class PortalBlock extends Block implements EntityBlock {



//Todo CONFIG
private static final ResourceKey<Level> OVERWORLD = Level.OVERWORLD;

private final WorldType type;

public PortalBlock(WorldType type) {
super(Properties.of().requiresCorrectToolForDrops().strength(5.0F, 6.0F).sound(SoundType.STONE).mapColor(MapColor.COLOR_BLUE));
this.type = type;
Expand All @@ -46,11 +41,11 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (!level.isClientSide()) {
if(level.dimension().equals(type.getKey().level())) {
if (level.dimension().equals(type.getKey().level())) {
TelerportUtils.teleport(player, OVERWORLD, pos, type);
}else if(level.dimension().equals(OVERWORLD)) {
} else if (level.dimension().equals(OVERWORLD)) {
TelerportUtils.teleport(player, type.getKey().level(), pos, type);
}else {
} else {
player.displayClientMessage(Component.literal("You can't teleport from this dimension"), true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class JamdCommand {

public static void register(CommandDispatcher<CommandSourceStack> commandDispatcher) {
commandDispatcher.register(Commands.literal("jamd")
.then(Commands.literal("reload")
.executes(JamdCommand::reload)));
.then(Commands.literal("reload")
.executes(JamdCommand::reload)));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.unrealdinnerbone.jamd.OresCodec;
import com.unrealdinnerbone.jamd.api.IFeatureTypeCompact;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.feature.ScatteredOreFeature;
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration;
import net.minecraft.world.level.levelgen.placement.PlacementModifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,38 @@
import java.nio.file.Path;
import java.util.*;

public class OreRegistry
{
public class OreRegistry {
private static final Logger LOGGER = LogUtils.getLogger();

public static final Map<WorldType, List<PlacedFeature>> REGISTERED_FEATURES = new HashMap<>();

public static List<PlacedFeature> getFeatures(Holder<Biome> biomeHolder) {
if(biomeHolder.is(JAMDRegistry.OVERWORLD.getKey().biome())) {
if (biomeHolder.is(JAMDRegistry.OVERWORLD.getKey().biome())) {
return getFeatures(JAMDRegistry.OVERWORLD);
}else if(biomeHolder.is(JAMDRegistry.NETHER.getKey().biome())) {
} else if (biomeHolder.is(JAMDRegistry.NETHER.getKey().biome())) {
return getFeatures(JAMDRegistry.NETHER);
}else if(biomeHolder.is(JAMDRegistry.END.getKey().biome())) {
} else if (biomeHolder.is(JAMDRegistry.END.getKey().biome())) {
return getFeatures(JAMDRegistry.END);
}
return Collections.emptyList();
}

public static List<PlacedFeature> getFeatures(WorldType type) {
if(!REGISTERED_FEATURES.containsKey(type)) {
if (!REGISTERED_FEATURES.containsKey(type)) {
try {
Path resolve = JAMD.CONFIG_FOLDER.resolve(type.getName() + ".json");
if(!Files.exists(resolve)) {
if (!Files.exists(resolve)) {
return Collections.emptyList();
}
String jsonString = Files.readString(resolve);
JsonElement parse = new JsonParser().parse(jsonString);
DataResult<ConfigCodec> data = ConfigCodec.CODEC.parse(JsonOps.INSTANCE, parse);
if(data.error().isPresent()) {
if (data.error().isPresent()) {
LOGGER.error("Failed to parse config: {}", data.error().get().message());
return Collections.emptyList();
}
Optional<ConfigCodec> result = data.result();
if(result.isPresent()) {
if (result.isPresent()) {
List<PlacedFeature> features = new ArrayList<>();
ConfigCodec configCodec = result.get();
for (int i = 0; i < configCodec.oreMultiplier(); i++) {
Expand All @@ -56,11 +56,11 @@ public static List<PlacedFeature> getFeatures(WorldType type) {
}
}
REGISTERED_FEATURES.put(type, features);
}else {
} else {
LOGGER.error("Failed to parse config: {}", "No result");
return Collections.emptyList();
}
}catch (IOException e) {
} catch (IOException e) {
LOGGER.error("Failed to read config file", e);
}
}
Expand Down
Loading

0 comments on commit 2055bed

Please sign in to comment.