mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
move most mod code into mod common
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.forge.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.VanillaBiomeProperties;
|
||||
|
||||
|
||||
public final class ForgeAddon implements BaseAddon {
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
private static final Logger logger = LoggerFactory.getLogger(ForgeAddon.class);
|
||||
private final PlatformImpl terraForgePlugin;
|
||||
|
||||
public ForgeAddon(PlatformImpl terraForgePlugin) {
|
||||
this.terraForgePlugin = terraForgePlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
terraForgePlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions())))
|
||||
.global();
|
||||
|
||||
terraForgePlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPostLoadEvent.class)
|
||||
.then(event -> event.getPack().getContext().put(event.loadTemplate(new PostLoadCompatibilityOptions())))
|
||||
.priority(100)
|
||||
.global();
|
||||
|
||||
terraForgePlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
|
||||
}
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "terra-forge";
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,6 @@
|
||||
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.forge.AwfulForgeHacks.RegistrySanityCheck;
|
||||
import com.dfsek.terra.forge.AwfulForgeHacks.RegistryStep;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
@@ -34,8 +31,10 @@ import net.minecraftforge.registries.RegisterEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.forge.data.Codecs;
|
||||
import com.dfsek.terra.forge.AwfulForgeHacks.RegistrySanityCheck;
|
||||
import com.dfsek.terra.forge.AwfulForgeHacks.RegistryStep;
|
||||
import com.dfsek.terra.forge.util.LifecycleUtil;
|
||||
import com.dfsek.terra.mod.data.Codecs;
|
||||
|
||||
|
||||
@Mod("terra")
|
||||
@@ -70,7 +69,7 @@ public class ForgeEntryPoint {
|
||||
event.register(Registry.WORLD_PRESET_KEY, helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> LifecycleUtil.registerWorldTypes(helper)));
|
||||
|
||||
|
||||
event.register(Registry.CHUNK_GENERATOR_KEY, helper -> helper.register(new Identifier("terra:terra"), Codecs.FORGE_CHUNK_GENERATOR_WRAPPER));
|
||||
event.register(Registry.CHUNK_GENERATOR_KEY, helper -> helper.register(new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER));
|
||||
event.register(Registry.BIOME_SOURCE_KEY, helper -> helper.register(new Identifier("terra:terra"), Codecs.TERRA_BIOME_SOURCE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,8 @@ package com.dfsek.terra.forge;
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import net.minecraft.MinecraftVersion;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.world.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -38,31 +31,31 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.addon.EphemeralAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.handle.ForgeItemHandle;
|
||||
import com.dfsek.terra.forge.util.ProtoPlatformBiome;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.mod.ModPlatform;
|
||||
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.mod.handle.MinecraftItemHandle;
|
||||
import com.dfsek.terra.mod.handle.MinecraftWorldHandle;
|
||||
|
||||
|
||||
public class PlatformImpl extends AbstractPlatform {
|
||||
public class PlatformImpl extends ModPlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PlatformImpl.class);
|
||||
private final ItemHandle itemHandle = new ForgeItemHandle();
|
||||
private final ItemHandle itemHandle = new MinecraftItemHandle();
|
||||
private final WorldHandle worldHandle = new MinecraftWorldHandle();
|
||||
private final Lazy<File> dataFolder = Lazy.lazy(() -> new File("./config/Terra"));
|
||||
|
||||
public PlatformImpl() {
|
||||
CommonPlatform.initialize(this);
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
}
|
||||
@@ -82,7 +75,7 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
}).join();
|
||||
//BiomeUtil.registerBiomes();
|
||||
server.getWorlds().forEach(world -> {
|
||||
if(world.getChunkManager().getChunkGenerator() instanceof ForgeChunkGeneratorWrapper chunkGeneratorWrapper) {
|
||||
if(world.getChunkManager().getChunkGenerator() instanceof MinecraftChunkGeneratorWrapper chunkGeneratorWrapper) {
|
||||
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
|
||||
chunkGeneratorWrapper.setPack(pack);
|
||||
LOGGER.info("Replaced pack in chunk generator for world {}", world);
|
||||
@@ -96,8 +89,8 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
List<BaseAddon> addons = new ArrayList<>();
|
||||
|
||||
addons.add(new ForgeAddon(this));
|
||||
|
||||
super.platformAddon().forEach(addons::add);
|
||||
|
||||
String mcVersion = MinecraftVersion.CURRENT.getReleaseTarget();
|
||||
try {
|
||||
@@ -139,27 +132,4 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
public @NotNull ItemHandle getItemHandle() {
|
||||
return itemHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||
.registerLoader(Identifier.class, (type, o, loader, depthTracker) -> {
|
||||
Identifier identifier = Identifier.tryParse((String) o);
|
||||
if(identifier == null)
|
||||
throw new LoadException("Invalid identifier: " + o, depthTracker);
|
||||
return identifier;
|
||||
})
|
||||
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class, (type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)));
|
||||
}
|
||||
|
||||
|
||||
private ProtoPlatformBiome parseBiome(String id, DepthTracker tracker) throws LoadException {
|
||||
Identifier identifier = Identifier.tryParse(id);
|
||||
if(BuiltinRegistries.BIOME.get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier, tracker); // failure.
|
||||
return new ProtoPlatformBiome(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
|
||||
@Value("forge.use-vanilla-biomes")
|
||||
@Default
|
||||
private boolean vanillaBiomes = false;
|
||||
|
||||
@Value("forge.beard.enable")
|
||||
@Default
|
||||
private boolean beard = true;
|
||||
|
||||
@Value("forge.beard.threshold")
|
||||
@Default
|
||||
private double beardThreshold = 0.5;
|
||||
|
||||
@Value("forge.beard.air-threshold")
|
||||
@Default
|
||||
private double airThreshold = -0.5;
|
||||
|
||||
public boolean useVanillaBiomes() {
|
||||
return vanillaBiomes;
|
||||
}
|
||||
|
||||
public boolean isBeard() {
|
||||
return beard;
|
||||
}
|
||||
|
||||
public double getBeardThreshold() {
|
||||
return beardThreshold;
|
||||
}
|
||||
|
||||
public double getAirThreshold() {
|
||||
return airThreshold;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import net.minecraft.world.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
@Value("colors.grass")
|
||||
@Default
|
||||
private Integer grassColor = null;
|
||||
|
||||
@Value("colors.fog")
|
||||
@Default
|
||||
private Integer fogColor = null;
|
||||
|
||||
@Value("colors.water")
|
||||
@Default
|
||||
private Integer waterColor = null;
|
||||
|
||||
@Value("colors.water-fog")
|
||||
@Default
|
||||
private Integer waterFogColor = null;
|
||||
|
||||
@Value("colors.foliage")
|
||||
@Default
|
||||
private Integer foliageColor = null;
|
||||
|
||||
@Value("colors.sky")
|
||||
@Default
|
||||
private Integer skyColor = null;
|
||||
|
||||
@Value("colors.modifier")
|
||||
@Default
|
||||
private GrassColorModifier modifier = null;
|
||||
|
||||
@Value("climate.precipitation")
|
||||
@Default
|
||||
private Precipitation precipitation = null;
|
||||
|
||||
public Integer getFogColor() {
|
||||
return fogColor;
|
||||
}
|
||||
|
||||
public Integer getFoliageColor() {
|
||||
return foliageColor;
|
||||
}
|
||||
|
||||
public Integer getGrassColor() {
|
||||
return grassColor;
|
||||
}
|
||||
|
||||
public Integer getWaterColor() {
|
||||
return waterColor;
|
||||
}
|
||||
|
||||
public Integer getWaterFogColor() {
|
||||
return waterFogColor;
|
||||
}
|
||||
|
||||
public Integer getSkyColor() {
|
||||
return skyColor;
|
||||
}
|
||||
|
||||
public Precipitation getPrecipitation() {
|
||||
return precipitation;
|
||||
}
|
||||
|
||||
public GrassColorModifier getModifier() {
|
||||
return modifier;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.dfsek.terra.forge.data;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.generation.TerraBiomeSource;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.util.dynamic.RegistryOps;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
|
||||
|
||||
public final class Codecs {
|
||||
public static final Codec<RegistryKey> TERRA_REGISTRY_KEY = RecordCodecBuilder
|
||||
.create(registryKey -> registryKey.group(Codec.STRING.fieldOf("namespace")
|
||||
.stable()
|
||||
.forGetter(RegistryKey::getNamespace),
|
||||
Codec.STRING.fieldOf("id")
|
||||
.stable()
|
||||
.forGetter(RegistryKey::getID))
|
||||
.apply(registryKey, registryKey.stable(RegistryKey::of)));
|
||||
|
||||
public static final Codec<ConfigPack> CONFIG_PACK = RecordCodecBuilder
|
||||
.create(config -> config.group(TERRA_REGISTRY_KEY.fieldOf("pack")
|
||||
.stable()
|
||||
.forGetter(ConfigPack::getRegistryKey))
|
||||
.apply(config, config.stable(id -> ForgeEntryPoint.getPlatform()
|
||||
.getConfigRegistry()
|
||||
.get(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException(
|
||||
"No such config pack " +
|
||||
id)))));
|
||||
|
||||
public static final Codec<TerraBiomeSource> TERRA_BIOME_SOURCE = RecordCodecBuilder
|
||||
.create(instance -> instance.group(RegistryOps.createRegistryCodec(Registry.BIOME_KEY)
|
||||
.fieldOf("biome_registry")
|
||||
.stable()
|
||||
.forGetter(TerraBiomeSource::getBiomeRegistry),
|
||||
CONFIG_PACK.fieldOf("pack")
|
||||
.stable()
|
||||
.forGetter(TerraBiomeSource::getPack))
|
||||
.apply(instance, instance.stable(TerraBiomeSource::new)));
|
||||
|
||||
public static final Codec<ForgeChunkGeneratorWrapper> FORGE_CHUNK_GENERATOR_WRAPPER = RecordCodecBuilder
|
||||
.create(
|
||||
instance -> instance.group(
|
||||
RegistryOps.createRegistryCodec(Registry.STRUCTURE_SET_KEY)
|
||||
.fieldOf("structure_registry")
|
||||
.stable()
|
||||
.forGetter(ForgeChunkGeneratorWrapper::getNoiseRegistry),
|
||||
TERRA_BIOME_SOURCE.fieldOf("biome_source")
|
||||
.stable()
|
||||
.forGetter(ForgeChunkGeneratorWrapper::getBiomeSource),
|
||||
CONFIG_PACK.fieldOf("pack")
|
||||
.stable()
|
||||
.forGetter(ForgeChunkGeneratorWrapper::getPack),
|
||||
ChunkGeneratorSettings.REGISTRY_CODEC.fieldOf("settings")
|
||||
.stable()
|
||||
.forGetter(ForgeChunkGeneratorWrapper::getSettings)
|
||||
).apply(instance, instance.stable(ForgeChunkGeneratorWrapper::new))
|
||||
);
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.generation;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.structure.StructureSet;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.random.CheckedRandom;
|
||||
import net.minecraft.util.math.random.ChunkRandom;
|
||||
import net.minecraft.util.math.random.RandomSeed;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.HeightLimitView;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.gen.GenerationStep.Carver;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.StructureWeightSampler;
|
||||
import net.minecraft.world.gen.chunk.Blender;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
||||
import net.minecraft.world.gen.densityfunction.DensityFunction.UnblendedNoisePos;
|
||||
import net.minecraft.world.gen.noise.NoiseConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.Chunkified;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.data.Codecs;
|
||||
import com.dfsek.terra.forge.mixin.access.StructureAccessorAccessor;
|
||||
import com.dfsek.terra.forge.util.ForgeAdapter;
|
||||
|
||||
|
||||
public class ForgeChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.ChunkGenerator implements GeneratorWrapper {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ForgeChunkGeneratorWrapper.class);
|
||||
|
||||
private final TerraBiomeSource biomeSource;
|
||||
private final Registry<StructureSet> noiseRegistry;
|
||||
private final RegistryEntry<ChunkGeneratorSettings> settings;
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
|
||||
public ForgeChunkGeneratorWrapper(Registry<StructureSet> noiseRegistry, TerraBiomeSource biomeSource, ConfigPack configPack,
|
||||
RegistryEntry<ChunkGeneratorSettings> settingsSupplier) {
|
||||
super(noiseRegistry, Optional.empty(), biomeSource);
|
||||
this.noiseRegistry = noiseRegistry;
|
||||
this.pack = configPack;
|
||||
this.settings = settingsSupplier;
|
||||
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
logger.info("Loading world with config pack {}", pack.getID());
|
||||
this.biomeSource = biomeSource;
|
||||
}
|
||||
|
||||
public Registry<StructureSet> getNoiseRegistry() {
|
||||
return noiseRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() {
|
||||
return Codecs.FORGE_CHUNK_GENERATOR_WRAPPER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildSurface(ChunkRegion region, StructureAccessor structures, NoiseConfig noiseConfig, Chunk chunk) {
|
||||
// no op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateEntities(ChunkRegion region) {
|
||||
if(!this.settings.value().mobGenerationDisabled()) {
|
||||
ChunkPos chunkPos = region.getCenterPos();
|
||||
RegistryEntry<Biome> registryEntry = region.getBiome(chunkPos.getStartPos().withY(region.getTopY() - 1));
|
||||
ChunkRandom chunkRandom = new ChunkRandom(new CheckedRandom(RandomSeed.getSeed()));
|
||||
chunkRandom.setPopulationSeed(region.getSeed(), chunkPos.getStartX(), chunkPos.getStartZ());
|
||||
SpawnHelper.populateEntities(region, registryEntry, chunkPos, chunkRandom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWorldHeight() {
|
||||
return settings.value().generationShapeConfig().height();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender, NoiseConfig noiseConfig,
|
||||
StructureAccessor structureAccessor, Chunk chunk) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
ProtoWorld world = (ProtoWorld) ((StructureAccessorAccessor) structureAccessor).getWorld();
|
||||
BiomeProvider biomeProvider = pack.getBiomeProvider();
|
||||
delegate.generateChunkData((ProtoChunk) chunk, world, biomeProvider, chunk.getPos().x, chunk.getPos().z);
|
||||
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class);
|
||||
if(compatibilityOptions.isBeard()) {
|
||||
beard(structureAccessor, chunk, world, biomeProvider, compatibilityOptions);
|
||||
}
|
||||
return chunk;
|
||||
}, Util.getMainWorkerExecutor());
|
||||
}
|
||||
|
||||
private void beard(StructureAccessor structureAccessor, Chunk chunk, WorldProperties world, BiomeProvider biomeProvider,
|
||||
PreLoadCompatibilityOptions compatibilityOptions) {
|
||||
StructureWeightSampler structureWeightSampler = StructureWeightSampler.method_42695(structureAccessor, chunk.getPos());
|
||||
double threshold = compatibilityOptions.getBeardThreshold();
|
||||
double airThreshold = compatibilityOptions.getAirThreshold();
|
||||
int xi = chunk.getPos().x << 4;
|
||||
int zi = chunk.getPos().z << 4;
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
int depth = 0;
|
||||
for(int y = world.getMaxHeight(); y >= world.getMinHeight(); y--) {
|
||||
double noise = structureWeightSampler.sample(new UnblendedNoisePos(x + xi, y, z + zi));
|
||||
if(noise > threshold) {
|
||||
chunk.setBlockState(new BlockPos(x, y, z), (BlockState) delegate
|
||||
.getPalette(x + xi, y, z + zi, world, biomeProvider)
|
||||
.get(depth, x + xi, y, z + zi, world.getSeed()), false);
|
||||
depth++;
|
||||
} else if(noise < airThreshold) {
|
||||
chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.getDefaultState(), false);
|
||||
} else {
|
||||
depth = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFeatures(StructureWorldAccess world, Chunk chunk, StructureAccessor structureAccessor) {
|
||||
super.generateFeatures(world, chunk, structureAccessor);
|
||||
pack.getStages().forEach(populator -> {
|
||||
if(!(populator instanceof Chunkified)) {
|
||||
populator.populate((ProtoWorld) world);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeaLevel() {
|
||||
return settings.value().seaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumY() {
|
||||
return settings.value().generationShapeConfig().minimumY();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Type heightmap, HeightLimitView height, NoiseConfig noiseConfig) {
|
||||
WorldProperties properties = ForgeAdapter.adapt(height, noiseConfig.getLegacyWorldSeed());
|
||||
BiomeProvider biomeProvider = pack.getBiomeProvider();
|
||||
int min = height.getBottomY();
|
||||
for(int y = height.getTopY() - 1; y >= min; y--) {
|
||||
if(heightmap
|
||||
.getBlockPredicate()
|
||||
.test((BlockState) delegate.getBlock(properties, x, y, z, biomeProvider))) return y + 1;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView height, NoiseConfig noiseConfig) {
|
||||
BlockState[] array = new BlockState[height.getHeight()];
|
||||
WorldProperties properties = ForgeAdapter.adapt(height, noiseConfig.getLegacyWorldSeed());
|
||||
BiomeProvider biomeProvider = pack.getBiomeProvider();
|
||||
for(int y = height.getTopY() - 1; y >= height.getBottomY(); y--) {
|
||||
array[y - height.getBottomY()] = (BlockState) delegate.getBlock(properties, x, y, z, biomeProvider);
|
||||
}
|
||||
return new VerticalBlockSample(height.getBottomY(), array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDebugHudText(List<String> text, NoiseConfig noiseConfig, BlockPos pos) {
|
||||
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
biomeSource.setPack(pack);
|
||||
|
||||
logger.debug("Loading world with config pack {}", pack.getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void carve(ChunkRegion chunkRegion, long seed, NoiseConfig noiseConfig, BiomeAccess world, StructureAccessor structureAccessor,
|
||||
Chunk chunk, Carver carverStep) {
|
||||
// no op
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public RegistryEntry<ChunkGeneratorSettings> getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraBiomeSource getBiomeSource() {
|
||||
return biomeSource;
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.generation;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.forge.data.Codecs;
|
||||
import com.dfsek.terra.forge.util.ProtoPlatformBiome;
|
||||
|
||||
import com.dfsek.terra.forge.util.SeedHack;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
|
||||
public class TerraBiomeSource extends BiomeSource {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TerraBiomeSource.class);
|
||||
private final Registry<net.minecraft.world.biome.Biome> biomeRegistry;
|
||||
private ConfigPack pack;
|
||||
|
||||
public TerraBiomeSource(Registry<net.minecraft.world.biome.Biome> biomes, ConfigPack pack) {
|
||||
super(StreamSupport
|
||||
.stream(pack.getBiomeProvider()
|
||||
.getBiomes()
|
||||
.spliterator(), false)
|
||||
.map(b -> biomes.getOrCreateEntry(((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate())));
|
||||
this.biomeRegistry = biomes;
|
||||
this.pack = pack;
|
||||
|
||||
LOGGER.debug("Biomes: " + getBiomes());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends BiomeSource> getCodec() {
|
||||
return Codecs.TERRA_BIOME_SOURCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryEntry<net.minecraft.world.biome.Biome> getBiome(int biomeX, int biomeY, int biomeZ, MultiNoiseSampler noiseSampler) {
|
||||
return biomeRegistry
|
||||
.entryOf(((ProtoPlatformBiome) pack
|
||||
.getBiomeProvider()
|
||||
.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2, SeedHack.getSeed(noiseSampler))
|
||||
.getPlatformBiome()).getDelegate()
|
||||
);
|
||||
}
|
||||
|
||||
public BiomeProvider getProvider() {
|
||||
return pack.getBiomeProvider();
|
||||
}
|
||||
|
||||
public Registry<net.minecraft.world.biome.Biome> getBiomeRegistry() {
|
||||
return biomeRegistry;
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.handle;
|
||||
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.CommandRegistryAccess;
|
||||
import net.minecraft.command.argument.ItemStackArgumentType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
|
||||
|
||||
public class ForgeItemHandle implements ItemHandle {
|
||||
|
||||
@Override
|
||||
public Item createItem(String data) {
|
||||
try {
|
||||
return (Item) new ItemStackArgumentType(new CommandRegistryAccess(
|
||||
ForgeEntryPoint.getPlatform().getServer().getRegistryManager())).parse(new StringReader(data)).getItem();
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment(String id) {
|
||||
return (Enchantment) (Registry.ENCHANTMENT.get(Identifier.tryParse(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return Registry.ENCHANTMENT.stream().map(enchantment -> (Enchantment) enchantment).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.access;
|
||||
|
||||
import net.minecraft.world.MobSpawnerEntry;
|
||||
import net.minecraft.world.MobSpawnerLogic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
|
||||
@Mixin(MobSpawnerLogic.class)
|
||||
public interface MobSpawnerLogicAccessor {
|
||||
@Accessor("spawnEntry")
|
||||
MobSpawnerEntry getSpawnEntry();
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.access;
|
||||
|
||||
import net.minecraft.state.State;
|
||||
import net.minecraft.state.property.Property;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
@Mixin(State.class)
|
||||
public interface StateAccessor {
|
||||
@Accessor("PROPERTY_MAP_PRINTER")
|
||||
static Function<Map.Entry<Property<?>, Comparable<?>>, String> getPropertyMapPrinter() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.access;
|
||||
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
|
||||
@Mixin(StructureAccessor.class)
|
||||
public interface StructureAccessorAccessor {
|
||||
@Accessor
|
||||
WorldAccess getWorld();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.fix;
|
||||
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
|
||||
import net.minecraft.entity.passive.BeeEntity.MoveToFlowerGoal;
|
||||
import net.minecraft.entity.passive.BeeEntity.MoveToHiveGoal;
|
||||
import net.minecraft.util.math.random.CheckedRandom;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
|
||||
/**
|
||||
* Bees spawning uses world.random without synchronization. This causes issues when spawning bees during world generation.
|
||||
*/
|
||||
@Mixin({
|
||||
MoveToHiveGoal.class,
|
||||
MoveToFlowerGoal.class
|
||||
})
|
||||
public class BeeMoveGoalsUnsynchronizedRandomAccessFix {
|
||||
@Redirect(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;random:Lnet/minecraft/util/math/random/Random;"))
|
||||
public Random redirectRandomAccess(World instance) {
|
||||
return new CheckedRandom(ForgeEntryPoint.getPlatform().getServer().getTicks()); // replace with new random seeded by tick time.
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.fix;
|
||||
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
|
||||
import net.minecraft.world.gen.structure.NetherFossilStructure;
|
||||
import net.minecraft.world.gen.structure.Structure.Context;
|
||||
import net.minecraft.world.gen.structure.Structure.StructurePosition;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
/**
|
||||
* Disable fossil generation in Terra worlds, as they are very expensive due to consistently triggering cache misses.
|
||||
*
|
||||
* Currently, on Forge, Terra cannot be specified as a Nether generator. TODO: logic to turn fossils back on if chunk generator is in nether.
|
||||
*/
|
||||
@Mixin(NetherFossilStructure.class)
|
||||
public class NetherFossilOptimization {
|
||||
@Inject(method = "getStructurePosition", at = @At("HEAD"), cancellable = true)
|
||||
public void injectFossilPositions(Context context, CallbackInfoReturnable<Optional<StructurePosition>> cir) {
|
||||
if(context.chunkGenerator() instanceof ForgeChunkGeneratorWrapper) {
|
||||
cir.setReturnValue(Optional.empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.compat;
|
||||
|
||||
import com.dfsek.terra.forge.mixin_ifaces.FloraFeatureHolder;
|
||||
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Mixin(GenerationSettings.class)
|
||||
@Implements(@Interface(iface = FloraFeatureHolder.class, prefix = "terra$"))
|
||||
public class GenerationSettingsFloraFeaturesMixin {
|
||||
private List<ConfiguredFeature<?, ?>> flora;
|
||||
|
||||
public void terra$setFloraFeatures(List<ConfiguredFeature<?, ?>> features) {
|
||||
this.flora = features;
|
||||
}
|
||||
|
||||
@Inject(method = "getFlowerFeatures", cancellable = true, at = @At("HEAD"))
|
||||
public void inject(CallbackInfoReturnable<List<ConfiguredFeature<?, ?>>> cir) {
|
||||
if(flora != null) {
|
||||
cir.setReturnValue(flora);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra;
|
||||
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
|
||||
@Mixin(Biome.class)
|
||||
@Implements(@Interface(iface = PlatformBiome.class, prefix = "terra$"))
|
||||
public abstract class BiomeMixin {
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.chunk.ProtoChunk;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
|
||||
/**
|
||||
* A ton of Minecraft classes must implement Handle identically, we can just take care of it here
|
||||
*/
|
||||
@Mixin({
|
||||
ServerWorld.class,
|
||||
ChunkRegion.class,
|
||||
|
||||
Block.class,
|
||||
BlockState.class,
|
||||
|
||||
BlockEntity.class,
|
||||
LootableContainerBlockEntity.class,
|
||||
LockableContainerBlockEntity.class,
|
||||
|
||||
ProtoChunk.class,
|
||||
WorldChunk.class,
|
||||
|
||||
Entity.class,
|
||||
EntityType.class,
|
||||
|
||||
ServerCommandSource.class,
|
||||
|
||||
Item.class,
|
||||
ItemStack.class,
|
||||
Enchantment.class,
|
||||
|
||||
Biome.class
|
||||
})
|
||||
@Implements(@Interface(iface = Handle.class, prefix = "terra$"))
|
||||
public class HandleImplementationMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
|
||||
|
||||
@Mixin(Block.class)
|
||||
@Implements(@Interface(iface = BlockType.class, prefix = "terra$"))
|
||||
public abstract class BlockMixin {
|
||||
public com.dfsek.terra.api.block.state.BlockState terra$getDefaultState() {
|
||||
return (com.dfsek.terra.api.block.state.BlockState) ((Block) (Object) this).getDefaultState();
|
||||
}
|
||||
|
||||
public boolean terra$isSolid() {
|
||||
return ((Block) (Object) this).getDefaultState().isOpaque();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public boolean terra$isWater() {
|
||||
return ((Object) this) == Blocks.WATER;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.block.entity;
|
||||
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
|
||||
|
||||
@Mixin(net.minecraft.block.entity.BlockEntity.class)
|
||||
@Implements(@Interface(iface = BlockEntity.class, prefix = "terra$"))
|
||||
public abstract class BlockEntityMixin {
|
||||
public boolean terra$update(boolean applyPhysics) {
|
||||
if(((net.minecraft.block.entity.BlockEntity) (Object) this).hasWorld()) //noinspection ConstantConditions
|
||||
((net.minecraft.block.entity.BlockEntity) (Object) this).getWorld().getChunk(
|
||||
((net.minecraft.block.entity.BlockEntity) (Object) this).getPos()).setBlockEntity(
|
||||
(net.minecraft.block.entity.BlockEntity) (Object) this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int terra$getX() {
|
||||
return ((net.minecraft.block.entity.BlockEntity) (Object) this).getPos().getX();
|
||||
}
|
||||
|
||||
public int terra$getY() {
|
||||
return ((net.minecraft.block.entity.BlockEntity) (Object) this).getPos().getY();
|
||||
}
|
||||
|
||||
public int terra$getZ() {
|
||||
return ((net.minecraft.block.entity.BlockEntity) (Object) this).getPos().getZ();
|
||||
}
|
||||
|
||||
public BlockState terra$getBlockState() {
|
||||
return (BlockState) ((net.minecraft.block.entity.BlockEntity) (Object) this).getCachedState();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.block.entity;
|
||||
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.Container;
|
||||
import com.dfsek.terra.api.inventory.Inventory;
|
||||
|
||||
|
||||
@Mixin(LootableContainerBlockEntity.class)
|
||||
@Implements(@Interface(iface = Container.class, prefix = "terra$"))
|
||||
public abstract class LootableContainerBlockEntityMixin extends BlockEntityMixin {
|
||||
public Inventory terra$getInventory() {
|
||||
return (Inventory) this;
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.block.entity;
|
||||
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
import com.dfsek.terra.forge.mixin.access.MobSpawnerLogicAccessor;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.MobSpawnerLogic;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.MobSpawner;
|
||||
import com.dfsek.terra.api.block.entity.SerialState;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
|
||||
|
||||
@Mixin(MobSpawnerBlockEntity.class)
|
||||
@Implements(@Interface(iface = MobSpawner.class, prefix = "terra$"))
|
||||
public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
private MobSpawnerBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
public abstract MobSpawnerLogic getLogic();
|
||||
|
||||
public EntityType terra$getSpawnedType() {
|
||||
return (EntityType) Registry.ENTITY_TYPE.get(
|
||||
Identifier.tryParse(((MobSpawnerLogicAccessor) getLogic()).getSpawnEntry().getNbt().getString("id")));
|
||||
}
|
||||
|
||||
public void terra$setSpawnedType(@NotNull EntityType creatureType) {
|
||||
getLogic().setEntityId((net.minecraft.entity.EntityType<?>) creatureType);
|
||||
}
|
||||
|
||||
public int terra$getDelay() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setDelay(int delay) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMinSpawnDelay() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setMinSpawnDelay(int delay) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMaxSpawnDelay() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setMaxSpawnDelay(int delay) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getSpawnCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setSpawnCount(int spawnCount) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getMaxNearbyEntities() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setMaxNearbyEntities(int maxNearbyEntities) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getRequiredPlayerRange() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setRequiredPlayerRange(int requiredPlayerRange) {
|
||||
|
||||
}
|
||||
|
||||
public int terra$getSpawnRange() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void terra$setSpawnRange(int spawnRange) {
|
||||
|
||||
}
|
||||
|
||||
public void terra$applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type" -> terra$setSpawnedType(ForgeEntryPoint.getPlatform().getWorldHandle().getEntity(v));
|
||||
case "delay" -> terra$setDelay(Integer.parseInt(v));
|
||||
case "min_delay" -> terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
case "max_delay" -> terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
case "spawn_count" -> terra$setSpawnCount(Integer.parseInt(v));
|
||||
case "spawn_range" -> terra$setSpawnRange(Integer.parseInt(v));
|
||||
case "max_nearby" -> terra$setMaxNearbyEntities(Integer.parseInt(v));
|
||||
case "required_player_range" -> terra$setRequiredPlayerRange(Integer.parseInt(v));
|
||||
default -> throw new IllegalArgumentException("Invalid property: " + k);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.block.entity;
|
||||
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.SerialState;
|
||||
import com.dfsek.terra.api.block.entity.Sign;
|
||||
|
||||
|
||||
@Mixin(SignBlockEntity.class)
|
||||
@Implements(@Interface(iface = Sign.class, prefix = "terra$"))
|
||||
public abstract class SignBlockEntityMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private Text[] texts;
|
||||
|
||||
@Shadow
|
||||
public abstract void setTextOnRow(int row, Text text);
|
||||
|
||||
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||
setTextOnRow(index, Text.literal(line));
|
||||
}
|
||||
|
||||
public @NotNull String[] terra$getLines() {
|
||||
String[] lines = new String[texts.length];
|
||||
for(int i = 0; i < texts.length; i++) {
|
||||
lines[i] = texts[i].getString();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
|
||||
return texts[index].getString();
|
||||
}
|
||||
|
||||
public void terra$applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k);
|
||||
terra$setLine(Integer.parseInt(k.substring(4)), v);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.block.state;
|
||||
|
||||
|
||||
import com.dfsek.terra.forge.mixin.access.StateAccessor;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.block.AbstractBlock.AbstractBlockState;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.state.State;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
|
||||
@Mixin(AbstractBlockState.class)
|
||||
@Implements(@Interface(iface = BlockState.class, prefix = "terra$"))
|
||||
public abstract class BlockStateMixin extends State<Block, net.minecraft.block.BlockState> {
|
||||
private BlockStateMixin(Block owner, ImmutableMap<net.minecraft.state.property.Property<?>, Comparable<?>> entries,
|
||||
MapCodec<net.minecraft.block.BlockState> codec) {
|
||||
super(owner, entries, codec);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
public abstract Block getBlock();
|
||||
|
||||
@Shadow
|
||||
public abstract boolean isAir();
|
||||
|
||||
public boolean terra$matches(BlockState other) {
|
||||
return getBlock() == ((net.minecraft.block.BlockState) other).getBlock();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public <T extends Comparable<T>> boolean terra$has(Property<T> property) {
|
||||
if(property instanceof net.minecraft.state.property.Property<?> minecraftProperty) {
|
||||
return contains(minecraftProperty);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Intrinsic
|
||||
public <T extends Comparable<T>> T terra$get(Property<T> property) {
|
||||
return get((net.minecraft.state.property.Property<T>) property);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Intrinsic
|
||||
public <T extends Comparable<T>> BlockState terra$set(Property<T> property, T value) {
|
||||
return (BlockState) with((net.minecraft.state.property.Property<T>) property, value);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public BlockType terra$getBlockType() {
|
||||
return (BlockType) getBlock();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public String terra$getAsString(boolean properties) {
|
||||
StringBuilder data = new StringBuilder(Registry.BLOCK.getId(getBlock()).toString());
|
||||
if(properties && !getEntries().isEmpty()) {
|
||||
data.append('[');
|
||||
data.append(
|
||||
getEntries().entrySet().stream().map(StateAccessor.getPropertyMapPrinter()).collect(Collectors.joining(",")));
|
||||
data.append(']');
|
||||
}
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public boolean terra$isAir() {
|
||||
return isAir();
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.block.state;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Interface.Remap;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
|
||||
@Mixin(net.minecraft.state.property.Property.class)
|
||||
@Implements(@Interface(iface = Property.class, prefix = "terra$", remap = Remap.NONE))
|
||||
public abstract class PropertyMixin<T> {
|
||||
@Shadow
|
||||
@Final
|
||||
private Class<T> type;
|
||||
@Shadow
|
||||
@Final
|
||||
private String name;
|
||||
|
||||
@Shadow
|
||||
public abstract Collection<T> getValues();
|
||||
|
||||
@Intrinsic
|
||||
public Collection<T> terra$values() {
|
||||
return getValues();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Class<T> terra$getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public String terra$getID() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.chunk;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
|
||||
|
||||
@Mixin(ChunkRegion.class)
|
||||
@Implements(@Interface(iface = Chunk.class, prefix = "terraChunk$"))
|
||||
public abstract class ChunkRegionMixin {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private net.minecraft.world.chunk.Chunk centerPos;
|
||||
|
||||
public void terraChunk$setBlock(int x, int y, int z, @NotNull BlockState blockState, boolean physics) {
|
||||
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerPos.getPos().x << 4), y, z + (centerPos.getPos().z << 4)),
|
||||
(net.minecraft.block.BlockState) blockState, 0);
|
||||
}
|
||||
|
||||
public @NotNull BlockState terraChunk$getBlock(int x, int y, int z) {
|
||||
return (BlockState) ((ChunkRegion) (Object) this).getBlockState(
|
||||
new BlockPos(x + (centerPos.getPos().x << 4), y, z + (centerPos.getPos().z << 4)));
|
||||
}
|
||||
|
||||
public int terraChunk$getX() {
|
||||
return centerPos.getPos().x;
|
||||
}
|
||||
|
||||
public int terraChunk$getZ() {
|
||||
return centerPos.getPos().z;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.chunk;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
|
||||
|
||||
@Mixin(WorldChunk.class)
|
||||
@Implements(@Interface(iface = Chunk.class, prefix = "terra$"))
|
||||
public abstract class WorldChunkMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
net.minecraft.world.World world;
|
||||
|
||||
@Shadow
|
||||
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public abstract net.minecraft.block.BlockState setBlockState(BlockPos pos, net.minecraft.block.BlockState state, boolean moved);
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, BlockState data, boolean physics) {
|
||||
setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) data, false);
|
||||
}
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState,
|
||||
false);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
|
||||
return (BlockState) getBlockState(new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public int terra$getX() {
|
||||
return ((net.minecraft.world.chunk.Chunk) (Object) this).getPos().x;
|
||||
}
|
||||
|
||||
public int terra$getZ() {
|
||||
return ((net.minecraft.world.chunk.Chunk) (Object) this).getPos().z;
|
||||
}
|
||||
|
||||
public ServerWorld terra$getWorld() {
|
||||
return (ServerWorld) world;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.chunk.data;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.HeightLimitView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
|
||||
@Mixin(net.minecraft.world.chunk.ProtoChunk.class)
|
||||
@Implements(@Interface(iface = ProtoChunk.class, prefix = "terra$"))
|
||||
public abstract class ProtoChunkMixin {
|
||||
@Shadow
|
||||
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);
|
||||
|
||||
@Shadow
|
||||
public abstract HeightLimitView getHeightLimitView();
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState,
|
||||
false);
|
||||
}
|
||||
|
||||
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
|
||||
return (BlockState) getBlockState(new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public int terra$getMaxHeight() {
|
||||
return getHeightLimitView().getTopY();
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.entity;
|
||||
|
||||
import com.dfsek.terra.forge.util.ForgeAdapter;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
|
||||
|
||||
@Mixin(Entity.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.entity.Entity.class, prefix = "terra$"))
|
||||
public abstract class EntityMixin {
|
||||
@Shadow
|
||||
public net.minecraft.world.World world;
|
||||
|
||||
@Shadow
|
||||
private BlockPos blockPos;
|
||||
|
||||
@Shadow
|
||||
public abstract void teleport(double destX, double destY, double destZ);
|
||||
|
||||
public Vector3 terra$position() {
|
||||
return ForgeAdapter.adapt(blockPos);
|
||||
}
|
||||
|
||||
public void terra$position(Vector3 location) {
|
||||
teleport(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public ServerWorld terra$world() {
|
||||
return (ServerWorld) world;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.entity;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
|
||||
@Mixin(EntityType.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.entity.EntityType.class, prefix = "terra$"))
|
||||
public abstract class EntityTypeMixin {
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.entity;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
|
||||
|
||||
@Mixin(PlayerEntity.class)
|
||||
@Implements(@Interface(iface = Player.class, prefix = "terra$"))
|
||||
public abstract class PlayerEntityMixin extends EntityMixin {
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.entity;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
|
||||
|
||||
@Mixin(ServerCommandSource.class)
|
||||
@Implements(@Interface(iface = CommandSender.class, prefix = "terra$"))
|
||||
public abstract class ServerCommandSourceMixin {
|
||||
@Shadow
|
||||
public abstract void sendFeedback(Text message, boolean broadcastToOps);
|
||||
|
||||
@Shadow
|
||||
public abstract ServerPlayerEntity getPlayer() throws CommandSyntaxException;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public abstract net.minecraft.entity.@Nullable Entity getEntity();
|
||||
|
||||
public void terra$sendMessage(String message) {
|
||||
sendFeedback(Text.literal(message), true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Optional<Entity> terra$getEntity() {
|
||||
return Optional.ofNullable((Entity) getEntity());
|
||||
}
|
||||
|
||||
public Optional<Player> terra$getPlayer() {
|
||||
try {
|
||||
return Optional.ofNullable((Player) getPlayer());
|
||||
} catch(CommandSyntaxException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.inventory;
|
||||
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.item.Items;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.inventory.Inventory;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
|
||||
|
||||
@Mixin(LockableContainerBlockEntity.class)
|
||||
@Implements(@Interface(iface = Inventory.class, prefix = "terra$"))
|
||||
public class LockableContainerBlockEntityMixin {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void terra$setItem(int slot, ItemStack newStack) {
|
||||
((LockableContainerBlockEntity) (Object) this).setStack(slot, (net.minecraft.item.ItemStack) (Object) newStack);
|
||||
}
|
||||
|
||||
public int terra$getSize() {
|
||||
return ((LockableContainerBlockEntity) (Object) this).size();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public ItemStack terra$getItem(int slot) {
|
||||
net.minecraft.item.ItemStack itemStack = ((LockableContainerBlockEntity) (Object) this).getStack(slot);
|
||||
return itemStack.getItem() == Items.AIR ? null : (ItemStack) (Object) itemStack;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.inventory.item;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
|
||||
|
||||
@Mixin(Item.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.inventory.Item.class, prefix = "terra$"))
|
||||
public abstract class ItemMixin {
|
||||
@Shadow
|
||||
public abstract int getMaxDamage();
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public ItemStack terra$newItemStack(int amount) {
|
||||
return (ItemStack) (Object) new net.minecraft.item.ItemStack((Item) (Object) this, amount);
|
||||
}
|
||||
|
||||
public double terra$getMaxDurability() {
|
||||
return getMaxDamage();
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.inventory.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.inventory.ItemStack.class, prefix = "terra$"))
|
||||
public abstract class ItemStackMixin {
|
||||
@Shadow
|
||||
public abstract int getCount();
|
||||
|
||||
@Shadow
|
||||
public abstract void setCount(int count);
|
||||
|
||||
@Shadow
|
||||
public abstract net.minecraft.item.Item getItem();
|
||||
|
||||
@Shadow
|
||||
public abstract boolean isDamageable();
|
||||
|
||||
@Shadow
|
||||
public abstract void setNbt(@Nullable NbtCompound tag);
|
||||
|
||||
public int terra$getAmount() {
|
||||
return getCount();
|
||||
}
|
||||
|
||||
public void terra$setAmount(int i) {
|
||||
setCount(i);
|
||||
}
|
||||
|
||||
public Item terra$getType() {
|
||||
return (Item) getItem();
|
||||
}
|
||||
|
||||
public ItemMeta terra$getItemMeta() {
|
||||
return (ItemMeta) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void terra$setItemMeta(ItemMeta meta) {
|
||||
setNbt(((ItemStack) (Object) meta).getNbt());
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public boolean terra$isDamageable() {
|
||||
return isDamageable();
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.inventory.meta;
|
||||
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
|
||||
|
||||
@Mixin(Enchantment.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.inventory.item.Enchantment.class, prefix = "terra$"))
|
||||
public abstract class EnchantmentMixin {
|
||||
@Shadow
|
||||
public abstract boolean isAcceptableItem(net.minecraft.item.ItemStack stack);
|
||||
|
||||
@Shadow
|
||||
public abstract boolean canCombine(Enchantment other);
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public boolean terra$canEnchantItem(ItemStack itemStack) {
|
||||
return isAcceptableItem((net.minecraft.item.ItemStack) (Object) itemStack);
|
||||
}
|
||||
|
||||
public boolean terra$conflictsWith(com.dfsek.terra.api.inventory.item.Enchantment other) {
|
||||
return !canCombine((Enchantment) other);
|
||||
}
|
||||
|
||||
public String terra$getID() {
|
||||
return Objects.requireNonNull(Registry.ENCHANTMENT.getId((Enchantment) (Object) this)).toString();
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.inventory.meta;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.inventory.item.Damageable;
|
||||
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
@Implements(@Interface(iface = Damageable.class, prefix = "terra$"))
|
||||
public abstract class ItemStackDamageableMixin {
|
||||
@Shadow
|
||||
public abstract boolean isDamaged();
|
||||
|
||||
@Shadow
|
||||
public abstract int getDamage();
|
||||
|
||||
@Shadow
|
||||
public abstract void setDamage(int damage);
|
||||
|
||||
@Intrinsic
|
||||
public int terra$getDamage() {
|
||||
return getDamage();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public void terra$setDamage(int damage) {
|
||||
setDamage(damage);
|
||||
}
|
||||
|
||||
public boolean terra$hasDamage() {
|
||||
return isDamaged();
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.inventory.meta;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
@Implements(@Interface(iface = ItemMeta.class, prefix = "terra$"))
|
||||
public abstract class ItemStackMetaMixin {
|
||||
@Shadow
|
||||
public abstract boolean hasEnchantments();
|
||||
|
||||
@Shadow
|
||||
public abstract NbtList getEnchantments();
|
||||
|
||||
@Shadow
|
||||
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level);
|
||||
|
||||
public void terra$addEnchantment(Enchantment enchantment, int level) {
|
||||
addEnchantment((net.minecraft.enchantment.Enchantment) enchantment, level);
|
||||
}
|
||||
|
||||
@Intrinsic(displace = true)
|
||||
public Map<Enchantment, Integer> terra$getEnchantments() {
|
||||
if(!hasEnchantments()) return Collections.emptyMap();
|
||||
Map<Enchantment, Integer> map = new HashMap<>();
|
||||
|
||||
getEnchantments().forEach(enchantment -> {
|
||||
NbtCompound eTag = (NbtCompound) enchantment;
|
||||
map.put((Enchantment) Registry.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl"));
|
||||
});
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mixins in this package implement Terra
|
||||
* interfaces in Minecraft classes.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra;
|
||||
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.world;
|
||||
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.world.tick.MultiTickScheduler;
|
||||
import net.minecraft.world.tick.OrderedTick;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||
import com.dfsek.terra.forge.util.ForgeUtil;
|
||||
|
||||
|
||||
@Mixin(ChunkRegion.class)
|
||||
@Implements(@Interface(iface = ProtoWorld.class, prefix = "terraWorld$"))
|
||||
public abstract class ChunkRegionMixin {
|
||||
private ConfigPack terra$config;
|
||||
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private net.minecraft.server.world.ServerWorld world;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private long seed;
|
||||
@Shadow
|
||||
@Final
|
||||
private Chunk centerPos;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private MultiTickScheduler<Fluid> fluidTickScheduler;
|
||||
|
||||
|
||||
@Inject(at = @At("RETURN"),
|
||||
method = "<init>(Lnet/minecraft/server/world/ServerWorld;Ljava/util/List;Lnet/minecraft/world/chunk/ChunkStatus;I)V")
|
||||
public void injectConstructor(net.minecraft.server.world.ServerWorld world, List<net.minecraft.world.chunk.Chunk> list,
|
||||
ChunkStatus chunkStatus, int i,
|
||||
CallbackInfo ci) {
|
||||
this.terra$config = ((ServerWorld) world).getPack();
|
||||
}
|
||||
|
||||
|
||||
@Intrinsic(displace = true)
|
||||
public void terraWorld$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
((ChunkRegion) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data, physics ? 3 : 1042);
|
||||
if(physics && ((net.minecraft.block.BlockState) data).getBlock() instanceof FluidBlock) {
|
||||
fluidTickScheduler.scheduleTick(
|
||||
OrderedTick.create(((FluidBlock) ((net.minecraft.block.BlockState) data).getBlock()).getFluidState(
|
||||
(net.minecraft.block.BlockState) data).getFluid(), pos));
|
||||
}
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public long terraWorld$getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
public int terraWorld$getMaxHeight() {
|
||||
return world.getTopY();
|
||||
}
|
||||
|
||||
@Intrinsic(displace = true)
|
||||
public BlockState terraWorld$getBlockState(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return (BlockState) ((ChunkRegion) (Object) this).getBlockState(pos);
|
||||
}
|
||||
|
||||
public BlockEntity terraWorld$getBlockEntity(int x, int y, int z) {
|
||||
return ForgeUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public int terraWorld$getMinHeight() {
|
||||
return world.getBottomY();
|
||||
}
|
||||
|
||||
public ChunkGenerator terraWorld$getGenerator() {
|
||||
return ((ForgeChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator()).getHandle();
|
||||
}
|
||||
|
||||
public BiomeProvider terraWorld$getBiomeProvider() {
|
||||
return terra$config.getBiomeProvider();
|
||||
}
|
||||
|
||||
public Entity terraWorld$spawnEntity(double x, double y, double z, EntityType entityType) {
|
||||
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(world);
|
||||
entity.setPos(x, y, z);
|
||||
((ChunkRegion) (Object) this).spawnEntity(entity);
|
||||
return (Entity) entity;
|
||||
}
|
||||
|
||||
public int terraWorld$centerChunkX() {
|
||||
return centerPos.getPos().x;
|
||||
}
|
||||
|
||||
public int terraWorld$centerChunkZ() {
|
||||
return centerPos.getPos().z;
|
||||
}
|
||||
|
||||
public ServerWorld terraWorld$getWorld() {
|
||||
return (ServerWorld) world;
|
||||
}
|
||||
|
||||
public ConfigPack terraWorld$getPack() {
|
||||
return terra$config;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.mixin.implementations.terra.world;
|
||||
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.generation.TerraBiomeSource;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.forge.util.ForgeUtil;
|
||||
|
||||
|
||||
@Mixin(net.minecraft.server.world.ServerWorld.class)
|
||||
@Implements(@Interface(iface = ServerWorld.class, prefix = "terra$"))
|
||||
public abstract class ServerWorldMixin {
|
||||
public Entity terra$spawnEntity(double x, double y, double z, EntityType entityType) {
|
||||
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(null);
|
||||
entity.setPos(x, y, z);
|
||||
((net.minecraft.server.world.ServerWorld) (Object) this).spawnEntity(entity);
|
||||
return (Entity) entity;
|
||||
}
|
||||
|
||||
public void terra$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
((net.minecraft.server.world.ServerWorld) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data,
|
||||
physics ? 3 : 1042);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public long terra$getSeed() {
|
||||
return ((net.minecraft.server.world.ServerWorld) (Object) this).getSeed();
|
||||
}
|
||||
|
||||
public int terra$getMaxHeight() {
|
||||
return (((net.minecraft.server.world.ServerWorld) (Object) this).getBottomY()) +
|
||||
((net.minecraft.server.world.ServerWorld) (Object) this).getHeight();
|
||||
}
|
||||
|
||||
public Chunk terra$getChunkAt(int x, int z) {
|
||||
return (Chunk) ((net.minecraft.server.world.ServerWorld) (Object) this).getChunk(x, z);
|
||||
}
|
||||
|
||||
public BlockState terra$getBlockState(int x, int y, int z) {
|
||||
return (BlockState) ((net.minecraft.server.world.ServerWorld) (Object) this).getBlockState(new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public BlockEntity terra$getBlockEntity(int x, int y, int z) {
|
||||
return ForgeUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public int terra$getMinHeight() {
|
||||
return ((net.minecraft.server.world.ServerWorld) (Object) this).getBottomY();
|
||||
}
|
||||
|
||||
public ChunkGenerator terra$getGenerator() {
|
||||
return ((ForgeChunkGeneratorWrapper) ((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()
|
||||
.getChunkGenerator()).getHandle();
|
||||
}
|
||||
|
||||
public BiomeProvider terra$getBiomeProvider() {
|
||||
return ((TerraBiomeSource) ((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()
|
||||
.getChunkGenerator()
|
||||
.getBiomeSource()).getProvider();
|
||||
}
|
||||
|
||||
public ConfigPack terra$getPack() {
|
||||
net.minecraft.world.gen.chunk.ChunkGenerator generator =
|
||||
(((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()).getChunkGenerator();
|
||||
if(generator instanceof ForgeChunkGeneratorWrapper forgeChunkGeneratorWrapper) {
|
||||
return forgeChunkGeneratorWrapper.getPack();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin_ifaces;
|
||||
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface FloraFeatureHolder {
|
||||
void setFloraFeatures(List<ConfiguredFeature<?, ?>> features);
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.VanillaBiomeProperties;
|
||||
|
||||
import com.dfsek.terra.forge.mixin_ifaces.FloraFeatureHolder;
|
||||
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
@@ -21,7 +15,19 @@ import net.minecraftforge.registries.RegisterEvent.RegisterHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.mixin_ifaces.FloraFeatureHolder;
|
||||
|
||||
|
||||
public final class BiomeUtil {
|
||||
@@ -57,7 +63,7 @@ public final class BiomeUtil {
|
||||
*/
|
||||
private static void registerBiome(Biome biome, ConfigPack pack,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id, RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(ForgeRegistries.BIOMES);
|
||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(BuiltinRegistries.BIOME);
|
||||
|
||||
|
||||
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.HeightLimitView;
|
||||
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
|
||||
public final class ForgeAdapter {
|
||||
|
||||
public static Vector3 adapt(BlockPos pos) {
|
||||
return Vector3.of(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static WorldProperties adapt(HeightLimitView height, long seed) {
|
||||
return new WorldProperties() {
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return height.getTopY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return height.getBottomY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return height;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryEntry;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.entity.Container;
|
||||
import com.dfsek.terra.api.block.entity.MobSpawner;
|
||||
import com.dfsek.terra.api.block.entity.Sign;
|
||||
|
||||
|
||||
public final class ForgeUtil {
|
||||
private ForgeUtil() {
|
||||
|
||||
}
|
||||
|
||||
public static BlockEntity createState(WorldAccess worldAccess, BlockPos pos) {
|
||||
net.minecraft.block.entity.BlockEntity entity = worldAccess.getBlockEntity(pos);
|
||||
if(entity instanceof SignBlockEntity) {
|
||||
return (Sign) entity;
|
||||
} else if(entity instanceof MobSpawnerBlockEntity) {
|
||||
return (MobSpawner) entity;
|
||||
} else if(entity instanceof LootableContainerBlockEntity) {
|
||||
return (Container) entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> Optional<RegistryEntry<T>> getEntry(Registry<T> registry, Identifier identifier) {
|
||||
return registry.getOrEmpty(identifier)
|
||||
.flatMap(registry::getKey)
|
||||
.map(registry::getOrCreateEntry);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.generation.TerraBiomeSource;
|
||||
|
||||
import net.minecraft.structure.StructureSet;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler.NoiseParameters;
|
||||
@@ -30,6 +25,11 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.mod.generation.TerraBiomeSource;
|
||||
|
||||
|
||||
public class LifecycleUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LifecycleUtil.class);
|
||||
@@ -80,7 +80,7 @@ public class LifecycleUtil {
|
||||
PRESETS.add(generatorID);
|
||||
|
||||
TerraBiomeSource biomeSource = new TerraBiomeSource(biomeRegistry, pack);
|
||||
ChunkGenerator generator = new ForgeChunkGeneratorWrapper(structureSetRegistry, biomeSource, pack, overworld);
|
||||
ChunkGenerator generator = new MinecraftChunkGeneratorWrapper(structureSetRegistry, biomeSource, pack, overworld);
|
||||
|
||||
DimensionOptions dimensionOptions = new DimensionOptions(overworldDimensionType, generator);
|
||||
WorldPreset preset = new WorldPreset(
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
|
||||
public class ProtoPlatformBiome implements PlatformBiome {
|
||||
private final Identifier identifier;
|
||||
|
||||
private RegistryKey<Biome> delegate;
|
||||
|
||||
public ProtoPlatformBiome(Identifier identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public RegistryKey<Biome> get(Registry<net.minecraft.world.biome.Biome> registry) {
|
||||
return ForgeUtil.getEntry(registry, identifier).orElseThrow().getKey().orElseThrow();
|
||||
}
|
||||
|
||||
public RegistryKey<Biome> get(IForgeRegistry<Biome> registry) {
|
||||
return registry.getHolder(identifier).orElseThrow().getKey().orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public RegistryKey<Biome> getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public void setDelegate(RegistryKey<Biome> delegate) {
|
||||
this.delegate = Objects.requireNonNull(delegate);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.tag.TagKey;
|
||||
import net.minecraft.tag.WorldPresetTags;
|
||||
@@ -38,7 +40,7 @@ public final class TagUtil {
|
||||
|
||||
LifecycleUtil
|
||||
.getPresets()
|
||||
.forEach(id -> ForgeUtil
|
||||
.forEach(id -> MinecraftUtil
|
||||
.getEntry(registry, id)
|
||||
.ifPresentOrElse(
|
||||
preset -> collect
|
||||
@@ -57,11 +59,11 @@ public final class TagUtil {
|
||||
BiomeUtil
|
||||
.getTerraBiomeMap()
|
||||
.forEach((vb, terraBiomes) ->
|
||||
ForgeUtil
|
||||
MinecraftUtil
|
||||
.getEntry(registry, vb)
|
||||
.ifPresentOrElse(
|
||||
vanilla -> terraBiomes
|
||||
.forEach(tb -> ForgeUtil
|
||||
.forEach(tb -> MinecraftUtil
|
||||
.getEntry(registry, tb)
|
||||
.ifPresentOrElse(
|
||||
terra -> {
|
||||
|
||||
@@ -4,36 +4,6 @@
|
||||
"package": "com.dfsek.terra.forge.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
"access.StateAccessor",
|
||||
"access.StructureAccessorAccessor",
|
||||
"fix.BeeMoveGoalsUnsynchronizedRandomAccessFix",
|
||||
"fix.NetherFossilOptimization",
|
||||
"implementations.compat.GenerationSettingsFloraFeaturesMixin",
|
||||
"implementations.terra.BiomeMixin",
|
||||
"implementations.terra.HandleImplementationMixin",
|
||||
"implementations.terra.block.BlockMixin",
|
||||
"implementations.terra.block.entity.BlockEntityMixin",
|
||||
"implementations.terra.block.entity.LootableContainerBlockEntityMixin",
|
||||
"implementations.terra.block.entity.MobSpawnerBlockEntityMixin",
|
||||
"implementations.terra.block.entity.SignBlockEntityMixin",
|
||||
"implementations.terra.block.state.BlockStateMixin",
|
||||
"implementations.terra.block.state.PropertyMixin",
|
||||
"implementations.terra.chunk.ChunkRegionMixin",
|
||||
"implementations.terra.chunk.WorldChunkMixin",
|
||||
"implementations.terra.chunk.data.ProtoChunkMixin",
|
||||
"implementations.terra.entity.EntityMixin",
|
||||
"implementations.terra.entity.EntityTypeMixin",
|
||||
"implementations.terra.entity.PlayerEntityMixin",
|
||||
"implementations.terra.entity.ServerCommandSourceMixin",
|
||||
"implementations.terra.inventory.LockableContainerBlockEntityMixin",
|
||||
"implementations.terra.inventory.item.ItemMixin",
|
||||
"implementations.terra.inventory.item.ItemStackMixin",
|
||||
"implementations.terra.inventory.meta.EnchantmentMixin",
|
||||
"implementations.terra.inventory.meta.ItemStackDamageableMixin",
|
||||
"implementations.terra.inventory.meta.ItemStackMetaMixin",
|
||||
"implementations.terra.world.ChunkRegionMixin",
|
||||
"implementations.terra.world.ServerWorldMixin",
|
||||
"lifecycle.DataPackContentsMixin",
|
||||
"lifecycle.NoiseConfigMixin"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user