Reformat all code

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
solonovamax
2021-08-30 17:34:44 -04:00
parent 1655381413
commit c445a0434d
753 changed files with 10461 additions and 8783 deletions
+2 -2
View File
@@ -20,11 +20,11 @@ tasks.named<ShadowJar>("shadowJar") {
dependencies {
"shadedApi"(project(":common:implementation"))
"minecraft"("com.mojang:minecraft:1.17.1")
"mappings"("net.fabricmc:yarn:1.17.1+build.1:v2")
"modImplementation"("net.fabricmc:fabric-loader:0.11.3")
"modCompileOnly"("com.sk89q.worldedit:worldedit-fabric-mc1.16:7.2.0-SNAPSHOT") {
exclude(group = "com.google.guava", module = "guava")
exclude(group = "com.google.code.gson", module = "gson")
@@ -1,6 +1,15 @@
package com.dfsek.terra.fabric;
import com.dfsek.tectonic.exception.ConfigException;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import java.util.HashMap;
import java.util.Map;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.annotations.Addon;
import com.dfsek.terra.api.addon.annotations.Author;
@@ -18,14 +27,7 @@ import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
import com.dfsek.terra.fabric.util.FabricUtil;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import java.util.HashMap;
import java.util.Map;
@Addon("terra-fabric")
@Author("Terra")
@@ -33,76 +35,86 @@ import java.util.Map;
public final class FabricAddon extends TerraAddon {
private final TerraPluginImpl terraFabricPlugin;
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
public FabricAddon(TerraPluginImpl terraFabricPlugin) {
this.terraFabricPlugin = terraFabricPlugin;
}
@Override
public void initialize() {
terraFabricPlugin.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class)
.then(event -> {
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
try {
event.loadTemplate(template);
} catch(ConfigException e) {
e.printStackTrace();
}
if(template.doRegistryInjection()) {
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
try {
event.getPack().getCheckedRegistry(Tree.class).register(entry.getKey().getValue().toString(), (Tree) entry.getValue());
terraFabricPlugin.getDebugLogger().info("Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
} catch(DuplicateEntryException ignored) {
}
}
});
}
templates.put(event.getPack(), Pair.of(template, null));
})
.global();
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class)
.then(event -> {
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
try {
event.loadTemplate(template);
} catch(ConfigException e) {
e.printStackTrace();
}
if(template.doRegistryInjection()) {
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
try {
event.getPack().getCheckedRegistry(Tree.class).register(entry.getKey().getValue().toString(),
(Tree) entry.getValue());
terraFabricPlugin.getDebugLogger().info(
"Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
} catch(DuplicateEntryException ignored) {
}
}
});
}
templates.put(event.getPack(), Pair.of(template, null));
})
.global();
terraFabricPlugin.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPostLoadEvent.class)
.then(event -> {
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
try {
event.loadTemplate(template);
} catch(ConfigException e) {
e.printStackTrace();
}
templates.get(event.getPack()).setRight(template);
})
.priority(100)
.global();
.getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPostLoadEvent.class)
.then(event -> {
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
try {
event.loadTemplate(template);
} catch(ConfigException e) {
e.printStackTrace();
}
templates.get(event.getPack()).setRight(template);
})
.priority(100)
.global();
terraFabricPlugin.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, BiomeRegistrationEvent.class)
.then(event -> {
terraFabricPlugin.logger().info("Registering biomes...");
Registry<Biome> biomeRegistry = event.getRegistryManager().get(Registry.BIOME_KEY);
terraFabricPlugin.getConfigRegistry().forEach(pack -> pack.getCheckedRegistry(TerraBiome.class).forEach((id, biome) -> FabricUtil.registerOrOverwrite(biomeRegistry, Registry.BIOME_KEY, new Identifier("terra", FabricUtil.createBiomeID(pack, id)), FabricUtil.createBiome(biome, pack, event.getRegistryManager())))); // Register all Terra biomes.
terraFabricPlugin.logger().info("Biomes registered.");
})
.global();
.getHandler(FunctionalEventHandler.class)
.register(this, BiomeRegistrationEvent.class)
.then(event -> {
terraFabricPlugin.logger().info("Registering biomes...");
Registry<Biome> biomeRegistry = event.getRegistryManager().get(Registry.BIOME_KEY);
terraFabricPlugin.getConfigRegistry().forEach(pack -> pack.getCheckedRegistry(TerraBiome.class)
.forEach(
(id, biome) -> FabricUtil.registerOrOverwrite(
biomeRegistry, Registry.BIOME_KEY,
new Identifier("terra",
FabricUtil.createBiomeID(
pack, id)),
FabricUtil.createBiome(biome, pack,
event.getRegistryManager())))); // Register all Terra biomes.
terraFabricPlugin.logger().info("Biomes registered.");
})
.global();
}
private void injectTree(CheckedRegistry<Tree> registry, String id, ConfiguredFeature<?, ?> tree) {
try {
registry.register(id, (Tree) tree);
} catch(DuplicateEntryException ignore) {
}
}
public Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> getTemplates() {
return templates;
}
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.PopulatorFeature;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
@@ -14,25 +11,30 @@ import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.FeatureConfig;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.PopulatorFeature;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
public class FabricEntryPoint implements ModInitializer {
private static final TerraPluginImpl TERRA_PLUGIN = new TerraPluginImpl();
public static final PopulatorFeature POPULATOR_FEATURE = new PopulatorFeature(DefaultFeatureConfig.CODEC);
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(
Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
private static final TerraPluginImpl TERRA_PLUGIN = new TerraPluginImpl();
public static TerraPluginImpl getTerraPlugin() {
return TERRA_PLUGIN;
}
@Override
public void onInitialize() {
// register the things
Registry.register(Registry.FEATURE, new Identifier("terra", "populator"), POPULATOR_FEATURE);
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_KEY, new Identifier("terra", "populator"));
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_KEY,
new Identifier("terra", "populator"));
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE);
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
}
public static TerraPluginImpl getTerraPlugin() {
return TERRA_PLUGIN;
}
}
@@ -2,6 +2,14 @@ package com.dfsek.terra.fabric;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.TypeRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.util.Optional;
import com.dfsek.terra.AbstractTerraPlugin;
import com.dfsek.terra.api.Logger;
import com.dfsek.terra.api.addon.TerraAddon;
@@ -12,61 +20,18 @@ import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.fabric.handle.FabricItemHandle;
import com.dfsek.terra.fabric.handle.FabricWorldHandle;
import com.dfsek.terra.fabric.util.ProtoBiome;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.util.Optional;
public class TerraPluginImpl extends AbstractTerraPlugin {
private final ItemHandle itemHandle = new FabricItemHandle();
private final WorldHandle worldHandle = new FabricWorldHandle();
private final Lazy<File> dataFolder = Lazy.lazy(() -> new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"));
@Override
public WorldHandle getWorldHandle() {
return worldHandle;
}
@Override
protected Optional<TerraAddon> getPlatformAddon() {
return Optional.of(new FabricAddon(this));
}
public TerraPluginImpl() {
load();
}
@Override
protected Logger createLogger() {
final org.apache.logging.log4j.Logger log4jLogger = LogManager.getLogger();
return new Logger() {
@Override
public void info(String message) {
log4jLogger.info(message);
}
@Override
public void warning(String message) {
log4jLogger.warn(message);
}
@Override
public void severe(String message) {
log4jLogger.error(message);
}
};
}
@Override
public File getDataFolder() {
return dataFolder.value();
}
@Override
public boolean reload() {
getTerraConfig().load(this);
@@ -74,17 +39,27 @@ public class TerraPluginImpl extends AbstractTerraPlugin {
boolean succeed = getRawConfigRegistry().loadAll(this);
return succeed;
}
@Override
public ItemHandle getItemHandle() {
return itemHandle;
}
@Override
public String platformName() {
return "Fabric";
}
@Override
public WorldHandle getWorldHandle() {
return worldHandle;
}
@Override
public File getDataFolder() {
return dataFolder.value();
}
@Override
public ItemHandle getItemHandle() {
return itemHandle;
}
@Override
public void register(TypeRegistry registry) {
super.register(registry);
@@ -96,7 +71,33 @@ public class TerraPluginImpl extends AbstractTerraPlugin {
return identifier;
});
}
@Override
protected Logger createLogger() {
final org.apache.logging.log4j.Logger log4jLogger = LogManager.getLogger();
return new Logger() {
@Override
public void info(String message) {
log4jLogger.info(message);
}
@Override
public void warning(String message) {
log4jLogger.warn(message);
}
@Override
public void severe(String message) {
log4jLogger.error(message);
}
};
}
@Override
protected Optional<TerraAddon> getPlatformAddon() {
return Optional.of(new FabricAddon(this));
}
private ProtoBiome parseBiome(String id) throws LoadException {
Identifier identifier = Identifier.tryParse(id);
if(BuiltinRegistries.BIOME.get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier); // failure.
@@ -1,13 +1,5 @@
package com.dfsek.terra.fabric.block;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.state.properties.Property;
import com.dfsek.terra.api.block.state.properties.base.Properties;
import com.dfsek.terra.api.util.generic.Construct;
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
import com.dfsek.terra.fabric.mixin.access.StateAccessor;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.block.Blocks;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.RailShape;
@@ -21,60 +13,123 @@ import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class FabricBlockState implements BlockState {
private static final Map<Property<?>, ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>>> PROPERTY_DELEGATES_T2M = Construct.construct(() -> {
Map<Property<?>, ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>>> map = new HashMap<>();
map.put(Properties.AXIS, ImmutablePair.of(net.minecraft.state.property.Properties.AXIS, a -> FabricAdapter.adapt((net.minecraft.util.math.Direction.Axis) a)));
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.state.properties.Property;
import com.dfsek.terra.api.block.state.properties.base.Properties;
import com.dfsek.terra.api.util.generic.Construct;
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
import com.dfsek.terra.fabric.mixin.access.StateAccessor;
import com.dfsek.terra.fabric.util.FabricAdapter;
public class FabricBlockState implements BlockState {
private static final Map<Property<?>, ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>>>
PROPERTY_DELEGATES_T2M = Construct.construct(() -> {
Map<Property<?>, ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>>> map = new HashMap<>();
map.put(Properties.AXIS, ImmutablePair.of(net.minecraft.state.property.Properties.AXIS,
a -> FabricAdapter.adapt((net.minecraft.util.math.Direction.Axis) a)));
map.put(Properties.NORTH, ImmutablePair.of(net.minecraft.state.property.Properties.NORTH, Function.identity()));
map.put(Properties.SOUTH, ImmutablePair.of(net.minecraft.state.property.Properties.SOUTH, Function.identity()));
map.put(Properties.EAST, ImmutablePair.of(net.minecraft.state.property.Properties.EAST, Function.identity()));
map.put(Properties.WEST, ImmutablePair.of(net.minecraft.state.property.Properties.WEST, Function.identity()));
map.put(Properties.NORTH_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.NORTH_WIRE_CONNECTION, c -> FabricAdapter.adapt((WireConnection) c)));
map.put(Properties.SOUTH_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.SOUTH_WIRE_CONNECTION, c -> FabricAdapter.adapt((WireConnection) c)));
map.put(Properties.EAST_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.EAST_WIRE_CONNECTION, c -> FabricAdapter.adapt((WireConnection) c)));
map.put(Properties.WEST_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.WEST_WIRE_CONNECTION, c -> FabricAdapter.adapt((WireConnection) c)));
map.put(Properties.NORTH_HEIGHT, ImmutablePair.of(net.minecraft.state.property.Properties.NORTH_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
map.put(Properties.SOUTH_HEIGHT, ImmutablePair.of(net.minecraft.state.property.Properties.SOUTH_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
map.put(Properties.EAST_HEIGHT, ImmutablePair.of(net.minecraft.state.property.Properties.EAST_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
map.put(Properties.WEST_HEIGHT, ImmutablePair.of(net.minecraft.state.property.Properties.WEST_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
map.put(Properties.DIRECTION, ImmutablePair.of(net.minecraft.state.property.Properties.FACING, d -> FabricAdapter.adapt((Direction) d)));
map.put(Properties.NORTH_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.NORTH_WIRE_CONNECTION,
c -> FabricAdapter.adapt((WireConnection) c)));
map.put(Properties.SOUTH_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.SOUTH_WIRE_CONNECTION,
c -> FabricAdapter.adapt((WireConnection) c)));
map.put(Properties.EAST_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.EAST_WIRE_CONNECTION,
c -> FabricAdapter.adapt((WireConnection) c)));
map.put(Properties.WEST_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.WEST_WIRE_CONNECTION,
c -> FabricAdapter.adapt((WireConnection) c)));
map.put(Properties.NORTH_HEIGHT,
ImmutablePair.of(net.minecraft.state.property.Properties.NORTH_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
map.put(Properties.SOUTH_HEIGHT,
ImmutablePair.of(net.minecraft.state.property.Properties.SOUTH_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
map.put(Properties.EAST_HEIGHT,
ImmutablePair.of(net.minecraft.state.property.Properties.EAST_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
map.put(Properties.WEST_HEIGHT,
ImmutablePair.of(net.minecraft.state.property.Properties.WEST_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
map.put(Properties.DIRECTION,
ImmutablePair.of(net.minecraft.state.property.Properties.FACING, d -> FabricAdapter.adapt((Direction) d)));
map.put(Properties.WATERLOGGED, ImmutablePair.of(net.minecraft.state.property.Properties.WATERLOGGED, Function.identity()));
map.put(Properties.RAIL_SHAPE, ImmutablePair.of(net.minecraft.state.property.Properties.RAIL_SHAPE, s -> FabricAdapter.adapt((RailShape) s)));
map.put(Properties.HALF, ImmutablePair.of(net.minecraft.state.property.Properties.BLOCK_HALF, h -> FabricAdapter.adapt((BlockHalf) h)));
map.put(Properties.RAIL_SHAPE,
ImmutablePair.of(net.minecraft.state.property.Properties.RAIL_SHAPE, s -> FabricAdapter.adapt((RailShape) s)));
map.put(Properties.HALF,
ImmutablePair.of(net.minecraft.state.property.Properties.BLOCK_HALF, h -> FabricAdapter.adapt((BlockHalf) h)));
return map;
});
private static final Map<net.minecraft.state.property.Property<?>, Property<?>> PROPERTY_DELEGATES_M2T = Construct.construct(() -> {
Map<net.minecraft.state.property.Property<?>, Property<?>> map = new HashMap<>();
PROPERTY_DELEGATES_T2M.forEach((p, p2) -> map.put(p2.getLeft(), p));
return map;
});
protected net.minecraft.block.BlockState delegate;
public FabricBlockState(net.minecraft.block.BlockState delegate) {
this.delegate = delegate;
}
@Override
public BlockType getBlockType() {
return (BlockType) delegate.getBlock();
}
@Override
public boolean matches(BlockState other) {
return delegate.getBlock() == ((FabricBlockState) other).delegate.getBlock();
}
@Override
public <T> boolean has(Property<T> property) {
return delegate.getProperties().contains(PROPERTY_DELEGATES_T2M.get(property).getLeft());
}
@SuppressWarnings("unchecked")
@Override
public <T> T get(Property<T> property) {
ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>> pair = PROPERTY_DELEGATES_T2M.get(property);
return (T) pair.getRight().apply(delegate.get(pair.getLeft()));
}
@Override
public <T> BlockState set(Property<T> property, T value) {
//return delegate = delegate.with(PROPERTY_DELEGATES_T2M.get(property), v);
return this;
}
@Override
public BlockType getBlockType() {
return (BlockType) delegate.getBlock();
}
@Override
public String getAsString() {
StringBuilder data = new StringBuilder(Registry.BLOCK.getId(delegate.getBlock()).toString());
if(!delegate.getEntries().isEmpty()) {
data.append('[');
data.append(
delegate.getEntries().entrySet().stream().map(StateAccessor.getPropertyMapPrinter()).collect(Collectors.joining(",")));
data.append(']');
}
return data.toString();
}
@Override
public boolean isAir() {
return delegate.isAir();
}
@Override
public boolean isStructureVoid() {
return delegate.getBlock() == Blocks.STRUCTURE_VOID;
}
@Override
public BlockState clone() {
try {
@@ -83,46 +138,7 @@ public class FabricBlockState implements BlockState {
throw new Error(e);
}
}
@Override
public String getAsString() {
StringBuilder data = new StringBuilder(Registry.BLOCK.getId(delegate.getBlock()).toString());
if(!delegate.getEntries().isEmpty()) {
data.append('[');
data.append(delegate.getEntries().entrySet().stream().map(StateAccessor.getPropertyMapPrinter()).collect(Collectors.joining(",")));
data.append(']');
}
return data.toString();
}
@Override
public boolean isAir() {
return delegate.isAir();
}
@Override
public boolean isStructureVoid() {
return delegate.getBlock() == Blocks.STRUCTURE_VOID;
}
@Override
public <T> boolean has(Property<T> property) {
return delegate.getProperties().contains(PROPERTY_DELEGATES_T2M.get(property).getLeft());
}
@SuppressWarnings("unchecked")
@Override
public <T> T get(Property<T> property) {
ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>> pair = PROPERTY_DELEGATES_T2M.get(property);
return (T) pair.getRight().apply(delegate.get(pair.getLeft()));
}
@Override
public <T> BlockState set(Property<T> property, T value) {
//return delegate = delegate.with(PROPERTY_DELEGATES_T2M.get(property), v);
return this;
}
@Override
public net.minecraft.block.BlockState getHandle() {
return delegate;
@@ -3,27 +3,29 @@ package com.dfsek.terra.fabric.config;
import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.terra.api.world.biome.TerraBiome;
import net.minecraft.util.Identifier;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.dfsek.terra.api.world.biome.TerraBiome;
@SuppressWarnings("FieldMayBeFinal")
public class PostLoadCompatibilityOptions implements ConfigTemplate {
@Value("structures.inject-biome.exclude-biomes")
@Default
private Map<TerraBiome, Set<Identifier>> excludedPerBiomeStructures = new HashMap<>();
@Value("features.inject-biome.exclude-biomes")
@Default
private Map<TerraBiome, Set<Identifier>> excludedPerBiomeFeatures = new HashMap<>();
public Map<TerraBiome, Set<Identifier>> getExcludedPerBiomeFeatures() {
return excludedPerBiomeFeatures;
}
public Map<TerraBiome, Set<Identifier>> getExcludedPerBiomeStructures() {
return excludedPerBiomeStructures;
}
@@ -8,44 +8,45 @@ import net.minecraft.util.Identifier;
import java.util.HashSet;
import java.util.Set;
@SuppressWarnings("FieldMayBeFinal")
public class PreLoadCompatibilityOptions implements ConfigTemplate {
@Value("features.inject-registry.enable")
@Default
private boolean doRegistryInjection = false;
@Value("features.inject-biome.enable")
@Default
private boolean doBiomeInjection = false;
@Value("features.inject-registry.excluded-features")
@Default
private Set<Identifier> excludedRegistryFeatures = new HashSet<>();
@Value("features.inject-biome.excluded-features")
@Default
private Set<Identifier> excludedBiomeFeatures = new HashSet<>();
@Value("structures.inject-biome.excluded-features")
@Default
private Set<Identifier> excludedBiomeStructures = new HashSet<>();
public boolean doBiomeInjection() {
return doBiomeInjection;
}
public boolean doRegistryInjection() {
return doRegistryInjection;
}
public Set<Identifier> getExcludedBiomeFeatures() {
return excludedBiomeFeatures;
}
public Set<Identifier> getExcludedRegistryFeatures() {
return excludedRegistryFeatures;
}
public Set<Identifier> getExcludedBiomeStructures() {
return excludedBiomeStructures;
}
@@ -1,18 +1,20 @@
package com.dfsek.terra.fabric.event;
import com.dfsek.terra.api.event.events.Event;
import net.minecraft.util.registry.DynamicRegistryManager;
import com.dfsek.terra.api.event.events.Event;
/**
* Fired when biomes should be registered.
*/
public class BiomeRegistrationEvent implements Event {
private final DynamicRegistryManager registryManager;
public BiomeRegistrationEvent(DynamicRegistryManager registryManager) {
this.registryManager = registryManager;
}
public DynamicRegistryManager getRegistryManager() {
return registryManager;
}
@@ -1,15 +1,5 @@
package com.dfsek.terra.fabric.generation;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.api.world.generator.Chunkified;
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
import com.dfsek.terra.util.FastRandom;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
@@ -39,69 +29,76 @@ import org.jetbrains.annotations.Nullable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.api.world.generator.Chunkified;
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
import com.dfsek.terra.util.FastRandom;
public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.ChunkGenerator implements GeneratorWrapper {
public static final Codec<ConfigPack> PACK_CODEC = RecordCodecBuilder.create(
config -> config.group(
Codec.STRING.fieldOf("pack")
.forGetter(ConfigPack::getID)
).apply(config, config.stable(FabricEntryPoint.getTerraPlugin().getConfigRegistry()::get)));
.forGetter(ConfigPack::getID)
).apply(config, config.stable(FabricEntryPoint.getTerraPlugin().getConfigRegistry()::get)));
public static final Codec<FabricChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(
instance -> instance.group(
TerraBiomeSource.CODEC.fieldOf("biome_source")
.forGetter(generator -> generator.biomeSource),
.forGetter(generator -> generator.biomeSource),
Codec.LONG.fieldOf("seed").stable()
.forGetter(generator -> generator.seed),
.forGetter(generator -> generator.seed),
PACK_CODEC.fieldOf("pack").stable()
.forGetter(generator -> generator.pack)
).apply(instance, instance.stable(FabricChunkGeneratorWrapper::new))
);
.forGetter(generator -> generator.pack)
).apply(instance, instance.stable(FabricChunkGeneratorWrapper::new))
);
private final long seed;
private final ChunkGenerator delegate;
private final TerraBiomeSource biomeSource;
private final ConfigPack pack;
private ServerWorld world;
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
super(biomeSource, new StructuresConfig(false));
this.pack = configPack;
this.delegate = pack.getGeneratorProvider().newInstance(pack);
delegate.getMain().logger().info("Loading world with config pack " + pack.getID());
this.biomeSource = biomeSource;
this.seed = seed;
}
@Override
protected Codec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() {
return CODEC;
}
@Override
public net.minecraft.world.gen.chunk.ChunkGenerator withSeed(long seed) {
return new FabricChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed, pack);
}
public ConfigPack getPack() {
return pack;
}
@Override
public void buildSurface(ChunkRegion region, Chunk chunk) {
// No-op
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
if(pack.vanillaCaves()) {
super.carve(seed, access, chunk, carver);
}
}
public void setWorld(ServerWorld world) {
this.world = world;
}
@Nullable
@Override
public BlockPos locateStructure(ServerWorld world, StructureFeature<?> feature, BlockPos center, int radius, boolean skipExistingChunks) {
public BlockPos locateStructure(ServerWorld world, StructureFeature<?> feature, BlockPos center, int radius,
boolean skipExistingChunks) {
/*
if(!pack.disableStructures()) {
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getId(feature)).toString();
@@ -109,7 +106,8 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
ConfiguredStructure located = pack.getRegistry(TerraStructure.class).get(pack.getLocatable().get(name));
if(located != null) {
CompletableFuture<BlockPos> result = new CompletableFuture<>();
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center), terraWorld.getWorld(), 0, 500, location -> {
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt
(center), terraWorld.getWorld(), 0, 500, location -> {
result.complete(FabricAdapter.adapt(location));
}, TerraFabricPlugin.getInstance());
finder.run(); // Do this synchronously.
@@ -123,21 +121,63 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
*/
return super.locateStructure(world, feature, center, radius, skipExistingChunks);
}
@Override
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
if(pack.vanillaCaves()) {
super.carve(seed, access, chunk, carver);
public void buildSurface(ChunkRegion region, Chunk chunk) {
// No-op
}
@Override
public void populateEntities(ChunkRegion region) {
if(pack.vanillaMobs()) {
int cx = region.getCenterPos().x;
int cy = region.getCenterPos().z;
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos());
ChunkRandom chunkRandom = new ChunkRandom();
chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4);
SpawnHelper.populateEntities(region, biome, region.getCenterPos(), chunkRandom);
}
}
public Pool<SpawnSettings.SpawnEntry> getEntitySpawnList(Biome biome, StructureAccessor accessor, SpawnGroup group, BlockPos pos) {
if(accessor.getStructureAt(pos, true, StructureFeature.SWAMP_HUT).hasChildren()) {
if(group == SpawnGroup.MONSTER) {
return StructureFeature.SWAMP_HUT.getMonsterSpawns();
}
if(group == SpawnGroup.CREATURE) {
return StructureFeature.SWAMP_HUT.getCreatureSpawns();
}
}
if(group == SpawnGroup.MONSTER) {
if(accessor.getStructureAt(pos, false, StructureFeature.PILLAGER_OUTPOST).hasChildren()) {
return StructureFeature.PILLAGER_OUTPOST.getMonsterSpawns();
}
if(accessor.getStructureAt(pos, false, StructureFeature.MONUMENT).hasChildren()) {
return StructureFeature.MONUMENT.getMonsterSpawns();
}
if(accessor.getStructureAt(pos, true, StructureFeature.FORTRESS).hasChildren()) {
return StructureFeature.FORTRESS.getMonsterSpawns();
}
}
return group == SpawnGroup.UNDERGROUND_WATER_CREATURE && accessor.getStructureAt(pos, false, StructureFeature.MONUMENT)
.hasChildren()
? StructureFeature.MONUMENT.getUndergroundWaterCreatureSpawns()
: super.getEntitySpawnList(biome, accessor, group, pos);
}
@Override
public void setStructureStarts(DynamicRegistryManager dynamicRegistryManager, StructureAccessor structureAccessor, Chunk chunk, StructureManager structureManager, long worldSeed) {
public void setStructureStarts(DynamicRegistryManager dynamicRegistryManager, StructureAccessor structureAccessor, Chunk chunk,
StructureManager structureManager, long worldSeed) {
if(pack.vanillaStructures()) {
super.setStructureStarts(dynamicRegistryManager, structureAccessor, chunk, structureManager, worldSeed);
}
}
@Override
public CompletableFuture<Chunk> populateNoise(Executor executor, StructureAccessor accessor, Chunk chunk) {
return CompletableFuture.supplyAsync(() -> {
@@ -151,29 +191,17 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
return chunk;
}, executor);
}
@Override
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
if(pack.vanillaStructures()) {
return super.isStrongholdStartingChunk(chunkPos);
}
return false;
}
@Override
public int getHeightOnGround(int x, int z, Heightmap.Type heightmap, HeightLimitView world) {
return super.getHeightOnGround(x, z, heightmap, world);
}
@Override
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView heightmapType) {
int height = ((World) world).getMaxHeight();
while(height >= ((World) world).getMinHeight() && !heightmap.getBlockPredicate().test(((FabricBlockState) ((World) world).getGenerator().getBlock((World) world, x, height - 1, z)).getHandle())) {
while(height >= ((World) world).getMinHeight() && !heightmap.getBlockPredicate().test(
((FabricBlockState) ((World) world).getGenerator().getBlock((World) world, x, height - 1, z)).getHandle())) {
height--;
}
return height;
}
@Override
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView view) {
BlockState[] array = new BlockState[view.getHeight()];
@@ -182,47 +210,28 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
}
return new VerticalBlockSample(view.getBottomY(), array);
}
@Override
public void populateEntities(ChunkRegion region) {
if(pack.vanillaMobs()) {
int cx = region.getCenterPos().x;
int cy = region.getCenterPos().z;
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos());
ChunkRandom chunkRandom = new ChunkRandom();
chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4);
SpawnHelper.populateEntities(region, biome, region.getCenterPos(), chunkRandom);
}
public int getHeightOnGround(int x, int z, Heightmap.Type heightmap, HeightLimitView world) {
return super.getHeightOnGround(x, z, heightmap, world);
}
public Pool<SpawnSettings.SpawnEntry> getEntitySpawnList(Biome biome, StructureAccessor accessor, SpawnGroup group, BlockPos pos) {
if(accessor.getStructureAt(pos, true, StructureFeature.SWAMP_HUT).hasChildren()) {
if(group == SpawnGroup.MONSTER) {
return StructureFeature.SWAMP_HUT.getMonsterSpawns();
}
if(group == SpawnGroup.CREATURE) {
return StructureFeature.SWAMP_HUT.getCreatureSpawns();
}
@Override
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
if(pack.vanillaStructures()) {
return super.isStrongholdStartingChunk(chunkPos);
}
if(group == SpawnGroup.MONSTER) {
if(accessor.getStructureAt(pos, false, StructureFeature.PILLAGER_OUTPOST).hasChildren()) {
return StructureFeature.PILLAGER_OUTPOST.getMonsterSpawns();
}
if(accessor.getStructureAt(pos, false, StructureFeature.MONUMENT).hasChildren()) {
return StructureFeature.MONUMENT.getMonsterSpawns();
}
if(accessor.getStructureAt(pos, true, StructureFeature.FORTRESS).hasChildren()) {
return StructureFeature.FORTRESS.getMonsterSpawns();
}
}
return group == SpawnGroup.UNDERGROUND_WATER_CREATURE && accessor.getStructureAt(pos, false, StructureFeature.MONUMENT).hasChildren() ? StructureFeature.MONUMENT.getUndergroundWaterCreatureSpawns() : super.getEntitySpawnList(biome, accessor, group, pos);
return false;
}
public ConfigPack getPack() {
return pack;
}
public void setWorld(ServerWorld world) {
this.world = world;
}
@Override
public ChunkGenerator getHandle() {
return delegate;
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric.generation;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.generator.Chunkified;
import com.mojang.serialization.Codec;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
@@ -10,6 +7,11 @@ import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.util.FeatureContext;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.generator.Chunkified;
/**
* Feature wrapper for Terra populator
*/
@@ -17,7 +19,7 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
public PopulatorFeature(Codec<DefaultFeatureConfig> codec) {
super(codec);
}
@Override
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
ChunkGenerator chunkGenerator = context.getGenerator();
@@ -1,10 +1,5 @@
package com.dfsek.terra.fabric.generation;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.util.FabricUtil;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.Identifier;
@@ -16,47 +11,60 @@ import net.minecraft.world.biome.source.BiomeSource;
import java.util.Objects;
import java.util.stream.Collectors;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.util.FabricUtil;
public class TerraBiomeSource extends BiomeSource {
public static final Codec<ConfigPack> PACK_CODEC = (RecordCodecBuilder.create(config -> config.group(
Codec.STRING.fieldOf("pack").forGetter(ConfigPack::getID)
).apply(config, config.stable(FabricEntryPoint.getTerraPlugin().getConfigRegistry()::get))));
Codec.STRING.fieldOf("pack").forGetter(ConfigPack::getID)
)
.apply(config, config.stable(
FabricEntryPoint.getTerraPlugin()
.getConfigRegistry()::get))));
public static final Codec<TerraBiomeSource> CODEC = RecordCodecBuilder.create(instance -> instance.group(
RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter(source -> source.biomeRegistry),
Codec.LONG.fieldOf("seed").stable().forGetter(source -> source.seed),
PACK_CODEC.fieldOf("pack").stable().forGetter(source -> source.pack))
.apply(instance, instance.stable(TerraBiomeSource::new)));
RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter(source -> source.biomeRegistry),
Codec.LONG.fieldOf("seed").stable().forGetter(source -> source.seed),
PACK_CODEC.fieldOf("pack").stable().forGetter(source -> source.pack))
.apply(instance, instance.stable(
TerraBiomeSource::new)));
private final Registry<Biome> biomeRegistry;
private final long seed;
private final BiomeProvider provider;
private final ConfigPack pack;
public TerraBiomeSource(Registry<Biome> biomes, long seed, ConfigPack pack) {
super(biomes.stream()
.filter(biome -> Objects.requireNonNull(biomes.getId(biome)).getNamespace().equals("terra")) // Filter out non-Terra biomes.
.collect(Collectors.toList()));
.filter(biome -> Objects.requireNonNull(biomes.getId(biome))
.getNamespace()
.equals("terra")) // Filter out non-Terra biomes.
.collect(Collectors.toList()));
this.biomeRegistry = biomes;
this.seed = seed;
this.provider = pack.getBiomeProviderBuilder();
this.pack = pack;
}
@Override
protected Codec<? extends BiomeSource> getCodec() {
return CODEC;
}
@Override
public BiomeSource withSeed(long seed) {
return new TerraBiomeSource(this.biomeRegistry, seed, pack);
}
@Override
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
TerraBiome biome = provider.getBiome(biomeX << 2, biomeZ << 2, seed);
return biomeRegistry.get(new Identifier("terra", FabricUtil.createBiomeID(pack, biome.getID())));
}
public BiomeProvider getProvider() {
return provider;
}
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric.generation;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.world.GeneratorType;
@@ -13,24 +10,31 @@ import net.minecraft.world.gen.GeneratorOptions;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
@Environment(EnvType.CLIENT)
public class TerraGeneratorType extends GeneratorType {
private final ConfigPack pack;
public TerraGeneratorType(ConfigPack pack) {
super("terra." + pack.getID());
this.pack = pack;
}
@Override
public GeneratorOptions createDefaultOptions(DynamicRegistryManager.Impl registryManager, long seed, boolean generateStructures, boolean bonusChest) {
public GeneratorOptions createDefaultOptions(DynamicRegistryManager.Impl registryManager, long seed, boolean generateStructures,
boolean bonusChest) {
GeneratorOptions options = super.createDefaultOptions(registryManager, seed, generateStructures, bonusChest);
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(new BiomeRegistrationEvent(registryManager)); // register biomes
return options;
}
@Override
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry,
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
}
}
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric.handle;
import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.Enchantment;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.argument.ItemStackArgumentType;
@@ -12,8 +9,13 @@ import net.minecraft.util.registry.Registry;
import java.util.Set;
import java.util.stream.Collectors;
public class FabricItemHandle implements ItemHandle {
import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.Enchantment;
public class FabricItemHandle implements ItemHandle {
@Override
public Item createItem(String data) {
try {
@@ -22,12 +24,12 @@ public class FabricItemHandle implements ItemHandle {
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,5 +1,14 @@
package com.dfsek.terra.fabric.handle;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.command.argument.BlockArgumentParser;
import net.minecraft.nbt.StringNbtReader;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.entity.Player;
@@ -9,22 +18,12 @@ import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.util.FabricAdapter;
import com.dfsek.terra.fabric.util.WorldEditUtil;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.command.argument.BlockArgumentParser;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.StringNbtReader;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.util.Locale;
public class FabricWorldHandle implements WorldHandle {
private static final com.dfsek.terra.api.block.state.BlockState AIR = FabricAdapter.adapt(Blocks.AIR.getDefaultState());
@Override
public FabricBlockState createBlockData(String data) {
BlockArgumentParser parser = new BlockArgumentParser(new StringReader(data), true);
@@ -36,28 +35,29 @@ public class FabricWorldHandle implements WorldHandle {
throw new IllegalArgumentException(e);
}
}
@Override
public com.dfsek.terra.api.block.state.BlockState air() {
return AIR;
}
@Override
public BlockEntity createBlockEntity(Vector3 location, com.dfsek.terra.api.block.state.BlockState block, String snbt) {
try {
return (BlockEntity) net.minecraft.block.entity.BlockEntity.createFromNbt(FabricAdapter.adapt(location), (BlockState) block,
StringNbtReader.parse(snbt));
} catch(CommandSyntaxException e) {
throw new RuntimeException(e);
}
}
@Override
public EntityType getEntity(String id) {
Identifier identifier = Identifier.tryParse(id);
if(identifier == null) identifier = Identifier.tryParse(id);
return (EntityType) Registry.ENTITY_TYPE.get(identifier);
}
@Override
public BlockEntity createBlockEntity(Vector3 location, com.dfsek.terra.api.block.state.BlockState block, String snbt) {
try {
return (BlockEntity) net.minecraft.block.entity.BlockEntity.createFromNbt(FabricAdapter.adapt(location), (BlockState) block, StringNbtReader.parse(snbt));
} catch(CommandSyntaxException e) {
throw new RuntimeException(e);
}
}
@Override
public Pair<Vector3, Vector3> getSelectedLocation(Player player) {
try {
@@ -1,9 +1,5 @@
package com.dfsek.terra.fabric.mixin;
import com.dfsek.terra.api.command.exception.CommandException;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
@@ -22,31 +18,41 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.dfsek.terra.api.command.exception.CommandException;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.fabric.FabricEntryPoint;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
@Mixin(CommandManager.class)
public abstract class CommandManagerMixin {
@Shadow
@Final
private CommandDispatcher<ServerCommandSource> dispatcher;
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V", remap = false))
@Inject(method = "<init>",
at = @At(value = "INVOKE",
target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V",
remap = false))
private void injectTerraCommands(CommandManager.RegistrationEnvironment environment, CallbackInfo ci) {
com.dfsek.terra.api.command.CommandManager manager = FabricEntryPoint.getTerraPlugin().getManager();
int max = manager.getMaxArgumentDepth();
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
for(int i = 0; i < max; i++) {
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
arg = next.then(assemble(arg, manager));
}
dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager)));
dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager)));
}
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, com.dfsek.terra.api.command.CommandManager manager) {
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in,
com.dfsek.terra.api.command.CommandManager manager) {
return in.suggests((context, builder) -> {
List<String> args = parseCommand(context.getInput());
CommandSender sender = (CommandSender) context.getSource();
@@ -75,7 +81,7 @@ public abstract class CommandManagerMixin {
return 1;
});
}
private List<String> parseCommand(String command) {
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
@@ -1,7 +1,5 @@
package com.dfsek.terra.fabric.mixin;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerWorld;
@@ -20,10 +18,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
import java.util.concurrent.Executor;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin {
@Inject(method = "<init>", at = @At(value = "RETURN"))
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
@Inject(method = "<init>", at = @At("RETURN"))
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session,
ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType,
WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator,
boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((ServerWorld) (Object) this);
FabricEntryPoint.getTerraPlugin().logger().info("Registered world " + this);
@@ -5,6 +5,7 @@ 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
@@ -6,26 +6,27 @@ import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Optional;
@Mixin(BiomeEffects.class)
public interface BiomeEffectsAccessor {
@Accessor("fogColor")
int getFogColor();
@Accessor("waterColor")
int getWaterColor();
@Accessor("waterFogColor")
int getWaterFogColor();
@Accessor("skyColor")
int getSkyColor();
@Accessor("foliageColor")
Optional<Integer> getFoliageColor();
@Accessor("grassColor")
Optional<Integer> getGrassColor();
@Accessor("grassColorModifier")
BiomeEffects.GrassColorModifier getGrassColorModifier();
}
@@ -8,13 +8,14 @@ import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.List;
@Mixin(GeneratorType.class)
public interface GeneratorTypeAccessor {
@Accessor("VALUES")
static List<GeneratorType> getValues() {
throw new UnsupportedOperationException();
}
@Mutable
@Accessor("translationKey")
void setTranslationKey(Text translationKey);
@@ -7,6 +7,7 @@ import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(MobSpawnerLogic.class)
public interface MobSpawnerLogicAccessor {
@Invoker("getEntityId")
@@ -8,6 +8,7 @@ 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")
@@ -6,6 +6,7 @@ import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(Biome.class)
@Implements(@Interface(iface = com.dfsek.terra.api.world.biome.Biome.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class BiomeMixin {
@@ -1,12 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.util.collection.MaterialSet;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.FabricEntryPoint;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.world.ServerWorldAccess;
@@ -22,13 +15,22 @@ import java.util.Locale;
import java.util.Random;
import java.util.Set;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.util.collection.MaterialSet;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.FabricEntryPoint;
@Mixin(ConfiguredFeature.class)
@Implements(@Interface(iface = Tree.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class ConfiguredFeatureMixin {
@Shadow
public abstract boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos);
@SuppressWarnings({"ConstantConditions", "try"})
@SuppressWarnings({ "ConstantConditions", "try" })
public boolean terra$plant(Vector3 l, World world, Random r) {
String id = BuiltinRegistries.CONFIGURED_FEATURE.getId((ConfiguredFeature<?, ?>) (Object) this).toString();
try(ProfileFrame ignore = FabricEntryPoint.getTerraPlugin().getProfiler().profile("fabric_tree:" + id.toLowerCase(Locale.ROOT))) {
@@ -37,10 +39,10 @@ public abstract class ConfiguredFeatureMixin {
return generate(fabricWorldAccess, generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
}
}
public Set<BlockType> terra$getSpawnable() {
return MaterialSet.get(FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:grass_block"),
FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:podzol"),
FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:mycelium"));
FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:podzol"),
FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:mycelium"));
}
}
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.block;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
@@ -13,6 +10,11 @@ import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.fabric.util.FabricAdapter;
@Mixin(net.minecraft.block.entity.BlockEntity.class)
@Implements(@Interface(iface = BlockEntity.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class BlockEntityMixin {
@@ -22,36 +24,36 @@ public abstract class BlockEntityMixin {
@Shadow
@Nullable
protected World world;
@Shadow
public abstract net.minecraft.block.BlockState getCachedState();
@Shadow
public abstract boolean hasWorld();
@Intrinsic
public Object terra$getHandle() {
return this;
}
public int terra$getX() {
return pos.getX();
}
public int terra$getY() {
return pos.getY();
}
public int terra$getZ() {
return pos.getZ();
}
public BlockState terra$getBlockData() {
return FabricAdapter.adapt(getCachedState());
}
public boolean terra$update(boolean applyPhysics) {
if(hasWorld()) world.getChunk(pos).setBlockEntity((net.minecraft.block.entity.BlockEntity) (Object) this);
return true;
}
public int terra$getX() {
return pos.getX();
}
public int terra$getY() {
return pos.getY();
}
public int terra$getZ() {
return pos.getZ();
}
public BlockState terra$getBlockData() {
return FabricAdapter.adapt(getCachedState());
}
}
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.block;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import org.spongepowered.asm.mixin.Implements;
@@ -11,25 +8,30 @@ import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.fabric.util.FabricAdapter;
@Mixin(Block.class)
@Implements(@Interface(iface = BlockType.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class BlockMixin {
@Shadow
private net.minecraft.block.BlockState defaultState;
@Intrinsic
public Object terra$getHandle() {
return this;
}
public BlockState terra$getDefaultData() {
return FabricAdapter.adapt(defaultState);
}
public boolean terra$isSolid() {
return defaultState.isOpaque();
}
@SuppressWarnings("ConstantConditions")
public boolean terra$isWater() {
return ((Object) this) == Blocks.WATER;
@@ -1,21 +1,23 @@
package com.dfsek.terra.fabric.mixin.implementations.block.state;
import com.dfsek.terra.api.block.entity.Container;
import com.dfsek.terra.api.inventory.Inventory;
import com.dfsek.terra.fabric.mixin.implementations.block.BlockEntityMixin;
import net.minecraft.block.entity.LootableContainerBlockEntity;
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.Container;
import com.dfsek.terra.api.inventory.Inventory;
import com.dfsek.terra.fabric.mixin.implementations.block.BlockEntityMixin;
@Mixin(LootableContainerBlockEntity.class)
@Implements(@Interface(iface = Container.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class LootableContainerBlockEntityMixin extends BlockEntityMixin {
public Inventory terra$getInventory() {
return (Inventory) this;
}
@Intrinsic
public Object terra$getHandle() {
return this;
@@ -1,10 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.block.state;
import com.dfsek.terra.api.block.entity.MobSpawner;
import com.dfsek.terra.api.block.entity.SerialState;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.mixin.access.MobSpawnerLogicAccessor;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
@@ -18,80 +13,87 @@ 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;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.mixin.access.MobSpawnerLogicAccessor;
@Mixin(MobSpawnerBlockEntity.class)
@Implements(@Interface(iface = MobSpawner.class, prefix = "terra$", remap = Interface.Remap.NONE))
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(((MobSpawnerLogicAccessor) getLogic()).callGetEntityId(world, pos));
}
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) {
@@ -1,7 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.block.state;
import com.dfsek.terra.api.block.entity.SerialState;
import com.dfsek.terra.api.block.entity.Sign;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@@ -12,16 +10,24 @@ 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$", remap = Interface.Remap.NONE))
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, new LiteralText(line));
}
public @NotNull String[] terra$getLines() {
String[] lines = new String[texts.length];
for(int i = 0; i < texts.length; i++) {
@@ -29,15 +35,11 @@ public abstract class SignBlockEntityMixin {
}
return lines;
}
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
return texts[index].asString();
}
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
setTextOnRow(index, new LiteralText(line));
}
public void terra$applyState(String state) {
SerialState.parse(state).forEach((k, v) -> {
if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k);
@@ -1,9 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.chunk;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.block.FabricBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ChunkRegion;
@@ -14,32 +10,40 @@ 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;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.block.FabricBlockState;
@Mixin(ChunkRegion.class)
@Implements(@Interface(iface = Chunk.class, prefix = "terraChunk$", remap = Interface.Remap.NONE))
public abstract class ChunkRegionMixin {
@Final
@Shadow
private ChunkPos centerPos;
public void terraChunk$setBlock(int x, int y, int z, @NotNull BlockState blockState, boolean physics) {
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4)),
((FabricBlockState) blockState).getHandle(), 0);
}
public @NotNull BlockState terraChunk$getBlock(int x, int y, int z) {
return new FabricBlockState(
((ChunkRegion) (Object) this).getBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4))));
}
public int terraChunk$getX() {
return centerPos.x;
}
public int terraChunk$getZ() {
return centerPos.z;
}
public World terraChunk$getWorld() {
return (World) this;
}
public @NotNull BlockState terraChunk$getBlock(int x, int y, int z) {
return new FabricBlockState(((ChunkRegion) (Object) this).getBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4))));
}
public void terraChunk$setBlock(int x, int y, int z, @NotNull BlockState blockState, boolean physics) {
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4)), ((FabricBlockState) blockState).getHandle(), 0);
}
// getHandle already added in world/ChunkRegionMixin.
}
@@ -1,9 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.chunk;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.block.FabricBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.WorldChunk;
import org.jetbrains.annotations.NotNull;
@@ -15,44 +11,50 @@ 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.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.block.FabricBlockState;
@Mixin(WorldChunk.class)
@Implements(@Interface(iface = Chunk.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class WorldChunkMixin {
@Final
@Shadow
private 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 int terra$getX() {
return ((net.minecraft.world.chunk.Chunk) this).getPos().x;
}
public int terra$getZ() {
return ((net.minecraft.world.chunk.Chunk) this).getPos().z;
}
public World terra$getWorld() {
return (World) world;
}
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
return new FabricBlockState(getBlockState(new BlockPos(x, y, z)));
}
public void terra$setBlock(int x, int y, int z, BlockState data, boolean physics) {
setBlockState(new BlockPos(x, y, z), ((FabricBlockState) data).getHandle(), false);
}
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
((net.minecraft.world.chunk.Chunk) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockState) blockState).getHandle(), false);
}
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
return new FabricBlockState(getBlockState(new BlockPos(x, y, z)));
}
public int terra$getX() {
return ((net.minecraft.world.chunk.Chunk) this).getPos().x;
}
public int terra$getZ() {
return ((net.minecraft.world.chunk.Chunk) this).getPos().z;
}
public World terra$getWorld() {
return (World) world;
}
@Intrinsic
public Object terra$getHandle() {
return this;
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.chunk.data;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.fabric.block.FabricBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.ProtoChunk;
import org.jetbrains.annotations.NotNull;
@@ -12,25 +9,30 @@ 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.generator.ChunkData;
import com.dfsek.terra.fabric.block.FabricBlockState;
@Mixin(ProtoChunk.class)
@Implements(@Interface(iface = ChunkData.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class ProtoChunkMixin {
@Shadow
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
return new FabricBlockState(getBlockState(new BlockPos(x, y, z)));
}
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
((net.minecraft.world.chunk.Chunk) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockState) blockState).getHandle(), false);
}
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
return new FabricBlockState(getBlockState(new BlockPos(x, y, z)));
}
@Intrinsic
public Object terra$getHandle() {
return this;
}
public int terra$getMaxHeight() {
return 255; // TODO: 1.17 - Implement dynamic height.
}
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.entity;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.entity.Entity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@@ -15,38 +12,43 @@ import org.spongepowered.asm.mixin.Shadow;
import java.util.UUID;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.util.FabricAdapter;
@Mixin(Entity.class)
@Implements(@Interface(iface = com.dfsek.terra.api.entity.Entity.class, prefix = "terra$", remap = Interface.Remap.NONE))
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);
@Shadow
public abstract void sendSystemMessage(Text message, UUID senderUuid);
@Intrinsic
public Object terra$getHandle() {
return this;
}
public Vector3 terra$position() {
return FabricAdapter.adapt(blockPos);
}
public void terra$position(Vector3 location) {
teleport(location.getX(), location.getY(), location.getZ());
}
public World terra$world() {
return (World) world;
}
public void terra$sendMessage(String message) {
sendSystemMessage(new LiteralText(message), UUID.randomUUID()); // TODO: look into how this actually works and make it less jank
}
@@ -6,6 +6,7 @@ import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(EntityType.class)
@Implements(@Interface(iface = com.dfsek.terra.api.entity.EntityType.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class EntityTypeMixin {
@@ -1,11 +1,13 @@
package com.dfsek.terra.fabric.mixin.implementations.entity;
import com.dfsek.terra.api.entity.Player;
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$", remap = Interface.Remap.NONE))
public abstract class PlayerEntityMixin extends EntityMixin {
@@ -1,6 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.entity;
import com.dfsek.terra.api.entity.CommandSender;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@@ -10,16 +9,19 @@ import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import com.dfsek.terra.api.entity.CommandSender;
@Mixin(ServerCommandSource.class)
@Implements(@Interface(iface = CommandSender.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class ServerCommandSourceMixin {
@Shadow
public abstract void sendFeedback(Text message, boolean broadcastToOps);
public void terra$sendMessage(String message) {
sendFeedback(new LiteralText(message), true);
}
@Intrinsic
public Object terra$getHandle() {
return this;
@@ -1,7 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.inventory;
import com.dfsek.terra.api.inventory.Inventory;
import com.dfsek.terra.api.inventory.ItemStack;
import net.minecraft.block.entity.LockableContainerBlockEntity;
import net.minecraft.item.Items;
import org.spongepowered.asm.mixin.Implements;
@@ -9,6 +7,10 @@ import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
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$", remap = Interface.Remap.NONE))
public class LockableContainerBlockEntityMixin {
@@ -16,19 +18,19 @@ public class LockableContainerBlockEntityMixin {
public Object terra$getHandle() {
return this;
}
@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;
}
@SuppressWarnings("ConstantConditions")
public void terra$setItem(int slot, ItemStack newStack) {
((LockableContainerBlockEntity) (Object) this).setStack(slot, (net.minecraft.item.ItemStack) (Object) newStack);
}
}
@@ -1,6 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.inventory.item;
import com.dfsek.terra.api.inventory.ItemStack;
import net.minecraft.item.Item;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
@@ -8,22 +7,25 @@ import org.spongepowered.asm.mixin.Intrinsic;
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$", remap = Interface.Remap.NONE))
public abstract class ItemMixin {
@Shadow
public abstract int getMaxDamage();
@Intrinsic
public Object terra$getHandle() {
return this;
}
@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,7 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.inventory.item;
import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.ItemMeta;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Nullable;
@@ -11,52 +9,56 @@ 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$", remap = Interface.Remap.NONE))
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 setTag(@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) {
setTag(((ItemStack) (Object) meta).getTag());
}
@Intrinsic
public Object terra$getHandle() {
return this;
}
@Intrinsic
public boolean terra$isDamageable() {
return isDamageable();
}
@Intrinsic
public Object terra$getHandle() {
return this;
}
}
@@ -1,6 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.inventory.meta;
import com.dfsek.terra.api.inventory.ItemStack;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Implements;
@@ -11,30 +10,33 @@ 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$", remap = Interface.Remap.NONE))
public abstract class EnchantmentMixin {
@Shadow
public abstract boolean isAcceptableItem(net.minecraft.item.ItemStack stack);
@Shadow
public abstract boolean canCombine(Enchantment other);
@Intrinsic
public Object terra$getHandle() {
return this;
}
@SuppressWarnings("ConstantConditions")
public boolean terra$canEnchantItem(ItemStack itemStack) {
return isAcceptableItem((net.minecraft.item.ItemStack) (Object) itemStack);
}
public String terra$getID() {
return Objects.requireNonNull(Registry.ENCHANTMENT.getId((Enchantment) (Object) this)).toString();
}
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,6 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.inventory.meta;
import com.dfsek.terra.api.inventory.item.Damageable;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
@@ -8,29 +7,32 @@ 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$", remap = Interface.Remap.NONE))
public abstract class ItemStackDamageableMixin {
@Shadow
public abstract boolean isDamaged();
@Shadow
public abstract int getDamage();
@Shadow
public abstract void setDamage(int damage);
public boolean terra$hasDamage() {
return isDamaged();
}
@Intrinsic
public void terra$setDamage(int damage) {
setDamage(damage);
}
@Intrinsic
public int terra$getDamage() {
return getDamage();
}
@Intrinsic
public void terra$setDamage(int damage) {
setDamage(damage);
}
public boolean terra$hasDamage() {
return isDamaged();
}
}
@@ -1,7 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.inventory.meta;
import com.dfsek.terra.api.inventory.item.Enchantment;
import com.dfsek.terra.api.inventory.item.ItemMeta;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
@@ -16,36 +14,40 @@ 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$", remap = Interface.Remap.NONE))
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);
@Intrinsic
public Object terra$getHandle() {
return this;
}
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;
}
public void terra$addEnchantment(Enchantment enchantment, int level) {
addEnchantment((net.minecraft.enchantment.Enchantment) enchantment, level);
}
}
@@ -2,4 +2,5 @@
* Mixins in this package implement Terra
* interfaces in Minecraft classes.
*/
package com.dfsek.terra.fabric.mixin.implementations;
@@ -1,19 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.world;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
import com.dfsek.terra.fabric.util.FabricUtil;
import net.minecraft.block.FluidBlock;
import net.minecraft.fluid.Fluid;
import net.minecraft.server.world.ServerWorld;
@@ -35,89 +21,112 @@ 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.WorldConfig;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
import com.dfsek.terra.fabric.util.FabricUtil;
@Mixin(ChunkRegion.class)
@Implements(@Interface(iface = World.class, prefix = "terraWorld$", remap = Interface.Remap.NONE))
public abstract class ChunkRegionMixin {
private WorldConfig config;
@Shadow
@Final
private ServerWorld world;
@Shadow
@Final
private long seed;
@Shadow
public abstract TickScheduler<Fluid> getFluidTickScheduler();
public int terraWorld$getMaxHeight() {
return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight();
}
@Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/server/world/ServerWorld;Ljava/util/List;Lnet/minecraft/world/chunk/ChunkStatus;I)V")
public void injectConstructor(ServerWorld world, List<net.minecraft.world.chunk.Chunk> list, ChunkStatus chunkStatus, int i, CallbackInfo ci) {
@Inject(at = @At("RETURN"),
method = "<init>(Lnet/minecraft/server/world/ServerWorld;Ljava/util/List;Lnet/minecraft/world/chunk/ChunkStatus;I)V")
public void injectConstructor(ServerWorld world, List<net.minecraft.world.chunk.Chunk> list, ChunkStatus chunkStatus, int i,
CallbackInfo ci) {
this.config = ((World) world).getConfig();
}
public Chunk terraWorld$getChunkAt(int x, int z) {
return (Chunk) ((ChunkRegion) (Object) this).getChunk(x, z);
}
public BlockEntity terraWorld$getBlockState(int x, int y, int z) {
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
}
@SuppressWarnings("deprecation")
public Entity terraWorld$spawnEntity(Vector3 location, EntityType entityType) {
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(((ChunkRegion) (Object) this).toServerWorld());
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(
((ChunkRegion) (Object) this).toServerWorld());
entity.setPos(location.getX(), location.getY(), location.getZ());
((ChunkRegion) (Object) this).spawnEntity(entity);
return (Entity) entity;
}
@Intrinsic(displace = true)
public BlockState terraWorld$getBlockData(int x, int y, int z) {
BlockPos pos = new BlockPos(x, y, z);
return new FabricBlockState(((ChunkRegion) (Object) this).getBlockState(pos));
}
@Intrinsic(displace = true)
public void terraWorld$setBlockData(int x, int y, int z, BlockState data, boolean physics) {
BlockPos pos = new BlockPos(x, y, z);
((ChunkRegion) (Object) this).setBlockState(pos, ((FabricBlockState) data).getHandle(), physics ? 3 : 1042);
if(physics && ((FabricBlockState) data).getHandle().getBlock() instanceof FluidBlock) {
getFluidTickScheduler().schedule(pos, ((FluidBlock) ((FabricBlockState) data).getHandle().getBlock()).getFluidState(((FabricBlockState) data).getHandle()).getFluid(), 0);
getFluidTickScheduler().schedule(pos, ((FluidBlock) ((FabricBlockState) data).getHandle().getBlock()).getFluidState(
((FabricBlockState) data).getHandle()).getFluid(), 0);
}
}
@Intrinsic
public long terraWorld$getSeed() {
return seed;
}
public int terraWorld$getMaxHeight() {
return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight();
}
public Chunk terraWorld$getChunkAt(int x, int z) {
return (Chunk) ((ChunkRegion) (Object) this).getChunk(x, z);
}
@Intrinsic(displace = true)
public BlockState terraWorld$getBlockData(int x, int y, int z) {
BlockPos pos = new BlockPos(x, y, z);
return new FabricBlockState(((ChunkRegion) (Object) this).getBlockState(pos));
}
public BlockEntity terraWorld$getBlockState(int x, int y, int z) {
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
}
public int terraWorld$getMinHeight() {
return ((ChunkRegion) (Object) this).getBottomY();
}
public ChunkGenerator terraWorld$getGenerator() {
return ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator()).getHandle();
}
@SuppressWarnings("deprecation")
public BiomeProvider terraWorld$getBiomeProvider() {
return ((TerraBiomeSource) ((ChunkRegion) (Object) this).toServerWorld()
.getChunkManager()
.getChunkGenerator()
.getBiomeSource()).getProvider();
}
public WorldConfig terraWorld$getConfig() {
return config;
}
@Intrinsic
public Object terraWorld$getHandle() {
return this;
}
public ChunkGenerator terraWorld$getGenerator() {
return ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator()).getHandle();
}
@SuppressWarnings("deprecation")
public BiomeProvider terraWorld$getBiomeProvider() {
return ((TerraBiomeSource) ((ChunkRegion) (Object) this).toServerWorld().getChunkManager().getChunkGenerator().getBiomeSource()).getProvider();
}
public WorldConfig terraWorld$getConfig() {
return config;
}
/**
* We need regions delegating to the same world
* to have the same hashcode. This
@@ -132,12 +141,14 @@ public abstract class ChunkRegionMixin {
public int hashCode() {
return world.hashCode();
}
/**
* Overridden in the same manner as {@link #hashCode()}
*
* @param other Another object
*
* @return Whether this world is the same as other.
*
* @see #hashCode()
*/
@Override
@@ -1,19 +1,5 @@
package com.dfsek.terra.fabric.mixin.implementations.world;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
import com.dfsek.terra.fabric.util.FabricUtil;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerChunkManager;
@@ -39,83 +25,110 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
import java.util.concurrent.Executor;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
import com.dfsek.terra.fabric.util.FabricUtil;
@Mixin(ServerWorld.class)
@Implements(@Interface(iface = World.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class ServerWorldMixin {
private WorldConfig config;
@Shadow
public abstract long getSeed();
@Shadow
@Final
private ServerChunkManager chunkManager;
@Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/server/MinecraftServer;Ljava/util/concurrent/Executor;Lnet/minecraft/world/level/storage/LevelStorage$Session;Lnet/minecraft/world/level/ServerWorldProperties;Lnet/minecraft/util/registry/RegistryKey;Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/server/WorldGenerationProgressListener;Lnet/minecraft/world/gen/chunk/ChunkGenerator;ZJLjava/util/List;Z)V")
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<net.minecraft.world.World> worldKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, net.minecraft.world.gen.chunk.ChunkGenerator chunkGenerator, boolean debugWorld, long seed, List<Spawner> spawners, boolean shouldTickTime, CallbackInfo ci) {
@Shadow
public abstract long getSeed();
@Inject(at = @At("RETURN"),
method = "<init>(Lnet/minecraft/server/MinecraftServer;Ljava/util/concurrent/Executor;" +
"Lnet/minecraft/world/level/storage/LevelStorage$Session;Lnet/minecraft/world/level/ServerWorldProperties;" +
"Lnet/minecraft/util/registry/RegistryKey;Lnet/minecraft/world/dimension/DimensionType;" +
"Lnet/minecraft/server/WorldGenerationProgressListener;Lnet/minecraft/world/gen/chunk/ChunkGenerator;" +
"ZJLjava/util/List;Z)V")
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session,
ServerWorldProperties properties, RegistryKey<net.minecraft.world.World> worldKey,
DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener,
net.minecraft.world.gen.chunk.ChunkGenerator chunkGenerator, boolean debugWorld, long seed,
List<Spawner> spawners, boolean shouldTickTime, CallbackInfo ci) {
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
config = ((FabricChunkGeneratorWrapper) chunkGenerator).getPack().toWorldConfig((World) this);
}
}
public int terra$getMaxHeight() {
return (((ServerWorld) (Object) this).getBottomY()) + ((ServerWorld) (Object) this).getHeight();
}
public Chunk terra$getChunkAt(int x, int z) {
return (Chunk) ((ServerWorld) (Object) this).getChunk(x, z);
}
public BlockEntity terra$getBlockState(int x, int y, int z) {
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
}
public BlockState terra$getBlockData(int x, int y, int z) {
return new FabricBlockState(((ServerWorld) (Object) this).getBlockState(new BlockPos(x, y, z)));
}
public void terra$setBlockData(int x, int y, int z, BlockState data, boolean physics) {
BlockPos pos = new BlockPos(x, y, z);
((ServerWorld) (Object) this).setBlockState(pos, ((FabricBlockState) data).getHandle(), physics ? 3 : 1042);
}
public Entity terra$spawnEntity(Vector3 location, EntityType entityType) {
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(((ServerWorld) (Object) this));
entity.setPos(location.getX(), location.getY(), location.getZ());
((ServerWorld) (Object) this).spawnEntity(entity);
return (Entity) entity;
}
public void terra$setBlockData(int x, int y, int z, BlockState data, boolean physics) {
BlockPos pos = new BlockPos(x, y, z);
((ServerWorld) (Object) this).setBlockState(pos, ((FabricBlockState) data).getHandle(), physics ? 3 : 1042);
}
@Intrinsic
public long terra$getSeed() {
return getSeed();
}
public int terra$getMaxHeight() {
return (((ServerWorld) (Object) this).getBottomY()) + ((ServerWorld) (Object) this).getHeight();
}
public Chunk terra$getChunkAt(int x, int z) {
return (Chunk) ((ServerWorld) (Object) this).getChunk(x, z);
}
public BlockState terra$getBlockData(int x, int y, int z) {
return new FabricBlockState(((ServerWorld) (Object) this).getBlockState(new BlockPos(x, y, z)));
}
public BlockEntity terra$getBlockState(int x, int y, int z) {
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
}
public int terra$getMinHeight() {
return ((ServerWorld) (Object) this).getBottomY();
}
public ChunkGenerator terra$getGenerator() {
return ((FabricChunkGeneratorWrapper) chunkManager.getChunkGenerator()).getHandle();
}
public BiomeProvider terra$getBiomeProvider() {
return ((TerraBiomeSource) ((ServerWorld) (Object) this).getChunkManager().getChunkGenerator().getBiomeSource()).getProvider();
}
public WorldConfig terra$getConfig() {
return config;
}
@Intrinsic
public Object terra$getHandle() {
return this;
}
public ChunkGenerator terra$getGenerator() {
return ((FabricChunkGeneratorWrapper) chunkManager.getChunkGenerator()).getHandle();
}
public BiomeProvider terra$getBiomeProvider() {
return ((TerraBiomeSource) ((ServerWorld) (Object) this).getChunkManager().getChunkGenerator().getBiomeSource()).getProvider();
}
public WorldConfig terra$getConfig() {
return config;
}
/**
* Overridden in the same manner as {@link ChunkRegionMixin#hashCode()}
*
* @param other Another object
*
* @return Whether this world is the same as other.
*
* @see ChunkRegionMixin#hashCode()
*/
@SuppressWarnings("ConstantConditions")
@@ -1,9 +1,5 @@
package com.dfsek.terra.fabric.mixin.lifecycle.client;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.fabric.generation.TerraGeneratorType;
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.client.world.GeneratorType;
@@ -13,11 +9,20 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.generation.TerraGeneratorType;
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Inject(method = "<init>", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/util/WindowProvider;createWindow(Lnet/minecraft/client/WindowSettings;Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/client/util/Window;", // sorta arbitrary position, after mod init, before window opens
shift = At.Shift.BEFORE))
target = "Lnet/minecraft/client/util/WindowProvider;createWindow" +
"(Lnet/minecraft/client/WindowSettings;Ljava/lang/String;Ljava/lang/String;)" +
"Lnet/minecraft/client/util/Window;",
// sorta arbitrary position, after mod init, before window opens
shift = At.Shift.BEFORE))
public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) {
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(new PlatformInitializationEvent());
FabricEntryPoint.getTerraPlugin().getConfigRegistry().forEach(pack -> {
@@ -1,4 +1,5 @@
/**
* Mixins that inject behavior into the client/server lifecycle.
*/
package com.dfsek.terra.fabric.mixin.lifecycle;
@@ -1,11 +1,5 @@
package com.dfsek.terra.fabric.mixin.lifecycle.server;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.TerraPluginImpl;
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
import com.google.common.base.MoreObjects;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
@@ -23,16 +17,28 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Properties;
import java.util.Random;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.TerraPluginImpl;
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
@Mixin(GeneratorOptions.class)
public abstract class GeneratorOptionsMixin {
@Inject(method = "fromProperties(Lnet/minecraft/util/registry/DynamicRegistryManager;Ljava/util/Properties;)Lnet/minecraft/world/gen/GeneratorOptions;", at = @At("HEAD"), cancellable = true)
private static void fromProperties(DynamicRegistryManager registryManager, Properties properties, CallbackInfoReturnable<GeneratorOptions> cir) {
@Inject(method = "fromProperties(Lnet/minecraft/util/registry/DynamicRegistryManager;Ljava/util/Properties;)" +
"Lnet/minecraft/world/gen/GeneratorOptions;",
at = @At("HEAD"),
cancellable = true)
private static void fromProperties(DynamicRegistryManager registryManager, Properties properties,
CallbackInfoReturnable<GeneratorOptions> cir) {
if(properties.get("level-type") == null) {
return;
}
TerraPluginImpl main = FabricEntryPoint.getTerraPlugin();
String prop = properties.get("level-type").toString().trim();
if(prop.startsWith("Terra")) {
String seed = (String) MoreObjects.firstNonNull(properties.get("level-seed"), "");
@@ -47,23 +53,31 @@ public abstract class GeneratorOptionsMixin {
l = seed.hashCode();
}
}
String generate_structures = (String) properties.get("generate-structures");
boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures);
Registry<DimensionType> dimensionTypes = registryManager.get(Registry.DIMENSION_TYPE_KEY);
Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
Registry<ChunkGeneratorSettings> chunkGeneratorSettings = registryManager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(dimensionTypes, biomeRegistry, chunkGeneratorSettings, l);
SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(dimensionTypes, biomeRegistry,
chunkGeneratorSettings, l);
prop = prop.substring(prop.indexOf(":") + 1);
ConfigPack config = main.getConfigRegistry().get(prop);
if(config == null) throw new IllegalArgumentException("No such pack " + prop);
main.getEventManager().callEvent(new BiomeRegistrationEvent(registryManager)); // register biomes
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false, GeneratorOptions.getRegistryWithReplacedOverworldGenerator(dimensionTypes, dimensionOptions, new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, l, config), l, config))));
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false,
GeneratorOptions.getRegistryWithReplacedOverworldGenerator(dimensionTypes,
dimensionOptions,
new FabricChunkGeneratorWrapper(
new TerraBiomeSource(
biomeRegistry,
l, config),
l, config))));
}
}
}
@@ -1,17 +1,23 @@
package com.dfsek.terra.fabric.mixin.lifecycle.server;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import net.minecraft.server.Main;
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.CallbackInfo;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.fabric.FabricEntryPoint;
@Mixin(Main.class)
public class ServerMainMixin {
@Inject(method = "main([Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DynamicRegistryManager;create()Lnet/minecraft/util/registry/DynamicRegistryManager$Impl;"))
@Inject(method = "main([Ljava/lang/String;)V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/util/registry/DynamicRegistryManager;create()" +
"Lnet/minecraft/util/registry/DynamicRegistryManager$Impl;"))
private static void injectConstructor(String[] args, CallbackInfo ci) {
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(new PlatformInitializationEvent()); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(
new PlatformInitializationEvent()); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
}
}
@@ -1,5 +1,12 @@
package com.dfsek.terra.fabric.util;
import net.minecraft.block.BlockState;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.WallShape;
import net.minecraft.block.enums.WireConnection;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.state.properties.enums.Half;
import com.dfsek.terra.api.block.state.properties.enums.RailShape;
@@ -7,26 +14,21 @@ import com.dfsek.terra.api.block.state.properties.enums.RedstoneConnection;
import com.dfsek.terra.api.block.state.properties.enums.WallHeight;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.fabric.block.FabricBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.WallShape;
import net.minecraft.block.enums.WireConnection;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
public final class FabricAdapter {
public static BlockPos adapt(Vector3 v) {
return new BlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ());
}
public static Vector3 adapt(BlockPos pos) {
return new Vector3(pos.getX(), pos.getY(), pos.getZ());
}
public static FabricBlockState adapt(BlockState state) {
return new FabricBlockState(state);
}
public static Direction adapt(com.dfsek.terra.api.block.state.properties.enums.Direction direction) {
switch(direction) {
case SOUTH:
@@ -44,7 +46,7 @@ public final class FabricAdapter {
}
throw new IllegalArgumentException();
}
public static com.dfsek.terra.api.block.state.properties.enums.Direction adapt(Direction direction) {
switch(direction) {
case SOUTH:
@@ -62,7 +64,7 @@ public final class FabricAdapter {
}
throw new IllegalArgumentException();
}
public static WallHeight adapt(WallShape shape) {
switch(shape) {
case LOW:
@@ -74,7 +76,7 @@ public final class FabricAdapter {
}
throw new IllegalArgumentException();
}
public static WallShape adapt(WallHeight shape) {
switch(shape) {
case LOW:
@@ -86,7 +88,7 @@ public final class FabricAdapter {
}
throw new IllegalArgumentException();
}
public static RedstoneConnection adapt(WireConnection connection) {
switch(connection) {
case NONE:
@@ -98,7 +100,7 @@ public final class FabricAdapter {
}
throw new IllegalArgumentException();
}
public static WireConnection adapt(RedstoneConnection connection) {
switch(connection) {
case NONE:
@@ -110,8 +112,8 @@ public final class FabricAdapter {
}
throw new IllegalArgumentException();
}
public static Half adapt(BlockHalf half) {
switch(half) {
case BOTTOM:
@@ -122,7 +124,7 @@ public final class FabricAdapter {
throw new IllegalStateException();
}
}
public static BlockHalf adapt(Half half) {
switch(half) {
case TOP:
@@ -133,7 +135,7 @@ public final class FabricAdapter {
throw new IllegalStateException();
}
}
public static RailShape adapt(net.minecraft.block.enums.RailShape railShape) {
switch(railShape) {
case EAST_WEST:
@@ -159,7 +161,7 @@ public final class FabricAdapter {
}
throw new IllegalStateException();
}
public static net.minecraft.block.enums.RailShape adapt(RailShape railShape) {
switch(railShape) {
case EAST_WEST:
@@ -185,8 +187,8 @@ public final class FabricAdapter {
}
throw new IllegalStateException();
}
public static Axis adapt(Direction.Axis axis) {
switch(axis) {
case X:
@@ -199,7 +201,7 @@ public final class FabricAdapter {
throw new IllegalStateException();
}
}
public static Direction.Axis adapt(Axis axis) {
switch(axis) {
case Z:
@@ -1,13 +1,5 @@
package com.dfsek.terra.fabric.util;
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;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
import com.mojang.serialization.Lifecycle;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.block.entity.MobSpawnerBlockEntity;
@@ -31,33 +23,45 @@ import java.util.Locale;
import java.util.Map;
import java.util.function.Supplier;
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;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
public final class FabricUtil {
public static String createBiomeID(ConfigPack pack, String biomeID) {
return pack.getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
}
/**
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
*
* @param biome The Terra BiomeBuilder.
* @param pack The ConfigPack this biome belongs to.
*
* @return The Minecraft delegate biome.
*/
public static Biome createBiome(TerraBiome biome, ConfigPack pack, DynamicRegistryManager registryManager) {
// BiomeTemplate template = biome.getTemplate();
Map<String, Integer> colors = new HashMap<>(); // template.getColors();
//TerraFabricPlugin.FabricAddon fabricAddon = TerraFabricPlugin.getInstance().getFabricAddon();
Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
Biome vanilla = ((ProtoBiome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0))).get(biomeRegistry);
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
generationSettings.surfaceBuilder(vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
generationSettings.surfaceBuilder(
vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, FabricEntryPoint.POPULATOR_CONFIGURED_FEATURE);
if(pack.vanillaCaves()) {
for(GenerationStep.Carver carver : GenerationStep.Carver.values()) {
for(Supplier<ConfiguredCarver<?>> configuredCarverSupplier : vanilla.getGenerationSettings().getCarversForStep(carver)) {
@@ -71,12 +75,15 @@ public final class FabricUtil {
PreLoadCompatibilityOptions compatibilityOptions = pair.getLeft();
PostLoadCompatibilityOptions postLoadCompatibilityOptions = pair.getRight();
//TerraFabricPlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome.getTemplate().getID());
//TerraFabricPlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome
.getTemplate().getID());
Registry<ConfiguredStructureFeature<?, ?>> configuredStructureFeatureRegistry = registryManager.get(Registry.CONFIGURED_STRUCTURE_FEATURE_KEY);
Registry<ConfiguredStructureFeature<?, ?>> configuredStructureFeatureRegistry = registryManager.get(Registry
.CONFIGURED_STRUCTURE_FEATURE_KEY);
for(Supplier<ConfiguredStructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().getStructureFeatures()) {
Identifier key = configuredStructureFeatureRegistry.getId(structureFeature.get());
if(!compatibilityOptions.getExcludedBiomeStructures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
if(!compatibilityOptions.getExcludedBiomeStructures().contains(key) && !postLoadCompatibilityOptions
.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
generationSettings.structureFeature(structureFeature.get());
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected structure " + key);
}
@@ -87,7 +94,8 @@ public final class FabricUtil {
for(int step = 0; step < vanilla.getGenerationSettings().getFeatures().size(); step++) {
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().getFeatures().get(step)) {
Identifier key = configuredFeatureRegistry.getId(featureSupplier.get());
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !postLoadCompatibilityOptions
.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
generationSettings.feature(step, featureSupplier);
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
}
@@ -96,7 +104,7 @@ public final class FabricUtil {
}
*/
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
BiomeEffects.Builder effects = new BiomeEffects.Builder()
.waterColor(colors.getOrDefault("water", accessor.getWaterColor()))
@@ -104,7 +112,7 @@ public final class FabricUtil {
.fogColor(colors.getOrDefault("fog", accessor.getFogColor()))
.skyColor(colors.getOrDefault("sky", accessor.getSkyColor()))
.grassColorModifier(accessor.getGrassColorModifier());
if(colors.containsKey("grass")) {
effects.grassColor(colors.get("grass"));
} else {
@@ -115,7 +123,7 @@ public final class FabricUtil {
} else {
accessor.getFoliageColor().ifPresent(effects::foliageColor);
}
return new Biome.Builder()
.precipitation(vanilla.getPrecipitation())
.category(vanilla.getCategory())
@@ -128,15 +136,16 @@ public final class FabricUtil {
.generationSettings(generationSettings.build())
.build();
}
public static <T> void registerOrOverwrite(Registry<T> registry, RegistryKey<Registry<T>> key, Identifier identifier, T item) {
if(registry.containsId(identifier)) {
((MutableRegistry<T>) registry).set(registry.getRawId(registry.get(identifier)), RegistryKey.of(key, identifier), item, Lifecycle.stable());
((MutableRegistry<T>) registry).set(registry.getRawId(registry.get(identifier)), RegistryKey.of(key, identifier), item,
Lifecycle.stable());
} else {
Registry.register(registry, identifier, item);
}
}
public static BlockEntity createState(WorldAccess worldAccess, BlockPos pos) {
net.minecraft.block.entity.BlockEntity entity = worldAccess.getBlockEntity(pos);
if(entity instanceof SignBlockEntity) {
@@ -1,20 +1,22 @@
package com.dfsek.terra.fabric.util;
import com.dfsek.terra.api.world.biome.Biome;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import com.dfsek.terra.api.world.biome.Biome;
public class ProtoBiome implements Biome {
private final Identifier identifier;
public ProtoBiome(Identifier identifier) {
this.identifier = identifier;
}
public net.minecraft.world.biome.Biome get(Registry<net.minecraft.world.biome.Biome> registry) {
return registry.get(identifier);
}
@Override
public Object getHandle() {
return identifier;
@@ -1,8 +1,5 @@
package com.dfsek.terra.fabric.util;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.api.vector.Vector3;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector3;
@@ -10,13 +7,18 @@ import com.sk89q.worldedit.regions.Region;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.api.vector.Vector3;
public final class WorldEditUtil {
public static Pair<Vector3, Vector3> getSelection(Player player) {
WorldEdit worldEdit = WorldEdit.getInstance();
try {
Region selection = worldEdit.getSessionManager()
.get(com.sk89q.worldedit.fabric.FabricAdapter.adaptPlayer((ServerPlayerEntity) player))
.getSelection(com.sk89q.worldedit.fabric.FabricAdapter.adapt((World) player.world()));
.get(com.sk89q.worldedit.fabric.FabricAdapter.adaptPlayer((ServerPlayerEntity) player))
.getSelection(com.sk89q.worldedit.fabric.FabricAdapter.adapt((World) player.world()));
BlockVector3 min = selection.getMinimumPoint();
BlockVector3 max = selection.getMaximumPoint();
Vector3 l1 = new Vector3(min.getBlockX(), min.getBlockY(), min.getBlockZ());
@@ -1,4 +1,4 @@
{
"generator.terra": "Terra"
"generator.terra": "Terra"
}
@@ -1,31 +1,31 @@
{
"schemaVersion": 1,
"id": "terra",
"version": "@VERSION@",
"name": "Terra",
"description": "@DESCRIPTION@",
"authors": [
"dfsek"
],
"contact": {
"homepage": "@WIKI@",
"sources": "@SOURCE@",
"issues": "@ISSUES@"
},
"license": "@LICENSE@",
"icon": "assets/terra/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"com.dfsek.terra.fabric.FabricEntryPoint"
]
},
"mixins": [
"terra.mixins.json"
],
"depends": {
"fabricloader": ">=0.7.4",
"minecraft": "1.17.x"
},
"accessWidener": "terra.accesswidener"
"schemaVersion": 1,
"id": "terra",
"version": "@VERSION@",
"name": "Terra",
"description": "@DESCRIPTION@",
"authors": [
"dfsek"
],
"contact": {
"homepage": "@WIKI@",
"sources": "@SOURCE@",
"issues": "@ISSUES@"
},
"license": "@LICENSE@",
"icon": "assets/terra/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"com.dfsek.terra.fabric.FabricEntryPoint"
]
},
"mixins": [
"terra.mixins.json"
],
"depends": {
"fabricloader": ">=0.7.4",
"minecraft": "1.17.x"
},
"accessWidener": "terra.accesswidener"
}
@@ -1,48 +1,48 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"CommandManagerMixin",
"ServerWorldMixin",
"StructureAccessorAccessor",
"access.BiomeEffectsAccessor",
"access.MobSpawnerLogicAccessor",
"access.StateAccessor",
"implementations.BiomeMixin",
"implementations.ConfiguredFeatureMixin",
"implementations.block.BlockEntityMixin",
"implementations.block.BlockMixin",
"implementations.block.state.LootableContainerBlockEntityMixin",
"implementations.block.state.MobSpawnerBlockEntityMixin",
"implementations.block.state.SignBlockEntityMixin",
"implementations.chunk.ChunkRegionMixin",
"implementations.chunk.WorldChunkMixin",
"implementations.chunk.data.ProtoChunkMixin",
"implementations.entity.EntityMixin",
"implementations.entity.EntityTypeMixin",
"implementations.entity.PlayerEntityMixin",
"implementations.entity.ServerCommandSourceMixin",
"implementations.inventory.LockableContainerBlockEntityMixin",
"implementations.inventory.item.ItemMixin",
"implementations.inventory.item.ItemStackMixin",
"implementations.inventory.meta.EnchantmentMixin",
"implementations.inventory.meta.ItemStackDamageableMixin",
"implementations.inventory.meta.ItemStackMetaMixin",
"implementations.world.ChunkRegionMixin",
"implementations.world.ServerWorldMixin"
],
"client": [
"access.GeneratorTypeAccessor",
"lifecycle.client.MinecraftClientMixin"
],
"server": [
"lifecycle.server.GeneratorOptionsMixin",
"lifecycle.server.ServerMainMixin"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "terra-refmap.json"
"required": true,
"minVersion": "0.8",
"package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"CommandManagerMixin",
"ServerWorldMixin",
"StructureAccessorAccessor",
"access.BiomeEffectsAccessor",
"access.MobSpawnerLogicAccessor",
"access.StateAccessor",
"implementations.BiomeMixin",
"implementations.ConfiguredFeatureMixin",
"implementations.block.BlockEntityMixin",
"implementations.block.BlockMixin",
"implementations.block.state.LootableContainerBlockEntityMixin",
"implementations.block.state.MobSpawnerBlockEntityMixin",
"implementations.block.state.SignBlockEntityMixin",
"implementations.chunk.ChunkRegionMixin",
"implementations.chunk.WorldChunkMixin",
"implementations.chunk.data.ProtoChunkMixin",
"implementations.entity.EntityMixin",
"implementations.entity.EntityTypeMixin",
"implementations.entity.PlayerEntityMixin",
"implementations.entity.ServerCommandSourceMixin",
"implementations.inventory.LockableContainerBlockEntityMixin",
"implementations.inventory.item.ItemMixin",
"implementations.inventory.item.ItemStackMixin",
"implementations.inventory.meta.EnchantmentMixin",
"implementations.inventory.meta.ItemStackDamageableMixin",
"implementations.inventory.meta.ItemStackMetaMixin",
"implementations.world.ChunkRegionMixin",
"implementations.world.ServerWorldMixin"
],
"client": [
"access.GeneratorTypeAccessor",
"lifecycle.client.MinecraftClientMixin"
],
"server": [
"lifecycle.server.GeneratorOptionsMixin",
"lifecycle.server.ServerMainMixin"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "terra-refmap.json"
}