Now things compile on fabric ye
Signed-off-by: liach <liach@users.noreply.github.com>
This commit is contained in:
parent
5193434468
commit
b6c1b94e9d
@ -1 +1 @@
|
||||
Subproject commit 153286cb327b0329824e8dabf5a760bcb6b24b16
|
||||
Subproject commit 6e6959528b41fe1704eb1d301dbee923de6e4742
|
@ -28,7 +28,7 @@ package com.terraforged.api.chunk.surface.builder;
|
||||
import com.terraforged.api.chunk.surface.Surface;
|
||||
import com.terraforged.api.chunk.surface.SurfaceContext;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.surfacebuilders.ConfiguredSurfaceBuilder;
|
||||
import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilder;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@ -48,9 +48,9 @@ public class Delegate implements Surface {
|
||||
|
||||
@Override
|
||||
public void buildSurface(int x, int z, int height, SurfaceContext context) {
|
||||
surfaceBuilder.setSeed(context.seed);
|
||||
surfaceBuilder.initSeed(context.seed);
|
||||
|
||||
surfaceBuilder.buildSurface(
|
||||
surfaceBuilder.generate(
|
||||
context.random,
|
||||
context.chunk,
|
||||
context.biome,
|
||||
|
@ -35,21 +35,11 @@ import com.terraforged.mod.feature.tree.SaplingManager;
|
||||
import com.terraforged.mod.settings.SettingsHelper;
|
||||
import com.terraforged.mod.util.Environment;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.server.ServerStartCallback;
|
||||
import net.fabricmc.fabric.api.event.server.ServerStopCallback;
|
||||
import net.fabricmc.fabric.api.registry.CommandRegistry;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
|
||||
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
||||
|
||||
/**
|
||||
* Author <dags@dags.me>
|
||||
@ -61,7 +51,7 @@ public class TerraForgedMod implements ModInitializer {
|
||||
Log.info("Common setup");
|
||||
ServerStopCallback.EVENT.register(TerraForgedMod::onShutdown);
|
||||
MaterialTags.init();
|
||||
TerraWorld.init();
|
||||
// TerraWorld.init();
|
||||
SaplingManager.init();
|
||||
if (Environment.isDev()) {
|
||||
DataGen.dumpData();
|
||||
@ -69,6 +59,7 @@ public class TerraForgedMod implements ModInitializer {
|
||||
FeatureManager.registerTemplates();
|
||||
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new BiomeTagManager());
|
||||
CommandRegistry.INSTANCE.register(false, TerraCommand::register);
|
||||
// TODO register and fix sapling listener
|
||||
}
|
||||
|
||||
public static void server() {
|
||||
|
@ -1,126 +1,126 @@
|
||||
/*
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 TerraForged
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.terraforged.mod;
|
||||
|
||||
import com.terraforged.core.world.terrain.Terrains;
|
||||
import com.terraforged.mod.biome.provider.BiomeProvider;
|
||||
import com.terraforged.mod.chunk.ChunkGeneratorFactory;
|
||||
import com.terraforged.mod.chunk.TerraChunkGenerator;
|
||||
import com.terraforged.mod.chunk.TerraContext;
|
||||
import com.terraforged.mod.chunk.TerraGenSettings;
|
||||
import com.terraforged.mod.chunk.test.TestChunkGenerator;
|
||||
import com.terraforged.mod.gui.SettingsScreen;
|
||||
import com.terraforged.mod.settings.SettingsHelper;
|
||||
import com.terraforged.mod.settings.TerraSettings;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.CreateWorldScreen;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.OverworldGenSettings;
|
||||
import net.minecraft.world.level.LevelGeneratorType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TerraWorld extends LevelGeneratorType {
|
||||
public static final int VERSION = 1;
|
||||
|
||||
private static final Set<WorldType> types = new HashSet<>();
|
||||
public static final TerraWorld TERRA = new TerraWorld("terraforged", TerraChunkGenerator::new);
|
||||
public static final TerraWorld TEST = new TerraWorld("terratest", TestChunkGenerator::new);
|
||||
|
||||
private final ChunkGeneratorFactory<?> factory;
|
||||
|
||||
public TerraWorld(String name, ChunkGeneratorFactory<?> factory) {
|
||||
super(name);
|
||||
this.factory = factory;
|
||||
setCustomOptions(true);
|
||||
TerraWorld.types.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHorizon(World world) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCloudHeight() {
|
||||
return 260.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator<?> createChunkGenerator(World world) {
|
||||
if (world.getDimension().getType() != DimensionType.OVERWORLD) {
|
||||
return world.getDimension().createChunkGenerator();
|
||||
}
|
||||
|
||||
Log.debug("Creating {} generator", world.getDimension().getType());
|
||||
|
||||
int version = SettingsHelper.getVersion(world.getWorldInfo());
|
||||
TerraSettings settings = SettingsHelper.getSettings(world);
|
||||
SettingsHelper.syncSettings(world.getWorldInfo(), settings, version);
|
||||
|
||||
Terrains terrains = Terrains.create(settings);
|
||||
|
||||
OverworldGenSettings genSettings = new TerraGenSettings(settings.structures);
|
||||
OverworldBiomeProviderSettings biomeSettings = new OverworldBiomeProviderSettings(world.getWorldInfo());
|
||||
biomeSettings.setGeneratorSettings(genSettings);
|
||||
world.getWorldInfo().setGeneratorOptions(NBTHelper.serializeCompact(settings));
|
||||
|
||||
TerraContext context = new TerraContext(world, terrains, settings);
|
||||
BiomeProvider biomeProvider = new BiomeProvider(context);
|
||||
|
||||
return getGeneratorFactory().create(context, biomeProvider, genSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void onCustomizeButton(Minecraft mc, CreateWorldScreen gui) {
|
||||
mc.displayGuiScreen(new SettingsScreen(gui));
|
||||
}
|
||||
|
||||
public ChunkGeneratorFactory<?> getGeneratorFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
Log.info("Registered world type(s)");
|
||||
}
|
||||
|
||||
public static boolean isTerraWorld(IWorld world) {
|
||||
if (world instanceof World) {
|
||||
return types.contains(((World) world).getWorldType());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
///*
|
||||
// *
|
||||
// * MIT License
|
||||
// *
|
||||
// * Copyright (c) 2020 TerraForged
|
||||
// *
|
||||
// * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// * of this software and associated documentation files (the "Software"), to deal
|
||||
// * in the Software without restriction, including without limitation the rights
|
||||
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// * copies of the Software, and to permit persons to whom the Software is
|
||||
// * furnished to do so, subject to the following conditions:
|
||||
// *
|
||||
// * The above copyright notice and this permission notice shall be included in all
|
||||
// * copies or substantial portions of the Software.
|
||||
// *
|
||||
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// * SOFTWARE.
|
||||
// */
|
||||
//
|
||||
//package com.terraforged.mod;
|
||||
//
|
||||
//import com.terraforged.core.world.terrain.Terrains;
|
||||
//import com.terraforged.mod.biome.provider.BiomeProvider;
|
||||
//import com.terraforged.mod.chunk.ChunkGeneratorFactory;
|
||||
//import com.terraforged.mod.chunk.TerraChunkGenerator;
|
||||
//import com.terraforged.mod.chunk.TerraContext;
|
||||
//import com.terraforged.mod.chunk.TerraGenSettings;
|
||||
//import com.terraforged.mod.chunk.test.TestChunkGenerator;
|
||||
//import com.terraforged.mod.gui.SettingsScreen;
|
||||
//import com.terraforged.mod.settings.SettingsHelper;
|
||||
//import com.terraforged.mod.settings.TerraSettings;
|
||||
//import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
//import net.minecraft.client.Minecraft;
|
||||
//import net.minecraft.client.gui.screen.CreateWorldScreen;
|
||||
//import net.minecraft.world.IWorld;
|
||||
//import net.minecraft.world.World;
|
||||
//import net.minecraft.world.WorldType;
|
||||
//import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings;
|
||||
//import net.minecraft.world.dimension.DimensionType;
|
||||
//import net.minecraft.world.gen.ChunkGenerator;
|
||||
//import net.minecraft.world.gen.OverworldGenSettings;
|
||||
//import net.minecraft.world.level.LevelGeneratorType;
|
||||
//import net.minecraftforge.api.distmarker.Dist;
|
||||
//import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
//
|
||||
//import java.util.HashSet;
|
||||
//import java.util.Set;
|
||||
//
|
||||
//public class TerraWorld extends LevelGeneratorType {
|
||||
// public static final int VERSION = 1;
|
||||
//
|
||||
// private static final Set<WorldType> types = new HashSet<>();
|
||||
// public static final TerraWorld TERRA = new TerraWorld("terraforged", TerraChunkGenerator::new);
|
||||
// public static final TerraWorld TEST = new TerraWorld("terratest", TestChunkGenerator::new);
|
||||
//
|
||||
// private final ChunkGeneratorFactory<?> factory;
|
||||
//
|
||||
// public TerraWorld(String name, ChunkGeneratorFactory<?> factory) {
|
||||
// super(name);
|
||||
// this.factory = factory;
|
||||
// setCustomOptions(true);
|
||||
// TerraWorld.types.add(this);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getHorizon(World world) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public float getCloudHeight() {
|
||||
// return 260.0F;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ChunkGenerator<?> createChunkGenerator(World world) {
|
||||
// if (world.getDimension().getType() != DimensionType.OVERWORLD) {
|
||||
// return world.getDimension().createChunkGenerator();
|
||||
// }
|
||||
//
|
||||
// Log.debug("Creating {} generator", world.getDimension().getType());
|
||||
//
|
||||
// int version = SettingsHelper.getVersion(world.getWorldInfo());
|
||||
// TerraSettings settings = SettingsHelper.getSettings(world);
|
||||
// SettingsHelper.syncSettings(world.getWorldInfo(), settings, version);
|
||||
//
|
||||
// Terrains terrains = Terrains.create(settings);
|
||||
//
|
||||
// OverworldGenSettings genSettings = new TerraGenSettings(settings.structures);
|
||||
// OverworldBiomeProviderSettings biomeSettings = new OverworldBiomeProviderSettings(world.getWorldInfo());
|
||||
// biomeSettings.setGeneratorSettings(genSettings);
|
||||
// world.getWorldInfo().setGeneratorOptions(NBTHelper.serializeCompact(settings));
|
||||
//
|
||||
// TerraContext context = new TerraContext(world, terrains, settings);
|
||||
// BiomeProvider biomeProvider = new BiomeProvider(context);
|
||||
//
|
||||
// return getGeneratorFactory().create(context, biomeProvider, genSettings);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @OnlyIn(Dist.CLIENT)
|
||||
// public void onCustomizeButton(Minecraft mc, CreateWorldScreen gui) {
|
||||
// mc.displayGuiScreen(new SettingsScreen(gui));
|
||||
// }
|
||||
//
|
||||
// public ChunkGeneratorFactory<?> getGeneratorFactory() {
|
||||
// return factory;
|
||||
// }
|
||||
//
|
||||
// public static void init() {
|
||||
// Log.info("Registered world type(s)");
|
||||
// }
|
||||
//
|
||||
// public static boolean isTerraWorld(IWorld world) {
|
||||
// if (world instanceof World) {
|
||||
// return types.contains(((World) world).getWorldType());
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
|
@ -7,6 +7,6 @@ public interface DefaultBiome {
|
||||
Biome getBiome(float temperature);
|
||||
|
||||
default Biome getDefaultBiome(float temperature) {
|
||||
return getBiome(temperature).delegate.get();
|
||||
return getBiome(temperature);//.delegate.get(); todo no forge whack
|
||||
}
|
||||
}
|
||||
|
@ -28,14 +28,14 @@ package com.terraforged.mod.decorator;
|
||||
import com.terraforged.api.chunk.column.ColumnDecorator;
|
||||
import com.terraforged.api.chunk.column.DecoratorContext;
|
||||
import com.terraforged.api.material.state.States;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class ChunkPopulator implements ColumnDecorator {
|
||||
|
||||
public static final ChunkPopulator INSTANCE = new ChunkPopulator();
|
||||
|
||||
@Override
|
||||
public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
public void decorate(Chunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
if (context.cell.tag == context.terrains.volcanoPipe && context.cell.riverMask > 0.25F) {
|
||||
int lavaStart = Math.max(context.levels.waterY + 10, y - 30);
|
||||
int lavaEnd = Math.max(5, context.levels.waterY - 10);
|
||||
|
@ -28,7 +28,7 @@ package com.terraforged.mod.decorator.base;
|
||||
import com.terraforged.api.chunk.column.ColumnDecorator;
|
||||
import com.terraforged.api.chunk.column.DecoratorContext;
|
||||
import com.terraforged.api.material.state.States;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@ -37,7 +37,7 @@ public class BedrockDecorator implements ColumnDecorator {
|
||||
private final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
public void decorate(Chunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
fillDown(context, chunk, x, z, 1 + random.nextInt(4), -1, States.BEDROCK.get());
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import com.terraforged.core.util.VariablePredicate;
|
||||
import com.terraforged.core.world.terrain.Terrains;
|
||||
import com.terraforged.mod.chunk.TerraContext;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class CoastDecorator implements ColumnDecorator {
|
||||
|
||||
@ -58,7 +58,7 @@ public class CoastDecorator implements ColumnDecorator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
public void decorate(Chunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
if (context.cell.tag != terrains.beach) {
|
||||
return;
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ import com.terraforged.mod.chunk.TerraContext;
|
||||
import com.terraforged.mod.material.Materials;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
import net.minecraft.world.gen.surfacebuilders.ISurfaceBuilderConfig;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.gen.surfacebuilder.SurfaceConfig;
|
||||
|
||||
public class ErosionDecorator implements ColumnDecorator {
|
||||
|
||||
@ -74,7 +74,7 @@ public class ErosionDecorator implements ColumnDecorator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
public void decorate(Chunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
if (context.cell.value < minY || context.cell.tag == terrain.river || context.cell.tag == terrain.riverBanks) {
|
||||
return;
|
||||
}
|
||||
@ -83,14 +83,14 @@ public class ErosionDecorator implements ColumnDecorator {
|
||||
return;
|
||||
}
|
||||
|
||||
int topY = chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, x, z);
|
||||
int topY = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE_WG, x, z);
|
||||
if (topY - 1 > y) {
|
||||
y = topY;
|
||||
}
|
||||
|
||||
ISurfaceBuilderConfig config = context.biome.getSurfaceBuilderConfig();
|
||||
BlockState top = config.getTop();
|
||||
BlockState middle = config.getUnder();
|
||||
SurfaceConfig config = context.biome.getSurfaceConfig();
|
||||
BlockState top = config.getTopMaterial();
|
||||
BlockState middle = config.getUnderMaterial();
|
||||
|
||||
if (materials.isErodible(top.getBlock())) {
|
||||
BlockState material = getMaterial(x, z, context, top, middle);
|
||||
@ -106,7 +106,7 @@ public class ErosionDecorator implements ColumnDecorator {
|
||||
}
|
||||
}
|
||||
|
||||
protected void erodeRock(DecoratorContext context, IChunk chunk, int dx, int y, int dz) {
|
||||
protected void erodeRock(DecoratorContext context, Chunk chunk, int dx, int y, int dz) {
|
||||
int depth = 32;
|
||||
BlockState material = Blocks.GRAVEL.getDefaultState();
|
||||
// find the uppermost layer of rock & record it's depth
|
||||
@ -127,7 +127,7 @@ public class ErosionDecorator implements ColumnDecorator {
|
||||
}
|
||||
}
|
||||
|
||||
protected void placeScree(IChunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
protected void placeScree(Chunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
float steepness = context.cell.steepness + context.climate.getRand().getValue(x, z, seed2) * SLOPE_MODIFIER;
|
||||
if (steepness < SCREE_STEEPNESS) {
|
||||
return;
|
||||
@ -164,7 +164,7 @@ public class ErosionDecorator implements ColumnDecorator {
|
||||
}
|
||||
|
||||
private static BlockState rock(BlockState state) {
|
||||
if (state.getMaterial() == Material.ROCK) {
|
||||
if (state.getMaterial() == Material.STONE) {
|
||||
return state;
|
||||
}
|
||||
return States.STONE.get();
|
||||
@ -174,7 +174,7 @@ public class ErosionDecorator implements ColumnDecorator {
|
||||
if (state.getMaterial() == Material.ORGANIC) {
|
||||
return States.DIRT.get();
|
||||
}
|
||||
if (state.getMaterial() == Material.ROCK) {
|
||||
if (state.getMaterial() == Material.STONE) {
|
||||
return States.GRAVEL.get();
|
||||
}
|
||||
if (state.getMaterial() == Material.EARTH) {
|
||||
|
@ -29,7 +29,7 @@ import com.terraforged.api.chunk.column.ColumnDecorator;
|
||||
import com.terraforged.api.chunk.column.DecoratorContext;
|
||||
import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer;
|
||||
import com.terraforged.mod.material.geology.GeoManager;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class GeologyDecorator implements ColumnDecorator {
|
||||
|
||||
@ -40,7 +40,7 @@ public class GeologyDecorator implements ColumnDecorator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(IChunk chunk, DecoratorContext context, int x, int dy, int z) {
|
||||
public void decorate(Chunk chunk, DecoratorContext context, int x, int dy, int z) {
|
||||
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class GeologyDecorator implements ColumnDecorator {
|
||||
public void decorate(ChunkSurfaceBuffer buffer, DecoratorContext context, int x, int y, int z) {
|
||||
int top = buffer.getSurfaceBottom();
|
||||
geology.getGeology(context.biome).getStrata(x, z).downwards(x, top, z, (py, state) -> {
|
||||
context.pos.setPos(x, py, z);
|
||||
context.pos.set(x, py, z);
|
||||
buffer.getDelegate().setBlockState(context.pos, state, false);
|
||||
return true;
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ import com.terraforged.mod.chunk.TerraContext;
|
||||
import me.dags.noise.Module;
|
||||
import me.dags.noise.Source;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class RiverDecorator implements ColumnDecorator {
|
||||
|
||||
@ -61,23 +61,23 @@ public class RiverDecorator implements ColumnDecorator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
public void decorate(Chunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
if (context.cell.tag == river) {
|
||||
chunk.setBlockState(context.pos.setPos(x, y, z), dirt, false);
|
||||
chunk.setBlockState(context.pos.set(x, y, z), dirt, false);
|
||||
return;
|
||||
}
|
||||
if (context.cell.tag == riverBank) {
|
||||
float value = noise1.getValue(x, z) * 5;
|
||||
if (y + value >= levels.waterY) {
|
||||
if (context.cell.steepness > 0.5) {
|
||||
chunk.setBlockState(context.pos.setPos(x, y, z), gravel, false);
|
||||
chunk.setBlockState(context.pos.set(x, y, z), gravel, false);
|
||||
} else if (context.cell.steepness < 0.3) {
|
||||
chunk.setBlockState(context.pos.setPos(x, y, z), sand, false);
|
||||
chunk.setBlockState(context.pos.set(x, y, z), sand, false);
|
||||
} else {
|
||||
chunk.setBlockState(context.pos.setPos(x, y, z), dirt, false);
|
||||
chunk.setBlockState(context.pos.set(x, y, z), dirt, false);
|
||||
}
|
||||
} else {
|
||||
chunk.setBlockState(context.pos.setPos(x, y, z), dirt, false);
|
||||
chunk.setBlockState(context.pos.set(x, y, z), dirt, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ import com.terraforged.core.world.heightmap.Levels;
|
||||
import com.terraforged.mod.material.MaterialHelper;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class LayerDecorator implements ColumnDecorator {
|
||||
|
||||
@ -45,8 +45,8 @@ public class LayerDecorator implements ColumnDecorator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
context.pos.setPos(x, y + 1, z);
|
||||
public void decorate(Chunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
context.pos.set(x, y + 1, z);
|
||||
|
||||
// if block is already a layer-type then simply set the layer property
|
||||
BlockState state = chunk.getBlockState(context.pos);
|
||||
@ -63,16 +63,16 @@ public class LayerDecorator implements ColumnDecorator {
|
||||
// block is non-solid (grass/flower etc)
|
||||
if (!state.getMaterial().blocksMovement()) {
|
||||
// block below is solid
|
||||
if (chunk.getBlockState(context.pos.setPos(x, y, z)).getMaterial().blocksMovement()) {
|
||||
if (chunk.getBlockState(context.pos.set(x, y, z)).getMaterial().blocksMovement()) {
|
||||
// block above is air
|
||||
if (MaterialHelper.isAir(chunk.getBlockState(context.pos.setPos(x, y + 2, z)).getBlock())) {
|
||||
if (MaterialHelper.isAir(chunk.getBlockState(context.pos.set(x, y + 2, z)).getBlock())) {
|
||||
// setLayer(chunk, pos.setPos(x, y + 1, z), context.cell, context.levels, 0.25F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setLayer(IChunk chunk, BlockPos pos, LayerMaterial material, Cell<?> cell, Levels levels, float min) {
|
||||
private void setLayer(Chunk chunk, BlockPos pos, LayerMaterial material, Cell<?> cell, Levels levels, float min) {
|
||||
float height = cell.value * levels.worldHeight;
|
||||
float depth = material.getDepth(height);
|
||||
if (depth > min) {
|
||||
|
@ -32,8 +32,8 @@ import com.terraforged.mod.decorator.base.ErosionDecorator;
|
||||
import me.dags.noise.source.Rand;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@ -56,8 +56,8 @@ public class SnowEroder extends ErosionDecorator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
int surface = chunk.getTopBlockY(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, x, z);
|
||||
public void decorate(Chunk chunk, DecoratorContext context, int x, int y, int z) {
|
||||
int surface = chunk.sampleHeightmap(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, x, z);
|
||||
if (y - surface > 0) {
|
||||
if (y - surface > 4) {
|
||||
return;
|
||||
@ -65,7 +65,7 @@ public class SnowEroder extends ErosionDecorator {
|
||||
y = surface;
|
||||
}
|
||||
|
||||
if (context.biome.getTemperature(context.pos.setPos(x, y, z)) <= 0.25) {
|
||||
if (context.biome.getTemperature(context.pos.set(x, y, z)) <= 0.25) {
|
||||
float var = -ColumnDecorator.getNoise(x, z, seed1, 16, 0);
|
||||
float hNoise = rand.getValue(x, z, seed2) * HEIGHT_MODIFIER;
|
||||
float sNoise = rand.getValue(x, z, seed3) * SLOPE_MODIFIER;
|
||||
@ -73,7 +73,7 @@ public class SnowEroder extends ErosionDecorator {
|
||||
float height = context.cell.value + var + hNoise + vModifier;
|
||||
float steepness = context.cell.steepness + var + sNoise + vModifier;
|
||||
if (snowErosion(x, z, steepness, height)) {
|
||||
Predicate<BlockState> predicate = Heightmap.Type.MOTION_BLOCKING.getHeightLimitPredicate();
|
||||
Predicate<BlockState> predicate = Heightmap.Type.MOTION_BLOCKING.getBlockPredicate();
|
||||
for (int dy = 2; dy > 0; dy--) {
|
||||
context.pos.setY(y + dy);
|
||||
BlockState state = chunk.getBlockState(context.pos);
|
||||
|
@ -81,7 +81,7 @@ public class DesertDunes implements Surface {
|
||||
float depth = material.getDepth(duneHeight);
|
||||
int levels = material.getLevel(depth);
|
||||
BlockState top = material.getState(levels);
|
||||
ctx.chunk.setBlockState(pos.setPos(x, duneTop, z), top, false);
|
||||
ctx.chunk.setBlockState(pos.set(x, duneTop, z), top, false);
|
||||
}
|
||||
|
||||
public static Surface create(TerraContext context, BiomeProvider provider) {
|
||||
|
@ -36,7 +36,7 @@ import me.dags.noise.Source;
|
||||
import me.dags.noise.util.NoiseUtil;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
|
||||
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;
|
||||
|
||||
public class FrozenOcean implements Surface {
|
||||
|
||||
|
@ -28,9 +28,9 @@ package com.terraforged.mod.feature.predicate;
|
||||
import com.terraforged.core.world.climate.Climate;
|
||||
import com.terraforged.feature.predicate.FeaturePredicate;
|
||||
import com.terraforged.mod.chunk.TerraContext;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class TreeLine implements FeaturePredicate {
|
||||
|
||||
@ -43,11 +43,11 @@ public class TreeLine implements FeaturePredicate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(IChunk chunk, Biome biome) {
|
||||
int x = chunk.getPos().getXStart() + 8;
|
||||
int z = chunk.getPos().getZStart() + 8;
|
||||
public boolean test(Chunk chunk, Biome biome) {
|
||||
int x = chunk.getPos().getStartX() + 8;
|
||||
int z = chunk.getPos().getStartZ() + 8;
|
||||
int treeline = getTreeline(x, z);
|
||||
int y = chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, 8, 8);
|
||||
int y = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE_WG, 8, 8);
|
||||
return y < treeline;
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,10 @@ package com.terraforged.mod.feature.tree;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.mojang.datafixers.types.DynamicOps;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -40,11 +40,11 @@ import java.util.Map;
|
||||
|
||||
public class SaplingConfig {
|
||||
|
||||
private static final TypeToken<Feature<NoFeatureConfig>> TOKEN = new TypeToken<Feature<NoFeatureConfig>>() {
|
||||
private static final TypeToken<Feature<DefaultFeatureConfig>> TOKEN = new TypeToken<Feature<DefaultFeatureConfig>>() {
|
||||
};
|
||||
|
||||
private final Map<ResourceLocation, Integer> normal;
|
||||
private final Map<ResourceLocation, Integer> giant;
|
||||
private final Map<Identifier, Integer> normal;
|
||||
private final Map<Identifier, Integer> giant;
|
||||
|
||||
public SaplingConfig() {
|
||||
normal = new HashMap<>();
|
||||
@ -56,29 +56,29 @@ public class SaplingConfig {
|
||||
this.giant = getSection("giant", config, ops);
|
||||
}
|
||||
|
||||
public SaplingConfig addNormal(ResourceLocation name, int weight) {
|
||||
public SaplingConfig addNormal(Identifier name, int weight) {
|
||||
normal.put(name, weight);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SaplingConfig addNormal(String name, int weight) {
|
||||
normal.put(new ResourceLocation(name), weight);
|
||||
normal.put(new Identifier(name), weight);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SaplingConfig addGiant(ResourceLocation name, int weight) {
|
||||
public SaplingConfig addGiant(Identifier name, int weight) {
|
||||
giant.put(name, weight);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SaplingConfig addGiant(String name, int weight) {
|
||||
giant.put(new ResourceLocation(name), weight);
|
||||
giant.put(new Identifier(name), weight);
|
||||
return this;
|
||||
}
|
||||
|
||||
private <T> Map<ResourceLocation, Integer> getSection(String key, T config, DynamicOps<T> ops) {
|
||||
private <T> Map<Identifier, Integer> getSection(String key, T config, DynamicOps<T> ops) {
|
||||
return ops.get(config, key).flatMap(ops::getMapValues).map(map -> {
|
||||
Map<ResourceLocation, Integer> backing = new HashMap<>();
|
||||
Map<Identifier, Integer> backing = new HashMap<>();
|
||||
|
||||
for (Map.Entry<T, T> entry : map.entrySet()) {
|
||||
String name = ops.getStringValue(entry.getKey()).orElse("");
|
||||
@ -87,7 +87,7 @@ public class SaplingConfig {
|
||||
continue;
|
||||
}
|
||||
|
||||
ResourceLocation loc = new ResourceLocation(name);
|
||||
Identifier loc = new Identifier(name);
|
||||
backing.put(loc, weight);
|
||||
}
|
||||
|
||||
@ -95,25 +95,25 @@ public class SaplingConfig {
|
||||
}).orElse(Collections.emptyMap());
|
||||
}
|
||||
|
||||
public List<Feature<NoFeatureConfig>> getNormal() {
|
||||
public List<Feature<DefaultFeatureConfig>> getNormal() {
|
||||
return build(normal);
|
||||
}
|
||||
|
||||
public List<Feature<NoFeatureConfig>> getGiant() {
|
||||
public List<Feature<DefaultFeatureConfig>> getGiant() {
|
||||
return build(giant);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Feature<NoFeatureConfig>> build(Map<ResourceLocation, Integer> map) {
|
||||
List<Feature<NoFeatureConfig>> list = new LinkedList<>();
|
||||
for (Map.Entry<ResourceLocation, Integer> entry : map.entrySet()) {
|
||||
Feature<?> feature = ForgeRegistries.FEATURES.getValue(entry.getKey());
|
||||
public static List<Feature<DefaultFeatureConfig>> build(Map<Identifier, Integer> map) {
|
||||
List<Feature<DefaultFeatureConfig>> list = new LinkedList<>();
|
||||
for (Map.Entry<Identifier, Integer> entry : map.entrySet()) {
|
||||
Feature<?> feature = Registry.FEATURE.get(entry.getKey());
|
||||
if (feature == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TOKEN.getRawType().isAssignableFrom(feature.getClass())) {
|
||||
Feature<NoFeatureConfig> noConfFeature = (Feature<NoFeatureConfig>) feature;
|
||||
Feature<DefaultFeatureConfig> noConfFeature = (Feature<DefaultFeatureConfig>) feature;
|
||||
list.add(noConfFeature);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
package com.terraforged.mod.feature.tree;
|
||||
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -34,22 +34,22 @@ import java.util.Random;
|
||||
|
||||
public class SaplingFeature {
|
||||
|
||||
private final List<Feature<NoFeatureConfig>> normal;
|
||||
private final List<Feature<NoFeatureConfig>> giant;
|
||||
private final List<Feature<DefaultFeatureConfig>> normal;
|
||||
private final List<Feature<DefaultFeatureConfig>> giant;
|
||||
|
||||
public SaplingFeature(SaplingConfig config) {
|
||||
this.normal = new ArrayList<>(config.getNormal());
|
||||
this.giant = new ArrayList<>(config.getGiant());
|
||||
}
|
||||
|
||||
public Feature<NoFeatureConfig> nextNormal(Random random) {
|
||||
public Feature<DefaultFeatureConfig> nextNormal(Random random) {
|
||||
if (normal.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return normal.get(random.nextInt(normal.size()));
|
||||
}
|
||||
|
||||
public Feature<NoFeatureConfig> nextGiant(Random random) {
|
||||
public Feature<DefaultFeatureConfig> nextGiant(Random random) {
|
||||
if (giant.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1,141 +1,140 @@
|
||||
/*
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 TerraForged
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.terraforged.mod.feature.tree;
|
||||
|
||||
import com.terraforged.mod.TerraWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.SaplingBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class SaplingListener {
|
||||
|
||||
private static final BlockPos[] NONE = {BlockPos.ZERO};
|
||||
|
||||
private static final Vec3i[][] DIRECTIONS = {
|
||||
{new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(1, 0, 0)},
|
||||
{new Vec3i(1, 0, 0), new Vec3i(1, 0, -1), new Vec3i(0, 0, -1)},
|
||||
{new Vec3i(0, 0, -1), new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0)},
|
||||
{new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), new Vec3i(0, 0, 1)},
|
||||
};
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onTreeGrow(SaplingGrowTreeEvent event) {
|
||||
if (!TerraWorld.isTerraWorld(event.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
IWorld world = event.getWorld();
|
||||
BlockPos pos = event.getPos();
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (block instanceof SaplingBlock) {
|
||||
// get the sapling feature for the given block type
|
||||
SaplingFeature tree = SaplingManager.getSapling(block.getRegistryName());
|
||||
|
||||
// tree is null if the sapling type hasn't been configured
|
||||
if (tree == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check for a 2x2 arrangement of sapling blocks around the position
|
||||
Vec3i[] directions = getNeighbourDirections(world, block, pos);
|
||||
|
||||
// length is 1 if a full 2x2 arrangement could not be found
|
||||
if (directions.length == 1) {
|
||||
placeNormal(tree, event, directions);
|
||||
} else {
|
||||
placeGiant(tree, event, block, directions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void placeNormal(SaplingFeature tree, SaplingGrowTreeEvent event, Vec3i[] directions) {
|
||||
SaplingPlacer.placeTree(tree.nextNormal(event.getRand()), event, directions);
|
||||
}
|
||||
|
||||
private static void placeGiant(SaplingFeature tree, SaplingGrowTreeEvent event, Block type, Vec3i[] directions) {
|
||||
Feature<NoFeatureConfig> feature = tree.nextGiant(event.getRand());
|
||||
|
||||
// if no giant tree exists for this sapling type try and place a normal one instead
|
||||
if (feature == null) {
|
||||
placeNormal(tree, event, directions);
|
||||
return;
|
||||
}
|
||||
|
||||
// do not continue if unable to place the tree
|
||||
if (!SaplingPlacer.placeTree(feature, event, directions)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// iterate through the contributing saplings and remove any that were not destroyed during tree creation
|
||||
BlockPos pos = event.getPos();
|
||||
for (Vec3i dir : directions) {
|
||||
BlockPos blockPos = pos.add(dir);
|
||||
BlockState state = event.getWorld().getBlockState(blockPos);
|
||||
if (state.getBlock() == type) {
|
||||
event.getWorld().removeBlock(blockPos, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Vec3i[] getNeighbourDirections(IWorld world, Block block, BlockPos pos) {
|
||||
for (Vec3i[] dirs : DIRECTIONS) {
|
||||
boolean match = true;
|
||||
for (Vec3i dir : dirs) {
|
||||
BlockState state = world.getBlockState(pos.add(dir));
|
||||
if (state.getBlock() != block) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
return dirs;
|
||||
}
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
|
||||
private static boolean isTerraWorld(IWorld world) {
|
||||
if (world instanceof World) {
|
||||
return isTerraWorld(((World) world).getWorldType());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isTerraWorld(WorldType type) {
|
||||
return type.getName().equals("terraforged");
|
||||
}
|
||||
}
|
||||
///*
|
||||
// *
|
||||
// * MIT License
|
||||
// *
|
||||
// * Copyright (c) 2020 TerraForged
|
||||
// *
|
||||
// * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// * of this software and associated documentation files (the "Software"), to deal
|
||||
// * in the Software without restriction, including without limitation the rights
|
||||
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// * copies of the Software, and to permit persons to whom the Software is
|
||||
// * furnished to do so, subject to the following conditions:
|
||||
// *
|
||||
// * The above copyright notice and this permission notice shall be included in all
|
||||
// * copies or substantial portions of the Software.
|
||||
// *
|
||||
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// * SOFTWARE.
|
||||
// */
|
||||
//
|
||||
//package com.terraforged.mod.feature.tree;
|
||||
//
|
||||
//import com.terraforged.mod.TerraWorld;
|
||||
//import net.minecraft.block.Block;
|
||||
//import net.minecraft.block.BlockState;
|
||||
//import net.minecraft.block.SaplingBlock;
|
||||
//import net.minecraft.util.math.BlockPos;
|
||||
//import net.minecraft.util.math.Vec3i;
|
||||
//import net.minecraft.world.IWorld;
|
||||
//import net.minecraft.world.World;
|
||||
//import net.minecraft.world.WorldType;
|
||||
//import net.minecraft.world.gen.feature.Feature;
|
||||
//import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
//import net.minecraftforge.event.world.SaplingGrowTreeEvent;
|
||||
//import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//import net.minecraftforge.fml.common.Mod;
|
||||
//
|
||||
//public class SaplingListener {
|
||||
//
|
||||
// private static final BlockPos[] NONE = {BlockPos.ORIGIN};
|
||||
//
|
||||
// private static final Vec3i[][] DIRECTIONS = {
|
||||
// {new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(1, 0, 0)},
|
||||
// {new Vec3i(1, 0, 0), new Vec3i(1, 0, -1), new Vec3i(0, 0, -1)},
|
||||
// {new Vec3i(0, 0, -1), new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0)},
|
||||
// {new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), new Vec3i(0, 0, 1)},
|
||||
// };
|
||||
//
|
||||
// //@SubscribeEvent todo tree grow event
|
||||
// public static void onTreeGrow(SaplingGrowTreeEvent event) {
|
||||
// if (!TerraWorld.isTerraWorld(event.getWorld())) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// IWorld world = event.getWorld();
|
||||
// BlockPos pos = event.getPos();
|
||||
// Block block = world.getBlockState(pos).getBlock();
|
||||
// if (block instanceof SaplingBlock) {
|
||||
// // get the sapling feature for the given block type
|
||||
// SaplingFeature tree = SaplingManager.getSapling(block.getRegistryName());
|
||||
//
|
||||
// // tree is null if the sapling type hasn't been configured
|
||||
// if (tree == null) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // check for a 2x2 arrangement of sapling blocks around the position
|
||||
// Vec3i[] directions = getNeighbourDirections(world, block, pos);
|
||||
//
|
||||
// // length is 1 if a full 2x2 arrangement could not be found
|
||||
// if (directions.length == 1) {
|
||||
// placeNormal(tree, event, directions);
|
||||
// } else {
|
||||
// placeGiant(tree, event, block, directions);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static void placeNormal(SaplingFeature tree, SaplingGrowTreeEvent event, Vec3i[] directions) {
|
||||
// SaplingPlacer.placeTree(tree.nextNormal(event.getRand()), event, directions);
|
||||
// }
|
||||
//
|
||||
// private static void placeGiant(SaplingFeature tree, SaplingGrowTreeEvent event, Block type, Vec3i[] directions) {
|
||||
// Feature<NoFeatureConfig> feature = tree.nextGiant(event.getRand());
|
||||
//
|
||||
// // if no giant tree exists for this sapling type try and place a normal one instead
|
||||
// if (feature == null) {
|
||||
// placeNormal(tree, event, directions);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // do not continue if unable to place the tree
|
||||
// if (!SaplingPlacer.placeTree(feature, event, directions)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // iterate through the contributing saplings and remove any that were not destroyed during tree creation
|
||||
// BlockPos pos = event.getPos();
|
||||
// for (Vec3i dir : directions) {
|
||||
// BlockPos blockPos = pos.add(dir);
|
||||
// BlockState state = event.getWorld().getBlockState(blockPos);
|
||||
// if (state.getBlock() == type) {
|
||||
// event.getWorld().removeBlock(blockPos, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static Vec3i[] getNeighbourDirections(IWorld world, Block block, BlockPos pos) {
|
||||
// for (Vec3i[] dirs : DIRECTIONS) {
|
||||
// boolean match = true;
|
||||
// for (Vec3i dir : dirs) {
|
||||
// BlockState state = world.getBlockState(pos.add(dir));
|
||||
// if (state.getBlock() != block) {
|
||||
// match = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (match) {
|
||||
// return dirs;
|
||||
// }
|
||||
// }
|
||||
// return NONE;
|
||||
// }
|
||||
//
|
||||
// private static boolean isTerraWorld(IWorld world) {
|
||||
// if (world instanceof World) {
|
||||
// return isTerraWorld(((World) world).getWorldType());
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private static boolean isTerraWorld(WorldType type) {
|
||||
// return type.getName().equals("terraforged");
|
||||
// }
|
||||
//}
|
||||
|
@ -29,28 +29,29 @@ import com.mojang.datafixers.types.DynamicOps;
|
||||
import com.terraforged.mod.Log;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SaplingManager {
|
||||
|
||||
private static final Map<ResourceLocation, SaplingFeature> saplings = new HashMap<>();
|
||||
private static final Map<Identifier, SaplingFeature> saplings = new HashMap<>();
|
||||
|
||||
public static SaplingFeature getSapling(ResourceLocation name) {
|
||||
public static SaplingFeature getSapling(Identifier name) {
|
||||
return saplings.get(name);
|
||||
}
|
||||
|
||||
public static void register(Block block, SaplingConfig config) {
|
||||
register(block.getRegistryName(), config);
|
||||
register(Registry.BLOCK.getId(block), config);
|
||||
}
|
||||
|
||||
public static <T> void register(ResourceLocation location, T config, DynamicOps<T> ops) {
|
||||
public static <T> void register(Identifier location, T config, DynamicOps<T> ops) {
|
||||
register(location, new SaplingConfig(config, ops));
|
||||
}
|
||||
|
||||
public static void register(ResourceLocation location, SaplingConfig config) {
|
||||
public static void register(Identifier location, SaplingConfig config) {
|
||||
saplings.put(location, new SaplingFeature(config));
|
||||
}
|
||||
|
||||
|
@ -1,149 +1,149 @@
|
||||
/*
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 TerraForged
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.terraforged.mod.feature.tree;
|
||||
|
||||
import com.terraforged.feature.template.decorator.DecoratedFeature;
|
||||
import com.terraforged.feature.template.decorator.DecoratorWorld;
|
||||
import com.terraforged.feature.template.feature.TemplateFeature;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraft.world.server.ServerChunkProvider;
|
||||
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
public class SaplingPlacer {
|
||||
|
||||
public static boolean placeTree(Feature<NoFeatureConfig> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
|
||||
if (feature == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
event.setResult(Event.Result.DENY);
|
||||
|
||||
if (feature instanceof DecoratedFeature) {
|
||||
return placeDecorated((DecoratedFeature<?,?>) feature, event, dirs);
|
||||
}
|
||||
|
||||
return placeNormal(feature, event, dirs);
|
||||
}
|
||||
|
||||
private static <W extends DecoratorWorld> boolean placeDecorated(DecoratedFeature<?, W> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
|
||||
if (!(event.getWorld().getChunkProvider() instanceof ServerChunkProvider)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos());
|
||||
W world = feature.wrap(buffer);
|
||||
|
||||
ChunkGenerator<?> generator = ((ServerChunkProvider) event.getWorld().getChunkProvider()).getChunkGenerator();
|
||||
feature.placeFeature(world, generator, event.getRand(), event.getPos(), NoFeatureConfig.NO_FEATURE_CONFIG);
|
||||
|
||||
// check that the tree can grow here
|
||||
if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockPos translation = buffer.getBaseMin().add(getMin(dirs));
|
||||
|
||||
// apply buffer to world with translation
|
||||
applyBuffer(buffer, event.getWorld(), translation);
|
||||
|
||||
// translate the decoration positions and apply in the world
|
||||
world.setDelegate(event.getWorld());
|
||||
world.translate(translation);
|
||||
feature.decorate(world, event.getRand());
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean placeNormal(Feature<NoFeatureConfig> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
|
||||
// apply the feature to a buffer
|
||||
TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos());
|
||||
buffer.placeFeature(feature, event.getPos(), event.getRand());
|
||||
|
||||
// check that the tree can grow here
|
||||
if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the min position in the 2x2 grid
|
||||
BlockPos translation = buffer.getBaseMin().add(getMin(dirs));
|
||||
|
||||
// copy the feature from the buffer to the world while translating each block
|
||||
applyBuffer(buffer, event.getWorld(), translation);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void applyBuffer(TreeGrowBuffer buffer, IWorld world, BlockPos translation) {
|
||||
try (BlockPos.PooledMutable pos = BlockPos.PooledMutable.retain()) {
|
||||
for (TemplateFeature.BlockInfo block : buffer.getChanges()) {
|
||||
int x = block.getPos().getX() + translation.getX();
|
||||
int y = block.getPos().getY();
|
||||
int z = block.getPos().getZ() + translation.getZ();
|
||||
|
||||
pos.setPos(x, y, z);
|
||||
|
||||
BlockState current = world.getBlockState(pos);
|
||||
if (current.isSolid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
world.setBlockState(pos, block.getState(), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean overheadIsSolid(IWorld world, BlockPos pos, int topY) {
|
||||
try (BlockPos.PooledMutable blockPos = BlockPos.PooledMutable.retain()) {
|
||||
for (int y = pos.getY(); y <= topY; y++) {
|
||||
blockPos.setPos(pos.getX(), y, pos.getZ());
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (state.isSolid()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static Vec3i getMin(Vec3i[] dirs) {
|
||||
Vec3i min = Vec3i.NULL_VECTOR;
|
||||
for (Vec3i dir : dirs) {
|
||||
if (dir.getX() < min.getX() && dir.getZ() <= min.getZ()) {
|
||||
min = dir;
|
||||
continue;
|
||||
}
|
||||
if (dir.getZ() < min.getZ() && dir.getX() <= min.getX()) {
|
||||
min = dir;
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
}
|
||||
///*
|
||||
// *
|
||||
// * MIT License
|
||||
// *
|
||||
// * Copyright (c) 2020 TerraForged
|
||||
// *
|
||||
// * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// * of this software and associated documentation files (the "Software"), to deal
|
||||
// * in the Software without restriction, including without limitation the rights
|
||||
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// * copies of the Software, and to permit persons to whom the Software is
|
||||
// * furnished to do so, subject to the following conditions:
|
||||
// *
|
||||
// * The above copyright notice and this permission notice shall be included in all
|
||||
// * copies or substantial portions of the Software.
|
||||
// *
|
||||
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// * SOFTWARE.
|
||||
// */
|
||||
//
|
||||
//package com.terraforged.mod.feature.tree;
|
||||
//
|
||||
//import com.terraforged.feature.template.decorator.DecoratedFeature;
|
||||
//import com.terraforged.feature.template.decorator.DecoratorWorld;
|
||||
//import com.terraforged.feature.template.feature.TemplateFeature;
|
||||
//import net.minecraft.block.BlockState;
|
||||
//import net.minecraft.util.math.BlockPos;
|
||||
//import net.minecraft.util.math.Vec3i;
|
||||
//import net.minecraft.world.IWorld;
|
||||
//import net.minecraft.world.gen.ChunkGenerator;
|
||||
//import net.minecraft.world.gen.feature.Feature;
|
||||
//import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
//import net.minecraft.world.server.ServerChunkProvider;
|
||||
//import net.minecraftforge.event.world.SaplingGrowTreeEvent;
|
||||
//import net.minecraftforge.eventbus.api.Event;
|
||||
//
|
||||
//public class SaplingPlacer {
|
||||
//
|
||||
// public static boolean placeTree(Feature<DefaultFeatureConfig> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
|
||||
// if (feature == null) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// event.setResult(Event.Result.DENY);
|
||||
//
|
||||
// if (feature instanceof DecoratedFeature) {
|
||||
// return placeDecorated((DecoratedFeature<?,?>) feature, event, dirs);
|
||||
// }
|
||||
//
|
||||
// return placeNormal(feature, event, dirs);
|
||||
// }
|
||||
//
|
||||
// private static <W extends DecoratorWorld> boolean placeDecorated(DecoratedFeature<?, W> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
|
||||
// if (!(event.getWorld().getChunkProvider() instanceof ServerChunkProvider)) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos());
|
||||
// W world = feature.wrap(buffer);
|
||||
//
|
||||
// ChunkGenerator<?> generator = ((ServerChunkProvider) event.getWorld().getChunkProvider()).getChunkGenerator();
|
||||
// feature.placeFeature(world, generator, event.getRand(), event.getPos(), DefaultFeatureConfig.NO_FEATURE_CONFIG);
|
||||
//
|
||||
// // check that the tree can grow here
|
||||
// if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// BlockPos translation = buffer.getBaseMin().add(getMin(dirs));
|
||||
//
|
||||
// // apply buffer to world with translation
|
||||
// applyBuffer(buffer, event.getWorld(), translation);
|
||||
//
|
||||
// // translate the decoration positions and apply in the world
|
||||
// world.setDelegate(event.getWorld());
|
||||
// world.translate(translation);
|
||||
// feature.decorate(world, event.getRand());
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// private static boolean placeNormal(Feature<DefaultFeatureConfig> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
|
||||
// // apply the feature to a buffer
|
||||
// TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos());
|
||||
// buffer.placeFeature(feature, event.getPos(), event.getRand());
|
||||
//
|
||||
// // check that the tree can grow here
|
||||
// if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // get the min position in the 2x2 grid
|
||||
// BlockPos translation = buffer.getBaseMin().add(getMin(dirs));
|
||||
//
|
||||
// // copy the feature from the buffer to the world while translating each block
|
||||
// applyBuffer(buffer, event.getWorld(), translation);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// private static void applyBuffer(TreeGrowBuffer buffer, IWorld world, BlockPos translation) {
|
||||
// try (BlockPos.PooledMutable pos = BlockPos.PooledMutable.retain()) {
|
||||
// for (TemplateFeature.BlockInfo block : buffer.getChanges()) {
|
||||
// int x = block.getPos().getX() + translation.getX();
|
||||
// int y = block.getPos().getY();
|
||||
// int z = block.getPos().getZ() + translation.getZ();
|
||||
//
|
||||
// pos.setPos(x, y, z);
|
||||
//
|
||||
// BlockState current = world.getBlockState(pos);
|
||||
// if (current.isSolid()) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// world.setBlockState(pos, block.getState(), 2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static boolean overheadIsSolid(IWorld world, BlockPos pos, int topY) {
|
||||
// try (BlockPos.PooledMutable blockPos = BlockPos.PooledMutable.retain()) {
|
||||
// for (int y = pos.getY(); y <= topY; y++) {
|
||||
// blockPos.setPos(pos.getX(), y, pos.getZ());
|
||||
// BlockState state = world.getBlockState(pos);
|
||||
// if (state.isSolid()) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static Vec3i getMin(Vec3i[] dirs) {
|
||||
// Vec3i min = Vec3i.NULL_VECTOR;
|
||||
// for (Vec3i dir : dirs) {
|
||||
// if (dir.getX() < min.getX() && dir.getZ() <= min.getZ()) {
|
||||
// min = dir;
|
||||
// continue;
|
||||
// }
|
||||
// if (dir.getZ() < min.getZ() && dir.getX() <= min.getX()) {
|
||||
// min = dir;
|
||||
// }
|
||||
// }
|
||||
// return min;
|
||||
// }
|
||||
//}
|
||||
|
@ -28,13 +28,13 @@ package com.terraforged.mod.feature.tree;
|
||||
import com.terraforged.feature.template.feature.TemplateFeature;
|
||||
import com.terraforged.feature.util.WorldDelegate;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerChunkManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.IFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraft.world.server.ServerChunkProvider;
|
||||
import net.minecraft.world.gen.feature.FeatureConfig;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -74,21 +74,21 @@ public class TreeGrowBuffer extends WorldDelegate {
|
||||
if (pos.getY() < this.pos.getY()) {
|
||||
return false;
|
||||
}
|
||||
if (state.isSolid()) {
|
||||
if (state.isOpaque()) {
|
||||
recordPos(pos);
|
||||
}
|
||||
changes.add(new TemplateFeature.BlockInfo(pos, state));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void placeFeature(Feature<NoFeatureConfig> feature, BlockPos pos, Random random) {
|
||||
placeFeature(feature, pos, random, NoFeatureConfig.NO_FEATURE_CONFIG);
|
||||
public void placeFeature(Feature<DefaultFeatureConfig> feature, BlockPos pos, Random random) {
|
||||
placeFeature(feature, pos, random, DefaultFeatureConfig.DEFAULT);
|
||||
}
|
||||
|
||||
public <T extends IFeatureConfig> void placeFeature(Feature<T> feature, BlockPos pos, Random random, T config) {
|
||||
if (getChunkProvider() instanceof ServerChunkProvider) {
|
||||
ServerChunkProvider chunkProvider = (ServerChunkProvider) getChunkProvider();
|
||||
feature.place(this, chunkProvider.getChunkGenerator(), random, pos, config);
|
||||
public <T extends FeatureConfig> void placeFeature(Feature<T> feature, BlockPos pos, Random random, T config) {
|
||||
if (getChunkManager() instanceof ServerChunkManager) {
|
||||
ServerChunkManager chunkProvider = (ServerChunkManager) getChunkManager();
|
||||
feature.generate(this, chunkProvider.getChunkGenerator(), random, pos, config);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,23 +27,23 @@ package com.terraforged.mod.gui;
|
||||
|
||||
import com.terraforged.mod.gui.element.CheckBox;
|
||||
import com.terraforged.mod.gui.element.Element;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
||||
public class OverlayScreen extends Screen implements OverlayRenderer {
|
||||
|
||||
public boolean showTooltips = false;
|
||||
|
||||
public OverlayScreen() {
|
||||
super(new TranslationTextComponent(""));
|
||||
super.minecraft = Minecraft.getInstance();
|
||||
super.font = minecraft.fontRenderer;
|
||||
super(new TranslatableText(""));
|
||||
super.minecraft = MinecraftClient.getInstance();
|
||||
super.font = minecraft.textRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Widget> T addButton(T buttonIn) {
|
||||
public <T extends AbstractButtonWidget> T addButton(T buttonIn) {
|
||||
return super.addButton(buttonIn);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public class OverlayScreen extends Screen implements OverlayRenderer {
|
||||
|
||||
@Override
|
||||
public void renderOverlays(Screen screen, int mouseX, int mouseY) {
|
||||
for (Widget button : buttons) {
|
||||
for (AbstractButtonWidget button : buttons) {
|
||||
if (button.isMouseOver(mouseX, mouseY)) {
|
||||
if (button instanceof Element) {
|
||||
screen.renderTooltip(((Element) button).getTooltip(), mouseX, mouseY);
|
||||
|
@ -26,33 +26,31 @@
|
||||
package com.terraforged.mod.gui;
|
||||
|
||||
import com.terraforged.mod.gui.element.Element;
|
||||
import com.terraforged.mod.gui.preview.Preview;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.list.AbstractOptionList;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ElementListWidget;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ScrollPane extends AbstractOptionList<ScrollPane.Entry> implements OverlayRenderer {
|
||||
public class ScrollPane extends ElementListWidget<ScrollPane.Entry> implements OverlayRenderer {
|
||||
|
||||
private boolean hovered = false;
|
||||
|
||||
public ScrollPane(int slotHeightIn) {
|
||||
super(Minecraft.getInstance(), 0, 0, 0, 0, slotHeightIn);
|
||||
super(MinecraftClient.getInstance(), 0, 0, 0, 0, slotHeightIn);
|
||||
}
|
||||
|
||||
public void addButton(Widget button) {
|
||||
public void addButton(AbstractButtonWidget button) {
|
||||
super.addEntry(new Entry(button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderOverlays(Screen screen, int x, int y) {
|
||||
for (Entry entry : this.children()) {
|
||||
if (entry.isMouseOver(x, y) && entry.option.isMouseOver(x, y)) {
|
||||
Widget button = entry.option;
|
||||
if (/*entry.isMouseOver(x, y) && todo lost*/ entry.option.isMouseOver(x, y)) {
|
||||
AbstractButtonWidget button = entry.option;
|
||||
if (button instanceof Element) {
|
||||
screen.renderTooltip(((Element) button).getTooltip(), x, y);
|
||||
return;
|
||||
@ -74,7 +72,7 @@ public class ScrollPane extends AbstractOptionList<ScrollPane.Entry> implements
|
||||
|
||||
@Override
|
||||
protected int getScrollbarPosition() {
|
||||
return getRight();
|
||||
return getMaxPosition(); // todo old getRight
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,16 +80,16 @@ public class ScrollPane extends AbstractOptionList<ScrollPane.Entry> implements
|
||||
return hovered && super.mouseScrolled(x, y, direction);
|
||||
}
|
||||
|
||||
public class Entry extends AbstractOptionList.Entry<Entry> {
|
||||
public class Entry extends ElementListWidget.Entry<Entry> {
|
||||
|
||||
public final Widget option;
|
||||
public final AbstractButtonWidget option;
|
||||
|
||||
public Entry(Widget option) {
|
||||
public Entry(AbstractButtonWidget option) {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends IGuiEventListener> children() {
|
||||
public List<? extends net.minecraft.client.gui.Element> children() {
|
||||
return Collections.singletonList(option);
|
||||
}
|
||||
|
||||
@ -113,10 +111,10 @@ public class ScrollPane extends AbstractOptionList<ScrollPane.Entry> implements
|
||||
option.y = top;
|
||||
option.visible = true;
|
||||
option.setWidth(optionWidth);
|
||||
option.setHeight(height);
|
||||
if (option instanceof Preview) {
|
||||
option.setHeight(option.getWidth());
|
||||
}
|
||||
// option.height = height; todo maybe use accessor
|
||||
//if (option instanceof Preview) {
|
||||
// option.setHeight(option.getWidth());
|
||||
//}
|
||||
option.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
|
@ -40,11 +40,11 @@ import com.terraforged.mod.gui.preview.PreviewPage;
|
||||
import com.terraforged.mod.settings.SettingsHelper;
|
||||
import com.terraforged.mod.settings.TerraSettings;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.CreateWorldScreen;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
@ -55,7 +55,8 @@ import java.io.Writer;
|
||||
|
||||
public class SettingsScreen extends OverlayScreen {
|
||||
|
||||
private static final Button.IPressable NO_ACTION = b -> {};
|
||||
private static final ButtonWidget.PressAction NO_ACTION = b -> {
|
||||
};
|
||||
|
||||
private final Page[] pages;
|
||||
private final CreateWorldScreen parent;
|
||||
@ -65,7 +66,7 @@ public class SettingsScreen extends OverlayScreen {
|
||||
private int pageIndex = 0;
|
||||
|
||||
public SettingsScreen(CreateWorldScreen parent) {
|
||||
NBTHelper.deserialize(parent.chunkProviderSettingsJson, settings);
|
||||
NBTHelper.deserialize(parent.generatorOptionsTag, settings);
|
||||
this.parent = parent;
|
||||
this.pages = new Page[]{
|
||||
new GeneratorPage(settings, preview),
|
||||
@ -105,21 +106,21 @@ public class SettingsScreen extends OverlayScreen {
|
||||
}
|
||||
|
||||
// -52
|
||||
addButton(new Button(buttonsCenter - buttonWidth - buttonPad, buttonsRow, buttonWidth, buttonHeight, "Cancel"
|
||||
addButton(new ButtonWidget(buttonsCenter - buttonWidth - buttonPad, buttonsRow, buttonWidth, buttonHeight, "Cancel"
|
||||
, b -> onClose()));
|
||||
|
||||
// +2
|
||||
addButton(new Button(buttonsCenter + buttonPad, buttonsRow, buttonWidth, buttonHeight, "Done", b -> {
|
||||
addButton(new ButtonWidget(buttonsCenter + buttonPad, buttonsRow, buttonWidth, buttonHeight, "Done", b -> {
|
||||
for (Page page : pages) {
|
||||
page.save();
|
||||
}
|
||||
parent.chunkProviderSettingsJson = NBTHelper.serializeCompact(settings);
|
||||
parent.generatorOptionsTag = NBTHelper.serializeCompact(settings);
|
||||
onClose();
|
||||
}));
|
||||
|
||||
|
||||
// -106
|
||||
addButton(new Button(buttonsCenter - (buttonWidth * 2 + (buttonPad * 3)), buttonsRow, buttonWidth,
|
||||
addButton(new ButtonWidget(buttonsCenter - (buttonWidth * 2 + (buttonPad * 3)), buttonsRow, buttonWidth,
|
||||
buttonHeight, "<<", NO_ACTION) {
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
@ -142,7 +143,7 @@ public class SettingsScreen extends OverlayScreen {
|
||||
});
|
||||
|
||||
// +56
|
||||
addButton(new Button(buttonsCenter + buttonWidth + (buttonPad * 3), buttonsRow, buttonWidth, buttonHeight,
|
||||
addButton(new ButtonWidget(buttonsCenter + buttonWidth + (buttonPad * 3), buttonsRow, buttonWidth, buttonHeight,
|
||||
">>", NO_ACTION) {
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
@ -164,7 +165,7 @@ public class SettingsScreen extends OverlayScreen {
|
||||
}
|
||||
});
|
||||
|
||||
addButton(new Button(width - buttonWidth - 15, buttonsRow, buttonWidth, buttonHeight, "Export", NO_ACTION) {
|
||||
addButton(new ButtonWidget(width - buttonWidth - 15, buttonsRow, buttonWidth, buttonHeight, "Export", NO_ACTION) {
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY) {
|
||||
super.onClick(mouseX, mouseY);
|
||||
@ -236,20 +237,20 @@ public class SettingsScreen extends OverlayScreen {
|
||||
page.close();
|
||||
}
|
||||
preview.close();
|
||||
Minecraft.getInstance().displayGuiScreen(parent);
|
||||
MinecraftClient.getInstance().openScreen(parent);
|
||||
}
|
||||
|
||||
private void export(Settings settings) {
|
||||
for (Page page : pages) {
|
||||
page.save();
|
||||
}
|
||||
CompoundNBT tag = NBTHelper.serializeCompact(settings);
|
||||
CompoundTag tag = NBTHelper.serializeCompact(settings);
|
||||
JsonElement json = NBTHelper.toJson(tag);
|
||||
File config = new File(Minecraft.getInstance().gameDir, "config");
|
||||
File config = new File(MinecraftClient.getInstance().runDirectory, "config");
|
||||
File file = new File(config, SettingsHelper.SETTINGS_FILE_NAME);
|
||||
try (Writer writer = new BufferedWriter(new FileWriter(file))) {
|
||||
new GsonBuilder().setPrettyPrinting().create().toJson(json, writer);
|
||||
Util.getOSType().openURI(file.getParentFile().toURI());
|
||||
Util.getOperatingSystem().open(file.getParentFile().toURI());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -25,10 +25,10 @@
|
||||
|
||||
package com.terraforged.mod.gui.element;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.fabricmc.fabric.api.util.NbtType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -47,11 +47,11 @@ public interface Element {
|
||||
return ID_COUNTER.getAndAdd(1);
|
||||
}
|
||||
|
||||
static List<String> readTooltip(CompoundNBT value) {
|
||||
static List<String> readTooltip(CompoundTag value) {
|
||||
if (value.contains("#comment")) {
|
||||
ListNBT comment = value.getList("#comment", Constants.NBT.TAG_STRING);
|
||||
ListTag comment = value.getList("#comment", NbtType.STRING);
|
||||
return comment.stream()
|
||||
.map(INBT::getString)
|
||||
.map(Tag::asString)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
|
@ -25,9 +25,9 @@
|
||||
|
||||
package com.terraforged.mod.gui.element;
|
||||
|
||||
import net.minecraftforge.fml.client.gui.widget.ExtendedButton;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
|
||||
public class TerraButton extends ExtendedButton implements Element {
|
||||
public class TerraButton extends ButtonWidget implements Element {
|
||||
|
||||
public TerraButton(String displayString) {
|
||||
super(0, 0, 200, 20, displayString, b -> {});
|
||||
|
@ -25,28 +25,27 @@
|
||||
|
||||
package com.terraforged.mod.gui.element;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
|
||||
public class TerraLabel extends TerraButton {
|
||||
|
||||
// private final GuiLabel label;
|
||||
// private final GuiLabel label;
|
||||
|
||||
public TerraLabel(String text) {
|
||||
super(text);
|
||||
visible = true;
|
||||
// label = new GuiLabel(
|
||||
// Collections.singletonList(text),
|
||||
// 0xFFFFFF,
|
||||
// Minecraft.getInstance().fontRenderer
|
||||
// );
|
||||
// label.visible = true;
|
||||
// label = new GuiLabel(
|
||||
// Collections.singletonList(text),
|
||||
// 0xFFFFFF,
|
||||
// Minecraft.getInstance().fontRenderer
|
||||
// );
|
||||
// label.visible = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
FontRenderer fontrenderer = minecraft.fontRenderer;
|
||||
fontrenderer.drawStringWithShadow(getMessage(), x, y + (height - 8) / 2, 0xFFFFFF);
|
||||
TextRenderer fontrenderer = MinecraftClient.getInstance().textRenderer;
|
||||
fontrenderer.drawWithShadow(getMessage(), x, y + (height - 8) / 2, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
|
@ -1,100 +1,102 @@
|
||||
/*
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 TerraForged
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.terraforged.mod.gui.element;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraftforge.fml.client.gui.widget.Slider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TerraSlider extends Slider implements Slider.ISlider, Element {
|
||||
|
||||
private final CompoundNBT value;
|
||||
private final List<String> tooltip;
|
||||
|
||||
private Runnable callback = () -> {};
|
||||
|
||||
public TerraSlider(String prefix, CompoundNBT value, boolean decimal) {
|
||||
super(0, 0, 100, 20, prefix, "", value.getFloat("#min"), value.getFloat("#max"), 0F, decimal, true, b -> {});
|
||||
this.value = value;
|
||||
this.parent = this;
|
||||
this.tooltip = Element.readTooltip(value);
|
||||
}
|
||||
|
||||
public TerraSlider callback(Runnable callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTooltip() {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeSliderValue(Slider slider) {
|
||||
onChange(slider, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRelease(double mouseX, double mouseY) {
|
||||
super.onRelease(mouseX, mouseY);
|
||||
callback.run();
|
||||
}
|
||||
|
||||
protected abstract void onChange(Slider slider, CompoundNBT value);
|
||||
|
||||
public static class Int extends TerraSlider {
|
||||
|
||||
public Int(String prefix, CompoundNBT value) {
|
||||
super(prefix, value, false);
|
||||
setValue(value.getInt("value"));
|
||||
updateSlider();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChange(Slider slider, CompoundNBT value) {
|
||||
value.putInt("value", slider.getValueInt());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Float extends TerraSlider {
|
||||
|
||||
public Float(String prefix, CompoundNBT value) {
|
||||
super(prefix, value, true);
|
||||
precision = 3;
|
||||
setValue(value.getFloat("value"));
|
||||
updateSlider();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChange(Slider slider, CompoundNBT value) {
|
||||
int i = (int) (slider.getValue() * 1000);
|
||||
float f = i / 1000F;
|
||||
value.putFloat("value", f);
|
||||
}
|
||||
}
|
||||
}
|
||||
///*
|
||||
// *
|
||||
// * MIT License
|
||||
// *
|
||||
// * Copyright (c) 2020 TerraForged
|
||||
// *
|
||||
// * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// * of this software and associated documentation files (the "Software"), to deal
|
||||
// * in the Software without restriction, including without limitation the rights
|
||||
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// * copies of the Software, and to permit persons to whom the Software is
|
||||
// * furnished to do so, subject to the following conditions:
|
||||
// *
|
||||
// * The above copyright notice and this permission notice shall be included in all
|
||||
// * copies or substantial portions of the Software.
|
||||
// *
|
||||
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// * SOFTWARE.
|
||||
// */
|
||||
//
|
||||
//package com.terraforged.mod.gui.element;
|
||||
//
|
||||
//import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
//import net.minecraft.nbt.CompoundTag;
|
||||
//import net.minecraftforge.fml.client.gui.widget.Slider;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//// todo need to add forge slider lol
|
||||
//public abstract class TerraSlider extends AbstractButtonWidget implements Slider.ISlider, Element {
|
||||
//
|
||||
// private final CompoundTag value;
|
||||
// private final List<String> tooltip;
|
||||
//
|
||||
// private Runnable callback = () -> {};
|
||||
//
|
||||
// public TerraSlider(String prefix, CompoundTag value, boolean decimal) {
|
||||
// super(0, 0, 100, 20, prefix, "", value.getFloat("#min"), value.getFloat("#max"), 0F, decimal, true, b -> {});
|
||||
// this.value = value;
|
||||
// this.parent = this;
|
||||
// this.tooltip = Element.readTooltip(value);
|
||||
// }
|
||||
//
|
||||
// public TerraSlider callback(Runnable callback) {
|
||||
// this.callback = callback;
|
||||
// return this;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<String> getTooltip() {
|
||||
// return tooltip;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onChangeSliderValue(Slider slider) {
|
||||
// onChange(slider, value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRelease(double mouseX, double mouseY) {
|
||||
// super.onRelease(mouseX, mouseY);
|
||||
// callback.run();
|
||||
// }
|
||||
//
|
||||
// protected abstract void onChange(Slider slider, CompoundTag value);
|
||||
//
|
||||
// public static class Int extends TerraSlider {
|
||||
//
|
||||
// public Int(String prefix, CompoundTag value) {
|
||||
// super(prefix, value, false);
|
||||
// setValue(value.getInt("value"));
|
||||
// updateSlider();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onChange(Slider slider, CompoundTag value) {
|
||||
// value.putInt("value", slider.getValueInt());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static class Float extends TerraSlider {
|
||||
//
|
||||
// public Float(String prefix, CompoundTag value) {
|
||||
// super(prefix, value, true);
|
||||
// precision = 3;
|
||||
// setValue(value.getFloat("value"));
|
||||
// updateSlider();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onChange(Slider slider, CompoundTag value) {
|
||||
// int i = (int) (slider.getValue() * 1000);
|
||||
// float f = i / 1000F;
|
||||
// value.putFloat("value", f);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -25,25 +25,26 @@
|
||||
|
||||
package com.terraforged.mod.gui.element;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.fabricmc.fabric.api.util.NbtType;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
|
||||
public class Toggle extends TerraButton {
|
||||
|
||||
private final String prefix;
|
||||
private final CompoundNBT value;
|
||||
private final ListNBT options;
|
||||
private final CompoundTag value;
|
||||
private final ListTag options;
|
||||
|
||||
private int index;
|
||||
private Runnable callback = () -> {};
|
||||
private Runnable callback = () -> {
|
||||
};
|
||||
|
||||
public Toggle(String prefix, CompoundNBT value) {
|
||||
public Toggle(String prefix, CompoundTag value) {
|
||||
super(value.getString("value"));
|
||||
this.value = value;
|
||||
this.prefix = prefix;
|
||||
this.options = value.getList("#options", Constants.NBT.TAG_STRING);
|
||||
this.options = value.getList("#options", NbtType.STRING);
|
||||
for (int i = 0; i < options.size(); i++) {
|
||||
String s = options.getString(i);
|
||||
if (s.equals(value.getString("value"))) {
|
||||
@ -63,7 +64,7 @@ public class Toggle extends TerraButton {
|
||||
public boolean mouseClicked(double mx, double my, int button) {
|
||||
if (super.isValidClickButton(button)) {
|
||||
int direction = button == 0 ? 1 : -1;
|
||||
this.playDownSound(Minecraft.getInstance().getSoundHandler());
|
||||
this.playDownSound(MinecraftClient.getInstance().getSoundManager());
|
||||
this.onClick(mx, my, direction);
|
||||
return true;
|
||||
}
|
||||
|
@ -28,12 +28,12 @@ package com.terraforged.mod.gui.page;
|
||||
import com.terraforged.mod.gui.OverlayScreen;
|
||||
import com.terraforged.mod.settings.TerraSettings;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class FeaturePage extends BasePage {
|
||||
|
||||
private final TerraSettings settings;
|
||||
private final CompoundNBT featureSettings;
|
||||
private final CompoundTag featureSettings;
|
||||
|
||||
public FeaturePage(TerraSettings settings) {
|
||||
this.settings = settings;
|
||||
|
@ -29,13 +29,13 @@ import com.terraforged.core.settings.Settings;
|
||||
import com.terraforged.mod.gui.OverlayScreen;
|
||||
import com.terraforged.mod.gui.preview.PreviewPage;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class FilterPage extends BasePage {
|
||||
|
||||
private final Settings settings;
|
||||
private final PreviewPage preview;
|
||||
private final CompoundNBT filterSettings;
|
||||
private final CompoundTag filterSettings;
|
||||
|
||||
public FilterPage(Settings settings, PreviewPage preview) {
|
||||
this.settings = settings;
|
||||
|
@ -29,13 +29,13 @@ import com.terraforged.core.settings.Settings;
|
||||
import com.terraforged.mod.gui.OverlayScreen;
|
||||
import com.terraforged.mod.gui.preview.PreviewPage;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class GeneratorPage extends BasePage {
|
||||
|
||||
private final Settings settings;
|
||||
private final PreviewPage preview;
|
||||
private final CompoundNBT generatorSettings;
|
||||
private final CompoundTag generatorSettings;
|
||||
|
||||
public GeneratorPage(Settings settings, PreviewPage preview) {
|
||||
this.settings = settings;
|
||||
|
@ -30,23 +30,23 @@ import com.terraforged.mod.gui.OverlayScreen;
|
||||
import com.terraforged.mod.gui.ScrollPane;
|
||||
import com.terraforged.mod.gui.element.TerraButton;
|
||||
import com.terraforged.mod.gui.element.TerraLabel;
|
||||
import com.terraforged.mod.gui.element.TerraSlider;
|
||||
import com.terraforged.mod.gui.element.Toggle;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
import net.fabricmc.fabric.api.util.NbtType;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class Page implements IGuiEventListener, OverlayRenderer {
|
||||
public abstract class Page implements Element, OverlayRenderer {
|
||||
|
||||
protected static final Runnable NO_CALLBACK = () -> {};
|
||||
protected static final Runnable NO_CALLBACK = () -> {
|
||||
};
|
||||
|
||||
private static final int SLIDER_HEIGHT = 20;
|
||||
private static final int SLIDER_PAD = 2;
|
||||
@ -126,50 +126,51 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer {
|
||||
init(parent);
|
||||
}
|
||||
|
||||
public void addElements(int x, int y, Column column, CompoundNBT settings, Consumer<Widget> consumer, Runnable callback) {
|
||||
public void addElements(int x, int y, Column column, CompoundTag settings, Consumer<AbstractButtonWidget> consumer, Runnable callback) {
|
||||
addElements(x, y, column, settings, false, consumer, callback);
|
||||
}
|
||||
|
||||
public void addElements(int x, int y, Column column, CompoundNBT settings, boolean deep, Consumer<Widget> consumer, Runnable callback) {
|
||||
public void addElements(int x, int y, Column column, CompoundTag settings, boolean deep, Consumer<AbstractButtonWidget> consumer,
|
||||
Runnable callback) {
|
||||
AtomicInteger top = new AtomicInteger(y);
|
||||
|
||||
NBTHelper.stream(settings).forEach(value -> {
|
||||
String name = value.getString("#display");
|
||||
Widget button = createButton(name, value, callback);
|
||||
AbstractButtonWidget button = createButton(name, value, callback);
|
||||
if (button != null) {
|
||||
button.setWidth(column.width);
|
||||
button.setHeight(SLIDER_HEIGHT);
|
||||
// button.setHeight(SLIDER_HEIGHT); todo mixin
|
||||
button.x = x;
|
||||
button.y = top.getAndAdd(SLIDER_HEIGHT + SLIDER_PAD);
|
||||
consumer.accept(button);
|
||||
} else if (deep) {
|
||||
INBT child = value.get("value");
|
||||
if (child == null || child.getId() != Constants.NBT.TAG_COMPOUND) {
|
||||
Tag child = value.get("value");
|
||||
if (child == null || child.getType() != NbtType.COMPOUND) {
|
||||
return;
|
||||
}
|
||||
TerraLabel label = new TerraLabel(name);
|
||||
label.x = x;
|
||||
label.y = top.getAndAdd(SLIDER_HEIGHT + SLIDER_PAD);
|
||||
consumer.accept(label);
|
||||
addElements(x, label.y, column, (CompoundNBT) child, consumer, callback);
|
||||
addElements(x, label.y, column, (CompoundTag) child, consumer, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Widget createButton(String name, CompoundNBT value, Runnable callback) {
|
||||
INBT tag = value.get("value");
|
||||
public AbstractButtonWidget createButton(String name, CompoundTag value, Runnable callback) {
|
||||
Tag tag = value.get("value");
|
||||
if (tag == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte type = tag.getId();
|
||||
if (type == Constants.NBT.TAG_INT) {
|
||||
return new TerraSlider.Int(name + ": ", value).callback(callback);
|
||||
} else if (type == Constants.NBT.TAG_FLOAT) {
|
||||
return new TerraSlider.Float(name + ": ", value).callback(callback);
|
||||
} else if (type == Constants.NBT.TAG_STRING && value.contains("#options")) {
|
||||
byte type = tag.getType();
|
||||
if (type == NbtType.INT) {
|
||||
return new TerraButton(name);// todo slider return new TerraSlider.Int(name + ": ", value).callback(callback);
|
||||
} else if (type == NbtType.FLOAT) {
|
||||
return new TerraButton(name);// todo slider return new TerraSlider.Float(name + ": ", value).callback(callback);
|
||||
} else if (type == NbtType.STRING && value.contains("#options")) {
|
||||
return new Toggle(name + ": ", value).callback(callback);
|
||||
} else if (type == Constants.NBT.TAG_STRING) {
|
||||
} else if (type == NbtType.STRING) {
|
||||
return new TerraButton(name);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -29,13 +29,13 @@ import com.terraforged.core.settings.Settings;
|
||||
import com.terraforged.mod.gui.OverlayScreen;
|
||||
import com.terraforged.mod.gui.preview.PreviewPage;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class RiverPage extends BasePage {
|
||||
|
||||
private final Settings settings;
|
||||
private final PreviewPage preview;
|
||||
private final CompoundNBT riverSettings;
|
||||
private final CompoundTag riverSettings;
|
||||
|
||||
public RiverPage(Settings settings, PreviewPage preview) {
|
||||
this.settings = settings;
|
||||
|
@ -28,12 +28,12 @@ package com.terraforged.mod.gui.page;
|
||||
import com.terraforged.mod.gui.OverlayScreen;
|
||||
import com.terraforged.mod.settings.TerraSettings;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class StructurePage extends BasePage {
|
||||
|
||||
private final TerraSettings settings;
|
||||
private final CompoundNBT structureSettings;
|
||||
private final CompoundTag structureSettings;
|
||||
|
||||
public StructurePage(TerraSettings settings) {
|
||||
this.settings = settings;
|
||||
|
@ -29,13 +29,13 @@ import com.terraforged.core.settings.Settings;
|
||||
import com.terraforged.mod.gui.OverlayScreen;
|
||||
import com.terraforged.mod.gui.preview.PreviewPage;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class TerrainPage extends BasePage {
|
||||
|
||||
private final Settings settings;
|
||||
private final PreviewPage preview;
|
||||
private final CompoundNBT terrainSettings;
|
||||
private final CompoundTag terrainSettings;
|
||||
|
||||
public TerrainPage(Settings settings, PreviewPage preview) {
|
||||
this.settings = settings;
|
||||
|
@ -38,20 +38,20 @@ import com.terraforged.core.world.terrain.Terrain;
|
||||
import com.terraforged.core.world.terrain.Terrains;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import me.dags.noise.util.NoiseUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.renderer.texture.NativeImage;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.texture.NativeImageBackedTexture;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class Preview extends Button {
|
||||
public class Preview extends ButtonWidget {
|
||||
|
||||
private static final int FACTOR = 4;
|
||||
private static final int BLOCK_SIZE = 256;//Size.chunkToBlock(1 << FACTOR);
|
||||
@ -61,7 +61,7 @@ public class Preview extends Button {
|
||||
private final int offsetZ;
|
||||
private final Random random = new Random(System.currentTimeMillis());
|
||||
private final PreviewSettings previewSettings = new PreviewSettings();
|
||||
private final DynamicTexture texture = new DynamicTexture(new NativeImage(BLOCK_SIZE, BLOCK_SIZE, true));
|
||||
private final NativeImageBackedTexture texture = new NativeImageBackedTexture(new NativeImage(BLOCK_SIZE, BLOCK_SIZE, true));
|
||||
|
||||
private int seed;
|
||||
private long lastUpdate = 0L;
|
||||
@ -73,7 +73,8 @@ public class Preview extends Button {
|
||||
private String[] values = {"", "", ""};
|
||||
|
||||
public Preview() {
|
||||
super(0, 0, 0, 0, "", b -> {});
|
||||
super(0, 0, 0, 0, "", b -> {
|
||||
});
|
||||
this.seed = random.nextInt();
|
||||
this.offsetX = random.nextInt(50000) - 25000;
|
||||
this.offsetZ = random.nextInt(50000) - 25000;
|
||||
@ -87,6 +88,7 @@ public class Preview extends Button {
|
||||
texture.close();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(int mx, int my, float partialTicks) {
|
||||
preRender();
|
||||
@ -94,17 +96,18 @@ public class Preview extends Button {
|
||||
texture.bindTexture();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableRescaleNormal();
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE,
|
||||
GlStateManager.DstFactor.ZERO);
|
||||
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
AbstractGui.blit(x, y, 0, 0, width, height, width, height);
|
||||
DrawableHelper.blit(x, y, 0, 0, width, height, width, height);
|
||||
RenderSystem.disableRescaleNormal();
|
||||
|
||||
updateLegend(mx, my);
|
||||
renderLegend(labels, values, x + 1, y + height + 2, 15, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public void update(Settings settings, CompoundNBT prevSettings) {
|
||||
public void update(Settings settings, CompoundTag prevSettings) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - lastUpdate < 50) {
|
||||
return;
|
||||
@ -133,7 +136,7 @@ public class Preview extends Button {
|
||||
}
|
||||
|
||||
private void render(Region region) {
|
||||
NativeImage image = texture.getTextureData();
|
||||
NativeImage image = texture.getImage();
|
||||
if (image == null) {
|
||||
return;
|
||||
}
|
||||
@ -146,17 +149,17 @@ public class Preview extends Button {
|
||||
int width = region.getBlockSize().size;
|
||||
region.iterate((cell, x, z) -> {
|
||||
if (x < stroke || z < stroke || x >= width - stroke || z >= width - stroke) {
|
||||
image.setPixelRGBA(x, z, Color.black.getRGB());
|
||||
image.setPixelRgba(x, z, Color.black.getRGB());
|
||||
} else {
|
||||
Color color = renderer.color(cell, context);
|
||||
image.setPixelRGBA(x, z, RenderMode.rgba(color));
|
||||
image.setPixelRgba(x, z, RenderMode.rgba(color));
|
||||
}
|
||||
});
|
||||
|
||||
texture.updateDynamicTexture();
|
||||
texture.upload();
|
||||
}
|
||||
|
||||
private Future<Region> generate(Settings settings, CompoundNBT prevSettings) {
|
||||
private Future<Region> generate(Settings settings, CompoundTag prevSettings) {
|
||||
NBTHelper.deserialize(prevSettings, previewSettings);
|
||||
settings.generator.seed = seed;
|
||||
this.settings = settings;
|
||||
@ -172,7 +175,7 @@ public class Preview extends Button {
|
||||
return renderer.generate(offsetX, offsetZ, 101 - previewSettings.zoom, false);
|
||||
}
|
||||
|
||||
private void updateLegend(int mx ,int my) {
|
||||
private void updateLegend(int mx, int my) {
|
||||
if (region != null) {
|
||||
int zoom = (101 - previewSettings.zoom);
|
||||
int width = Math.max(1, region.getBlockSize().size * zoom);
|
||||
@ -192,7 +195,7 @@ public class Preview extends Button {
|
||||
}
|
||||
|
||||
private float getLegendScale() {
|
||||
int index = Minecraft.getInstance().gameSettings.guiScale - 1;
|
||||
int index = MinecraftClient.getInstance().options.guiScale - 1;
|
||||
if (index < 0 || index >= LEGEND_SCALES.length) {
|
||||
// index=-1 == GuiScale(AUTO) which is the same as GuiScale(4)
|
||||
// values above 4 don't exist but who knows what mods might try set it to
|
||||
@ -210,7 +213,7 @@ public class Preview extends Button {
|
||||
RenderSystem.translatef(left, top, 0);
|
||||
RenderSystem.scalef(scale, scale, 1);
|
||||
|
||||
FontRenderer renderer = Minecraft.getInstance().fontRenderer;
|
||||
TextRenderer renderer = MinecraftClient.getInstance().textRenderer;
|
||||
int spacing = 0;
|
||||
for (String s : labels) {
|
||||
spacing = Math.max(spacing, renderer.getStringWidth(s));
|
||||
@ -221,7 +224,7 @@ public class Preview extends Button {
|
||||
String label = labels[i];
|
||||
String value = values[i];
|
||||
|
||||
while (left + spacing + Minecraft.getInstance().fontRenderer.getStringWidth(value) > maxX) {
|
||||
while (left + spacing + MinecraftClient.getInstance().textRenderer.getStringWidth(value) > maxX) {
|
||||
value = value.substring(0, value.length() - 1);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ import com.terraforged.mod.gui.OverlayScreen;
|
||||
import com.terraforged.mod.gui.element.TerraButton;
|
||||
import com.terraforged.mod.gui.page.BasePage;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -38,7 +38,7 @@ public class PreviewPage extends BasePage {
|
||||
|
||||
private final Preview preview = new Preview();
|
||||
private final Settings settings = new Settings();
|
||||
private final CompoundNBT previewerSettings = NBTHelper.serialize(new PreviewSettings());
|
||||
private final CompoundTag previewerSettings = NBTHelper.serialize(new PreviewSettings());
|
||||
|
||||
public PreviewPage() {
|
||||
|
||||
@ -65,7 +65,7 @@ public class PreviewPage extends BasePage {
|
||||
preview.x = 0;
|
||||
preview.y = 0;
|
||||
preview.setWidth(256);
|
||||
preview.setHeight(256);
|
||||
// preview.setHeight(256); todo cannot set height
|
||||
|
||||
addElements(right.left, right.top, right, previewerSettings, right.scrollPane::addButton, this::update);
|
||||
right.scrollPane.addButton(new TerraButton("New Seed") {
|
||||
|
@ -32,15 +32,14 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.ConcretePowderBlock;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.tag.BlockTags;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.OreFeatureConfig;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -73,14 +72,11 @@ public class MaterialHelper {
|
||||
}
|
||||
|
||||
public static boolean isStone(Block block) {
|
||||
return Tags.Blocks.STONE.contains(block)
|
||||
&& !isBlacklisted(block)
|
||||
&& !("" + block.getRegistryName()).contains("polished_");
|
||||
return block == Blocks.STONE || block == Blocks.ANDESITE || block == Blocks.GRANITE || block == Blocks.DIORITE;
|
||||
}
|
||||
|
||||
public static boolean isDirt(Block block) {
|
||||
return Tags.Blocks.DIRT.contains(block)
|
||||
&& !isBlacklisted(block);
|
||||
return block == Blocks.DIRT || block == Blocks.COARSE_DIRT || block == Blocks.FARMLAND || isGrass(block);
|
||||
}
|
||||
|
||||
public static boolean isClay(Block block) {
|
||||
@ -101,24 +97,19 @@ public class MaterialHelper {
|
||||
}
|
||||
|
||||
public static boolean isGravel(Block block) {
|
||||
return getName(block).contains("gravel");
|
||||
return String.valueOf(Registry.BLOCK.getId(block)).contains("gravel");
|
||||
}
|
||||
|
||||
public static boolean isOre(Block block) {
|
||||
return Tags.Blocks.ORES.contains(block)
|
||||
&& !isBlacklisted(block);
|
||||
return block == Blocks.COAL_ORE || block == Blocks.DIAMOND_ORE || block == Blocks.EMERALD_ORE || block == Blocks.GOLD_ORE || block == Blocks.IRON_ORE || block == Blocks.LAPIS_ORE || block == Blocks.NETHER_QUARTZ_ORE || block == Blocks.REDSTONE_ORE;
|
||||
}
|
||||
|
||||
public static boolean isBlacklisted(Block block) {
|
||||
return BLACKLIST.contains(block);
|
||||
}
|
||||
|
||||
public static String getName(IForgeRegistryEntry<?> entry) {
|
||||
return "" + entry.getRegistryName();
|
||||
}
|
||||
|
||||
public static String getNamespace(IForgeRegistryEntry<?> entry) {
|
||||
ResourceLocation name = entry.getRegistryName();
|
||||
public static <T> String getNamespace(Registry<T> registry, T entry) {
|
||||
Identifier name = registry.getId(entry);
|
||||
if (name == null) {
|
||||
return "unknown";
|
||||
}
|
||||
@ -128,14 +119,14 @@ public class MaterialHelper {
|
||||
public static float getHardness(BlockState state) {
|
||||
try (ObjectPool.Item<DummyBlockReader> reader = DummyBlockReader.pooled()) {
|
||||
reader.getValue().set(state);
|
||||
return state.getBlockHardness(reader.getValue(), BlockPos.ZERO);
|
||||
return state.getHardness(reader.getValue(), BlockPos.ORIGIN);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCube(BlockState state) {
|
||||
try (ObjectPool.Item<DummyBlockReader> reader = DummyBlockReader.pooled()) {
|
||||
reader.getValue().set(state);
|
||||
return state.isNormalCube(reader.getValue(), BlockPos.ZERO);
|
||||
return state.isSimpleFullBlock(reader.getValue(), BlockPos.ORIGIN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,8 @@ import com.terraforged.api.material.layer.LayerManager;
|
||||
import com.terraforged.api.material.state.States;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -51,7 +51,7 @@ public class Materials {
|
||||
|
||||
public Materials() {
|
||||
Predicate<Block> filter = getTagFilter();
|
||||
for (Block block : ForgeRegistries.BLOCKS) {
|
||||
for (Block block : Registry.BLOCK) {
|
||||
if (filter.test(block)) {
|
||||
continue;
|
||||
}
|
||||
@ -142,22 +142,22 @@ public class Materials {
|
||||
}
|
||||
|
||||
private static Set<Block> create(Tag<Block> tag) {
|
||||
return new HashSet<>(tag.getAllElements());
|
||||
return new HashSet<>(tag.values());
|
||||
}
|
||||
|
||||
private static Predicate<Block> getTagFilter() {
|
||||
Set<String> namespaces = new HashSet<>();
|
||||
collectNamespace(namespaces, MaterialTags.WG_ROCK.getAllElements());
|
||||
collectNamespace(namespaces, MaterialTags.WG_EARTH.getAllElements());
|
||||
collectNamespace(namespaces, MaterialTags.WG_EARTH.getAllElements());
|
||||
collectNamespace(namespaces, MaterialTags.WG_SEDIMENT.getAllElements());
|
||||
collectNamespace(namespaces, MaterialTags.WG_ORE.getAllElements());
|
||||
return b -> namespaces.contains(MaterialHelper.getNamespace(b));
|
||||
collectNamespace(namespaces, MaterialTags.WG_ROCK.values());
|
||||
collectNamespace(namespaces, MaterialTags.WG_EARTH.values());
|
||||
collectNamespace(namespaces, MaterialTags.WG_EARTH.values());
|
||||
collectNamespace(namespaces, MaterialTags.WG_SEDIMENT.values());
|
||||
collectNamespace(namespaces, MaterialTags.WG_ORE.values());
|
||||
return b -> namespaces.contains(MaterialHelper.getNamespace(Registry.BLOCK, b));
|
||||
}
|
||||
|
||||
private static void collectNamespace(Set<String> set, Collection<Block> blocks) {
|
||||
for (Block block : blocks) {
|
||||
set.add(MaterialHelper.getNamespace(block));
|
||||
set.add(MaterialHelper.getNamespace(Registry.BLOCK, block));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,10 @@ package com.terraforged.mod.settings;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.terraforged.mod.Log;
|
||||
import com.terraforged.mod.TerraWorld;
|
||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
import net.minecraft.world.level.LevelProperties;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -22,14 +21,15 @@ public class SettingsHelper {
|
||||
dedicated = true;
|
||||
}
|
||||
|
||||
public static int getVersion(WorldInfo info) {
|
||||
public static int getVersion(LevelProperties info) {
|
||||
if (info.getGeneratorOptions().isEmpty()) {
|
||||
// if options have not been set then the world has been created
|
||||
// during the current runtime .: is not legacy
|
||||
return TerraWorld.VERSION;
|
||||
// return TerraWorld.VERSION; todo
|
||||
return 0;
|
||||
}
|
||||
|
||||
CompoundNBT version = info.getGeneratorOptions().getCompound("version");
|
||||
CompoundTag version = info.getGeneratorOptions().getCompound("version");
|
||||
if (version.isEmpty()) {
|
||||
// version tag is absent in legacy worlds .: is legacy
|
||||
return 0;
|
||||
@ -44,13 +44,13 @@ public class SettingsHelper {
|
||||
Log.info("Loading generator settings from json");
|
||||
return new Gson().fromJson(reader, TerraSettings.class);
|
||||
} catch (Throwable ignored) {
|
||||
return getSettings(world.getWorldInfo());
|
||||
return getSettings(world.getLevelProperties());
|
||||
}
|
||||
}
|
||||
return getSettings(world.getWorldInfo());
|
||||
return getSettings(world.getLevelProperties());
|
||||
}
|
||||
|
||||
public static TerraSettings getSettings(WorldInfo info) {
|
||||
public static TerraSettings getSettings(LevelProperties info) {
|
||||
TerraSettings settings = new TerraSettings();
|
||||
if (!info.getGeneratorOptions().isEmpty()) {
|
||||
NBTHelper.deserialize(info.getGeneratorOptions(), settings);
|
||||
@ -58,10 +58,10 @@ public class SettingsHelper {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static void syncSettings(WorldInfo info, TerraSettings settings, int version) {
|
||||
public static void syncSettings(LevelProperties info, TerraSettings settings, int version) {
|
||||
settings.version = version;
|
||||
settings.generator.seed = info.getSeed();
|
||||
CompoundNBT options = NBTHelper.serialize(settings);
|
||||
CompoundTag options = NBTHelper.serialize(settings);
|
||||
info.setGeneratorOptions(options);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user