Now things compile on fabric ye

Signed-off-by: liach <liach@users.noreply.github.com>
This commit is contained in:
liach 2020-03-11 11:09:15 -05:00
parent 5193434468
commit b6c1b94e9d
42 changed files with 791 additions and 804 deletions

@ -1 +1 @@
Subproject commit 153286cb327b0329824e8dabf5a760bcb6b24b16 Subproject commit 6e6959528b41fe1704eb1d301dbee923de6e4742

View File

@ -28,7 +28,7 @@ package com.terraforged.api.chunk.surface.builder;
import com.terraforged.api.chunk.surface.Surface; import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext; import com.terraforged.api.chunk.surface.SurfaceContext;
import net.minecraft.world.biome.Biome; 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; import java.util.function.Function;
@ -48,9 +48,9 @@ public class Delegate implements Surface {
@Override @Override
public void buildSurface(int x, int z, int height, SurfaceContext context) { 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.random,
context.chunk, context.chunk,
context.biome, context.biome,

View File

@ -35,21 +35,11 @@ import com.terraforged.mod.feature.tree.SaplingManager;
import com.terraforged.mod.settings.SettingsHelper; import com.terraforged.mod.settings.SettingsHelper;
import com.terraforged.mod.util.Environment; import com.terraforged.mod.util.Environment;
import net.fabricmc.api.ModInitializer; 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.event.server.ServerStopCallback;
import net.fabricmc.fabric.api.registry.CommandRegistry; import net.fabricmc.fabric.api.registry.CommandRegistry;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.resource.ResourceType; import net.minecraft.resource.ResourceType;
import net.minecraft.server.MinecraftServer; 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> * Author <dags@dags.me>
@ -61,7 +51,7 @@ public class TerraForgedMod implements ModInitializer {
Log.info("Common setup"); Log.info("Common setup");
ServerStopCallback.EVENT.register(TerraForgedMod::onShutdown); ServerStopCallback.EVENT.register(TerraForgedMod::onShutdown);
MaterialTags.init(); MaterialTags.init();
TerraWorld.init(); // TerraWorld.init();
SaplingManager.init(); SaplingManager.init();
if (Environment.isDev()) { if (Environment.isDev()) {
DataGen.dumpData(); DataGen.dumpData();
@ -69,6 +59,7 @@ public class TerraForgedMod implements ModInitializer {
FeatureManager.registerTemplates(); FeatureManager.registerTemplates();
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new BiomeTagManager()); ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new BiomeTagManager());
CommandRegistry.INSTANCE.register(false, TerraCommand::register); CommandRegistry.INSTANCE.register(false, TerraCommand::register);
// TODO register and fix sapling listener
} }
public static void server() { public static void server() {

View File

@ -1,126 +1,126 @@
/* ///*
* // *
* MIT License // * MIT License
* // *
* Copyright (c) 2020 TerraForged // * Copyright (c) 2020 TerraForged
* // *
* Permission is hereby granted, free of charge, to any person obtaining a copy // * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal // * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights // * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is // * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: // * furnished to do so, subject to the following conditions:
* // *
* The above copyright notice and this permission notice shall be included in all // * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. // * copies or substantial portions of the Software.
* // *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // * 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 // * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. // * SOFTWARE.
*/ // */
//
package com.terraforged.mod; //package com.terraforged.mod;
//
import com.terraforged.core.world.terrain.Terrains; //import com.terraforged.core.world.terrain.Terrains;
import com.terraforged.mod.biome.provider.BiomeProvider; //import com.terraforged.mod.biome.provider.BiomeProvider;
import com.terraforged.mod.chunk.ChunkGeneratorFactory; //import com.terraforged.mod.chunk.ChunkGeneratorFactory;
import com.terraforged.mod.chunk.TerraChunkGenerator; //import com.terraforged.mod.chunk.TerraChunkGenerator;
import com.terraforged.mod.chunk.TerraContext; //import com.terraforged.mod.chunk.TerraContext;
import com.terraforged.mod.chunk.TerraGenSettings; //import com.terraforged.mod.chunk.TerraGenSettings;
import com.terraforged.mod.chunk.test.TestChunkGenerator; //import com.terraforged.mod.chunk.test.TestChunkGenerator;
import com.terraforged.mod.gui.SettingsScreen; //import com.terraforged.mod.gui.SettingsScreen;
import com.terraforged.mod.settings.SettingsHelper; //import com.terraforged.mod.settings.SettingsHelper;
import com.terraforged.mod.settings.TerraSettings; //import com.terraforged.mod.settings.TerraSettings;
import com.terraforged.mod.util.nbt.NBTHelper; //import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.client.Minecraft; //import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.CreateWorldScreen; //import net.minecraft.client.gui.screen.CreateWorldScreen;
import net.minecraft.world.IWorld; //import net.minecraft.world.IWorld;
import net.minecraft.world.World; //import net.minecraft.world.World;
import net.minecraft.world.WorldType; //import net.minecraft.world.WorldType;
import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings; //import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings;
import net.minecraft.world.dimension.DimensionType; //import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.ChunkGenerator; //import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.OverworldGenSettings; //import net.minecraft.world.gen.OverworldGenSettings;
import net.minecraft.world.level.LevelGeneratorType; //import net.minecraft.world.level.LevelGeneratorType;
import net.minecraftforge.api.distmarker.Dist; //import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; //import net.minecraftforge.api.distmarker.OnlyIn;
//
import java.util.HashSet; //import java.util.HashSet;
import java.util.Set; //import java.util.Set;
//
public class TerraWorld extends LevelGeneratorType { //public class TerraWorld extends LevelGeneratorType {
public static final int VERSION = 1; // public static final int VERSION = 1;
//
private static final Set<WorldType> types = new HashSet<>(); // private static final Set<WorldType> types = new HashSet<>();
public static final TerraWorld TERRA = new TerraWorld("terraforged", TerraChunkGenerator::new); // public static final TerraWorld TERRA = new TerraWorld("terraforged", TerraChunkGenerator::new);
public static final TerraWorld TEST = new TerraWorld("terratest", TestChunkGenerator::new); // public static final TerraWorld TEST = new TerraWorld("terratest", TestChunkGenerator::new);
//
private final ChunkGeneratorFactory<?> factory; // private final ChunkGeneratorFactory<?> factory;
//
public TerraWorld(String name, ChunkGeneratorFactory<?> factory) { // public TerraWorld(String name, ChunkGeneratorFactory<?> factory) {
super(name); // super(name);
this.factory = factory; // this.factory = factory;
setCustomOptions(true); // setCustomOptions(true);
TerraWorld.types.add(this); // TerraWorld.types.add(this);
} // }
//
@Override // @Override
public double getHorizon(World world) { // public double getHorizon(World world) {
return 0; // return 0;
} // }
//
@Override // @Override
public float getCloudHeight() { // public float getCloudHeight() {
return 260.0F; // return 260.0F;
} // }
//
@Override // @Override
public ChunkGenerator<?> createChunkGenerator(World world) { // public ChunkGenerator<?> createChunkGenerator(World world) {
if (world.getDimension().getType() != DimensionType.OVERWORLD) { // if (world.getDimension().getType() != DimensionType.OVERWORLD) {
return world.getDimension().createChunkGenerator(); // return world.getDimension().createChunkGenerator();
} // }
//
Log.debug("Creating {} generator", world.getDimension().getType()); // Log.debug("Creating {} generator", world.getDimension().getType());
//
int version = SettingsHelper.getVersion(world.getWorldInfo()); // int version = SettingsHelper.getVersion(world.getWorldInfo());
TerraSettings settings = SettingsHelper.getSettings(world); // TerraSettings settings = SettingsHelper.getSettings(world);
SettingsHelper.syncSettings(world.getWorldInfo(), settings, version); // SettingsHelper.syncSettings(world.getWorldInfo(), settings, version);
//
Terrains terrains = Terrains.create(settings); // Terrains terrains = Terrains.create(settings);
//
OverworldGenSettings genSettings = new TerraGenSettings(settings.structures); // OverworldGenSettings genSettings = new TerraGenSettings(settings.structures);
OverworldBiomeProviderSettings biomeSettings = new OverworldBiomeProviderSettings(world.getWorldInfo()); // OverworldBiomeProviderSettings biomeSettings = new OverworldBiomeProviderSettings(world.getWorldInfo());
biomeSettings.setGeneratorSettings(genSettings); // biomeSettings.setGeneratorSettings(genSettings);
world.getWorldInfo().setGeneratorOptions(NBTHelper.serializeCompact(settings)); // world.getWorldInfo().setGeneratorOptions(NBTHelper.serializeCompact(settings));
//
TerraContext context = new TerraContext(world, terrains, settings); // TerraContext context = new TerraContext(world, terrains, settings);
BiomeProvider biomeProvider = new BiomeProvider(context); // BiomeProvider biomeProvider = new BiomeProvider(context);
//
return getGeneratorFactory().create(context, biomeProvider, genSettings); // return getGeneratorFactory().create(context, biomeProvider, genSettings);
} // }
//
@Override // @Override
@OnlyIn(Dist.CLIENT) // @OnlyIn(Dist.CLIENT)
public void onCustomizeButton(Minecraft mc, CreateWorldScreen gui) { // public void onCustomizeButton(Minecraft mc, CreateWorldScreen gui) {
mc.displayGuiScreen(new SettingsScreen(gui)); // mc.displayGuiScreen(new SettingsScreen(gui));
} // }
//
public ChunkGeneratorFactory<?> getGeneratorFactory() { // public ChunkGeneratorFactory<?> getGeneratorFactory() {
return factory; // return factory;
} // }
//
public static void init() { // public static void init() {
Log.info("Registered world type(s)"); // Log.info("Registered world type(s)");
} // }
//
public static boolean isTerraWorld(IWorld world) { // public static boolean isTerraWorld(IWorld world) {
if (world instanceof World) { // if (world instanceof World) {
return types.contains(((World) world).getWorldType()); // return types.contains(((World) world).getWorldType());
} // }
return false; // return false;
} // }
} //}

View File

@ -7,6 +7,6 @@ public interface DefaultBiome {
Biome getBiome(float temperature); Biome getBiome(float temperature);
default Biome getDefaultBiome(float temperature) { default Biome getDefaultBiome(float temperature) {
return getBiome(temperature).delegate.get(); return getBiome(temperature);//.delegate.get(); todo no forge whack
} }
} }

View File

@ -28,14 +28,14 @@ package com.terraforged.mod.decorator;
import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.material.state.States; 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 class ChunkPopulator implements ColumnDecorator {
public static final ChunkPopulator INSTANCE = new ChunkPopulator(); public static final ChunkPopulator INSTANCE = new ChunkPopulator();
@Override @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) { if (context.cell.tag == context.terrains.volcanoPipe && context.cell.riverMask > 0.25F) {
int lavaStart = Math.max(context.levels.waterY + 10, y - 30); int lavaStart = Math.max(context.levels.waterY + 10, y - 30);
int lavaEnd = Math.max(5, context.levels.waterY - 10); int lavaEnd = Math.max(5, context.levels.waterY - 10);

View File

@ -28,7 +28,7 @@ package com.terraforged.mod.decorator.base;
import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.material.state.States; import com.terraforged.api.material.state.States;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.chunk.Chunk;
import java.util.Random; import java.util.Random;
@ -37,7 +37,7 @@ public class BedrockDecorator implements ColumnDecorator {
private final Random random = new Random(); private final Random random = new Random();
@Override @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()); fillDown(context, chunk, x, z, 1 + random.nextInt(4), -1, States.BEDROCK.get());
} }
} }

View File

@ -32,7 +32,7 @@ import com.terraforged.core.util.VariablePredicate;
import com.terraforged.core.world.terrain.Terrains; import com.terraforged.core.world.terrain.Terrains;
import com.terraforged.mod.chunk.TerraContext; import com.terraforged.mod.chunk.TerraContext;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.chunk.Chunk;
public class CoastDecorator implements ColumnDecorator { public class CoastDecorator implements ColumnDecorator {
@ -58,7 +58,7 @@ public class CoastDecorator implements ColumnDecorator {
} }
@Override @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) { if (context.cell.tag != terrains.beach) {
return; return;
} }

View File

@ -33,10 +33,10 @@ import com.terraforged.mod.chunk.TerraContext;
import com.terraforged.mod.material.Materials; import com.terraforged.mod.material.Materials;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material; import net.minecraft.block.Material;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.Heightmap;
import net.minecraft.world.gen.Heightmap; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.surfacebuilders.ISurfaceBuilderConfig; import net.minecraft.world.gen.surfacebuilder.SurfaceConfig;
public class ErosionDecorator implements ColumnDecorator { public class ErosionDecorator implements ColumnDecorator {
@ -74,7 +74,7 @@ public class ErosionDecorator implements ColumnDecorator {
} }
@Override @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) { if (context.cell.value < minY || context.cell.tag == terrain.river || context.cell.tag == terrain.riverBanks) {
return; return;
} }
@ -83,14 +83,14 @@ public class ErosionDecorator implements ColumnDecorator {
return; 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) { if (topY - 1 > y) {
y = topY; y = topY;
} }
ISurfaceBuilderConfig config = context.biome.getSurfaceBuilderConfig(); SurfaceConfig config = context.biome.getSurfaceConfig();
BlockState top = config.getTop(); BlockState top = config.getTopMaterial();
BlockState middle = config.getUnder(); BlockState middle = config.getUnderMaterial();
if (materials.isErodible(top.getBlock())) { if (materials.isErodible(top.getBlock())) {
BlockState material = getMaterial(x, z, context, top, middle); 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; int depth = 32;
BlockState material = Blocks.GRAVEL.getDefaultState(); BlockState material = Blocks.GRAVEL.getDefaultState();
// find the uppermost layer of rock & record it's depth // 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; float steepness = context.cell.steepness + context.climate.getRand().getValue(x, z, seed2) * SLOPE_MODIFIER;
if (steepness < SCREE_STEEPNESS) { if (steepness < SCREE_STEEPNESS) {
return; return;
@ -164,7 +164,7 @@ public class ErosionDecorator implements ColumnDecorator {
} }
private static BlockState rock(BlockState state) { private static BlockState rock(BlockState state) {
if (state.getMaterial() == Material.ROCK) { if (state.getMaterial() == Material.STONE) {
return state; return state;
} }
return States.STONE.get(); return States.STONE.get();
@ -174,7 +174,7 @@ public class ErosionDecorator implements ColumnDecorator {
if (state.getMaterial() == Material.ORGANIC) { if (state.getMaterial() == Material.ORGANIC) {
return States.DIRT.get(); return States.DIRT.get();
} }
if (state.getMaterial() == Material.ROCK) { if (state.getMaterial() == Material.STONE) {
return States.GRAVEL.get(); return States.GRAVEL.get();
} }
if (state.getMaterial() == Material.EARTH) { if (state.getMaterial() == Material.EARTH) {

View File

@ -29,7 +29,7 @@ import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer; import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer;
import com.terraforged.mod.material.geology.GeoManager; import com.terraforged.mod.material.geology.GeoManager;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.chunk.Chunk;
public class GeologyDecorator implements ColumnDecorator { public class GeologyDecorator implements ColumnDecorator {
@ -40,7 +40,7 @@ public class GeologyDecorator implements ColumnDecorator {
} }
@Override @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) { public void decorate(ChunkSurfaceBuffer buffer, DecoratorContext context, int x, int y, int z) {
int top = buffer.getSurfaceBottom(); int top = buffer.getSurfaceBottom();
geology.getGeology(context.biome).getStrata(x, z).downwards(x, top, z, (py, state) -> { 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); buffer.getDelegate().setBlockState(context.pos, state, false);
return true; return true;
}); });

View File

@ -35,7 +35,7 @@ import com.terraforged.mod.chunk.TerraContext;
import me.dags.noise.Module; import me.dags.noise.Module;
import me.dags.noise.Source; import me.dags.noise.Source;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.chunk.Chunk;
public class RiverDecorator implements ColumnDecorator { public class RiverDecorator implements ColumnDecorator {
@ -61,23 +61,23 @@ public class RiverDecorator implements ColumnDecorator {
} }
@Override @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) { 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; return;
} }
if (context.cell.tag == riverBank) { if (context.cell.tag == riverBank) {
float value = noise1.getValue(x, z) * 5; float value = noise1.getValue(x, z) * 5;
if (y + value >= levels.waterY) { if (y + value >= levels.waterY) {
if (context.cell.steepness > 0.5) { 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) { } 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 { } else {
chunk.setBlockState(context.pos.setPos(x, y, z), dirt, false); chunk.setBlockState(context.pos.set(x, y, z), dirt, false);
} }
} else { } else {
chunk.setBlockState(context.pos.setPos(x, y, z), dirt, false); chunk.setBlockState(context.pos.set(x, y, z), dirt, false);
} }
} }
} }

View File

@ -34,7 +34,7 @@ import com.terraforged.core.world.heightmap.Levels;
import com.terraforged.mod.material.MaterialHelper; import com.terraforged.mod.material.MaterialHelper;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.chunk.Chunk;
public class LayerDecorator implements ColumnDecorator { public class LayerDecorator implements ColumnDecorator {
@ -45,8 +45,8 @@ public class LayerDecorator implements ColumnDecorator {
} }
@Override @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) {
context.pos.setPos(x, y + 1, z); context.pos.set(x, y + 1, z);
// if block is already a layer-type then simply set the layer property // if block is already a layer-type then simply set the layer property
BlockState state = chunk.getBlockState(context.pos); BlockState state = chunk.getBlockState(context.pos);
@ -63,16 +63,16 @@ public class LayerDecorator implements ColumnDecorator {
// block is non-solid (grass/flower etc) // block is non-solid (grass/flower etc)
if (!state.getMaterial().blocksMovement()) { if (!state.getMaterial().blocksMovement()) {
// block below is solid // 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 // 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); // 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 height = cell.value * levels.worldHeight;
float depth = material.getDepth(height); float depth = material.getDepth(height);
if (depth > min) { if (depth > min) {

View File

@ -32,8 +32,8 @@ import com.terraforged.mod.decorator.base.ErosionDecorator;
import me.dags.noise.source.Rand; import me.dags.noise.source.Rand;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.Heightmap;
import net.minecraft.world.gen.Heightmap; import net.minecraft.world.chunk.Chunk;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -56,8 +56,8 @@ public class SnowEroder extends ErosionDecorator {
} }
@Override @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) {
int surface = chunk.getTopBlockY(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, x, z); int surface = chunk.sampleHeightmap(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, x, z);
if (y - surface > 0) { if (y - surface > 0) {
if (y - surface > 4) { if (y - surface > 4) {
return; return;
@ -65,7 +65,7 @@ public class SnowEroder extends ErosionDecorator {
y = surface; 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 var = -ColumnDecorator.getNoise(x, z, seed1, 16, 0);
float hNoise = rand.getValue(x, z, seed2) * HEIGHT_MODIFIER; float hNoise = rand.getValue(x, z, seed2) * HEIGHT_MODIFIER;
float sNoise = rand.getValue(x, z, seed3) * SLOPE_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 height = context.cell.value + var + hNoise + vModifier;
float steepness = context.cell.steepness + var + sNoise + vModifier; float steepness = context.cell.steepness + var + sNoise + vModifier;
if (snowErosion(x, z, steepness, height)) { 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--) { for (int dy = 2; dy > 0; dy--) {
context.pos.setY(y + dy); context.pos.setY(y + dy);
BlockState state = chunk.getBlockState(context.pos); BlockState state = chunk.getBlockState(context.pos);

View File

@ -81,7 +81,7 @@ public class DesertDunes implements Surface {
float depth = material.getDepth(duneHeight); float depth = material.getDepth(duneHeight);
int levels = material.getLevel(depth); int levels = material.getLevel(depth);
BlockState top = material.getState(levels); 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) { public static Surface create(TerraContext context, BiomeProvider provider) {

View File

@ -36,7 +36,7 @@ import me.dags.noise.Source;
import me.dags.noise.util.NoiseUtil; import me.dags.noise.util.NoiseUtil;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; 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 { public class FrozenOcean implements Surface {

View File

@ -28,9 +28,9 @@ package com.terraforged.mod.feature.predicate;
import com.terraforged.core.world.climate.Climate; import com.terraforged.core.world.climate.Climate;
import com.terraforged.feature.predicate.FeaturePredicate; import com.terraforged.feature.predicate.FeaturePredicate;
import com.terraforged.mod.chunk.TerraContext; import com.terraforged.mod.chunk.TerraContext;
import net.minecraft.world.Heightmap;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.Heightmap;
public class TreeLine implements FeaturePredicate { public class TreeLine implements FeaturePredicate {
@ -43,11 +43,11 @@ public class TreeLine implements FeaturePredicate {
} }
@Override @Override
public boolean test(IChunk chunk, Biome biome) { public boolean test(Chunk chunk, Biome biome) {
int x = chunk.getPos().getXStart() + 8; int x = chunk.getPos().getStartX() + 8;
int z = chunk.getPos().getZStart() + 8; int z = chunk.getPos().getStartZ() + 8;
int treeline = getTreeline(x, z); 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; return y < treeline;
} }

View File

@ -27,10 +27,10 @@ package com.terraforged.mod.feature.tree;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.mojang.datafixers.types.DynamicOps; 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.Feature;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -40,11 +40,11 @@ import java.util.Map;
public class SaplingConfig { 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<Identifier, Integer> normal;
private final Map<ResourceLocation, Integer> giant; private final Map<Identifier, Integer> giant;
public SaplingConfig() { public SaplingConfig() {
normal = new HashMap<>(); normal = new HashMap<>();
@ -56,29 +56,29 @@ public class SaplingConfig {
this.giant = getSection("giant", config, ops); this.giant = getSection("giant", config, ops);
} }
public SaplingConfig addNormal(ResourceLocation name, int weight) { public SaplingConfig addNormal(Identifier name, int weight) {
normal.put(name, weight); normal.put(name, weight);
return this; return this;
} }
public SaplingConfig addNormal(String name, int weight) { public SaplingConfig addNormal(String name, int weight) {
normal.put(new ResourceLocation(name), weight); normal.put(new Identifier(name), weight);
return this; return this;
} }
public SaplingConfig addGiant(ResourceLocation name, int weight) { public SaplingConfig addGiant(Identifier name, int weight) {
giant.put(name, weight); giant.put(name, weight);
return this; return this;
} }
public SaplingConfig addGiant(String name, int weight) { public SaplingConfig addGiant(String name, int weight) {
giant.put(new ResourceLocation(name), weight); giant.put(new Identifier(name), weight);
return this; 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 -> { 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()) { for (Map.Entry<T, T> entry : map.entrySet()) {
String name = ops.getStringValue(entry.getKey()).orElse(""); String name = ops.getStringValue(entry.getKey()).orElse("");
@ -87,7 +87,7 @@ public class SaplingConfig {
continue; continue;
} }
ResourceLocation loc = new ResourceLocation(name); Identifier loc = new Identifier(name);
backing.put(loc, weight); backing.put(loc, weight);
} }
@ -95,25 +95,25 @@ public class SaplingConfig {
}).orElse(Collections.emptyMap()); }).orElse(Collections.emptyMap());
} }
public List<Feature<NoFeatureConfig>> getNormal() { public List<Feature<DefaultFeatureConfig>> getNormal() {
return build(normal); return build(normal);
} }
public List<Feature<NoFeatureConfig>> getGiant() { public List<Feature<DefaultFeatureConfig>> getGiant() {
return build(giant); return build(giant);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<Feature<NoFeatureConfig>> build(Map<ResourceLocation, Integer> map) { public static List<Feature<DefaultFeatureConfig>> build(Map<Identifier, Integer> map) {
List<Feature<NoFeatureConfig>> list = new LinkedList<>(); List<Feature<DefaultFeatureConfig>> list = new LinkedList<>();
for (Map.Entry<ResourceLocation, Integer> entry : map.entrySet()) { for (Map.Entry<Identifier, Integer> entry : map.entrySet()) {
Feature<?> feature = ForgeRegistries.FEATURES.getValue(entry.getKey()); Feature<?> feature = Registry.FEATURE.get(entry.getKey());
if (feature == null) { if (feature == null) {
continue; continue;
} }
if (TOKEN.getRawType().isAssignableFrom(feature.getClass())) { if (TOKEN.getRawType().isAssignableFrom(feature.getClass())) {
Feature<NoFeatureConfig> noConfFeature = (Feature<NoFeatureConfig>) feature; Feature<DefaultFeatureConfig> noConfFeature = (Feature<DefaultFeatureConfig>) feature;
list.add(noConfFeature); list.add(noConfFeature);
} }
} }

View File

@ -26,7 +26,7 @@
package com.terraforged.mod.feature.tree; package com.terraforged.mod.feature.tree;
import net.minecraft.world.gen.feature.Feature; 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.ArrayList;
import java.util.List; import java.util.List;
@ -34,22 +34,22 @@ import java.util.Random;
public class SaplingFeature { public class SaplingFeature {
private final List<Feature<NoFeatureConfig>> normal; private final List<Feature<DefaultFeatureConfig>> normal;
private final List<Feature<NoFeatureConfig>> giant; private final List<Feature<DefaultFeatureConfig>> giant;
public SaplingFeature(SaplingConfig config) { public SaplingFeature(SaplingConfig config) {
this.normal = new ArrayList<>(config.getNormal()); this.normal = new ArrayList<>(config.getNormal());
this.giant = new ArrayList<>(config.getGiant()); this.giant = new ArrayList<>(config.getGiant());
} }
public Feature<NoFeatureConfig> nextNormal(Random random) { public Feature<DefaultFeatureConfig> nextNormal(Random random) {
if (normal.isEmpty()) { if (normal.isEmpty()) {
return null; return null;
} }
return normal.get(random.nextInt(normal.size())); return normal.get(random.nextInt(normal.size()));
} }
public Feature<NoFeatureConfig> nextGiant(Random random) { public Feature<DefaultFeatureConfig> nextGiant(Random random) {
if (giant.isEmpty()) { if (giant.isEmpty()) {
return null; return null;
} }

View File

@ -1,141 +1,140 @@
/* ///*
* // *
* MIT License // * MIT License
* // *
* Copyright (c) 2020 TerraForged // * Copyright (c) 2020 TerraForged
* // *
* Permission is hereby granted, free of charge, to any person obtaining a copy // * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal // * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights // * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is // * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: // * furnished to do so, subject to the following conditions:
* // *
* The above copyright notice and this permission notice shall be included in all // * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. // * copies or substantial portions of the Software.
* // *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // * 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 // * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. // * SOFTWARE.
*/ // */
//
package com.terraforged.mod.feature.tree; //package com.terraforged.mod.feature.tree;
//
import com.terraforged.mod.TerraWorld; //import com.terraforged.mod.TerraWorld;
import net.minecraft.block.Block; //import net.minecraft.block.Block;
import net.minecraft.block.BlockState; //import net.minecraft.block.BlockState;
import net.minecraft.block.SaplingBlock; //import net.minecraft.block.SaplingBlock;
import net.minecraft.util.math.BlockPos; //import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i; //import net.minecraft.util.math.Vec3i;
import net.minecraft.world.IWorld; //import net.minecraft.world.IWorld;
import net.minecraft.world.World; //import net.minecraft.world.World;
import net.minecraft.world.WorldType; //import net.minecraft.world.WorldType;
import net.minecraft.world.gen.feature.Feature; //import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.NoFeatureConfig; //import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraftforge.event.world.SaplingGrowTreeEvent; //import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; //import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; //import net.minecraftforge.fml.common.Mod;
//
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) //public class SaplingListener {
public class SaplingListener { //
// private static final BlockPos[] NONE = {BlockPos.ORIGIN};
private static final BlockPos[] NONE = {BlockPos.ZERO}; //
// private static final Vec3i[][] DIRECTIONS = {
private static final Vec3i[][] DIRECTIONS = { // {new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(1, 0, 0)},
{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(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(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(-1, 0, 0), new Vec3i(-1, 0, 1), new Vec3i(0, 0, 1)}, // };
}; //
// //@SubscribeEvent todo tree grow event
@SubscribeEvent // public static void onTreeGrow(SaplingGrowTreeEvent event) {
public static void onTreeGrow(SaplingGrowTreeEvent event) { // if (!TerraWorld.isTerraWorld(event.getWorld())) {
if (!TerraWorld.isTerraWorld(event.getWorld())) { // return;
return; // }
} //
// IWorld world = event.getWorld();
IWorld world = event.getWorld(); // BlockPos pos = event.getPos();
BlockPos pos = event.getPos(); // Block block = world.getBlockState(pos).getBlock();
Block block = world.getBlockState(pos).getBlock(); // if (block instanceof SaplingBlock) {
if (block instanceof SaplingBlock) { // // get the sapling feature for the given block type
// get the sapling feature for the given block type // SaplingFeature tree = SaplingManager.getSapling(block.getRegistryName());
SaplingFeature tree = SaplingManager.getSapling(block.getRegistryName()); //
// // tree is null if the sapling type hasn't been configured
// tree is null if the sapling type hasn't been configured // if (tree == null) {
if (tree == null) { // return;
return; // }
} //
// // check for a 2x2 arrangement of sapling blocks around the position
// check for a 2x2 arrangement of sapling blocks around the position // Vec3i[] directions = getNeighbourDirections(world, block, pos);
Vec3i[] directions = getNeighbourDirections(world, block, pos); //
// // length is 1 if a full 2x2 arrangement could not be found
// length is 1 if a full 2x2 arrangement could not be found // if (directions.length == 1) {
if (directions.length == 1) { // placeNormal(tree, event, directions);
placeNormal(tree, event, directions); // } else {
} else { // placeGiant(tree, event, block, directions);
placeGiant(tree, event, block, directions); // }
} // }
} // }
} //
// private static void placeNormal(SaplingFeature tree, SaplingGrowTreeEvent event, Vec3i[] directions) {
private static void placeNormal(SaplingFeature tree, SaplingGrowTreeEvent event, Vec3i[] directions) { // SaplingPlacer.placeTree(tree.nextNormal(event.getRand()), event, directions);
SaplingPlacer.placeTree(tree.nextNormal(event.getRand()), event, directions); // }
} //
// private static void placeGiant(SaplingFeature tree, SaplingGrowTreeEvent event, Block type, Vec3i[] directions) {
private static void placeGiant(SaplingFeature tree, SaplingGrowTreeEvent event, Block type, Vec3i[] directions) { // Feature<NoFeatureConfig> feature = tree.nextGiant(event.getRand());
Feature<NoFeatureConfig> feature = tree.nextGiant(event.getRand()); //
// // if no giant tree exists for this sapling type try and place a normal one instead
// if no giant tree exists for this sapling type try and place a normal one instead // if (feature == null) {
if (feature == null) { // placeNormal(tree, event, directions);
placeNormal(tree, event, directions); // return;
return; // }
} //
// // do not continue if unable to place the tree
// do not continue if unable to place the tree // if (!SaplingPlacer.placeTree(feature, event, directions)) {
if (!SaplingPlacer.placeTree(feature, event, directions)) { // return;
return; // }
} //
// // iterate through the contributing saplings and remove any that were not destroyed during tree creation
// iterate through the contributing saplings and remove any that were not destroyed during tree creation // BlockPos pos = event.getPos();
BlockPos pos = event.getPos(); // for (Vec3i dir : directions) {
for (Vec3i dir : directions) { // BlockPos blockPos = pos.add(dir);
BlockPos blockPos = pos.add(dir); // BlockState state = event.getWorld().getBlockState(blockPos);
BlockState state = event.getWorld().getBlockState(blockPos); // if (state.getBlock() == type) {
if (state.getBlock() == type) { // event.getWorld().removeBlock(blockPos, false);
event.getWorld().removeBlock(blockPos, false); // }
} // }
} // }
} //
// private static Vec3i[] getNeighbourDirections(IWorld world, Block block, BlockPos pos) {
private static Vec3i[] getNeighbourDirections(IWorld world, Block block, BlockPos pos) { // for (Vec3i[] dirs : DIRECTIONS) {
for (Vec3i[] dirs : DIRECTIONS) { // boolean match = true;
boolean match = true; // for (Vec3i dir : dirs) {
for (Vec3i dir : dirs) { // BlockState state = world.getBlockState(pos.add(dir));
BlockState state = world.getBlockState(pos.add(dir)); // if (state.getBlock() != block) {
if (state.getBlock() != block) { // match = false;
match = false; // break;
break; // }
} // }
} // if (match) {
if (match) { // return dirs;
return dirs; // }
} // }
} // return NONE;
return NONE; // }
} //
// private static boolean isTerraWorld(IWorld world) {
private static boolean isTerraWorld(IWorld world) { // if (world instanceof World) {
if (world instanceof World) { // return isTerraWorld(((World) world).getWorldType());
return isTerraWorld(((World) world).getWorldType()); // }
} // return false;
return false; // }
} //
// private static boolean isTerraWorld(WorldType type) {
private static boolean isTerraWorld(WorldType type) { // return type.getName().equals("terraforged");
return type.getName().equals("terraforged"); // }
} //}
}

View File

@ -29,28 +29,29 @@ import com.mojang.datafixers.types.DynamicOps;
import com.terraforged.mod.Log; import com.terraforged.mod.Log;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Blocks; 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.HashMap;
import java.util.Map; import java.util.Map;
public class SaplingManager { 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); return saplings.get(name);
} }
public static void register(Block block, SaplingConfig config) { 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)); 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)); saplings.put(location, new SaplingFeature(config));
} }

View File

@ -1,149 +1,149 @@
/* ///*
* // *
* MIT License // * MIT License
* // *
* Copyright (c) 2020 TerraForged // * Copyright (c) 2020 TerraForged
* // *
* Permission is hereby granted, free of charge, to any person obtaining a copy // * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal // * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights // * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is // * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: // * furnished to do so, subject to the following conditions:
* // *
* The above copyright notice and this permission notice shall be included in all // * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. // * copies or substantial portions of the Software.
* // *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // * 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 // * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. // * SOFTWARE.
*/ // */
//
package com.terraforged.mod.feature.tree; //package com.terraforged.mod.feature.tree;
//
import com.terraforged.feature.template.decorator.DecoratedFeature; //import com.terraforged.feature.template.decorator.DecoratedFeature;
import com.terraforged.feature.template.decorator.DecoratorWorld; //import com.terraforged.feature.template.decorator.DecoratorWorld;
import com.terraforged.feature.template.feature.TemplateFeature; //import com.terraforged.feature.template.feature.TemplateFeature;
import net.minecraft.block.BlockState; //import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; //import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i; //import net.minecraft.util.math.Vec3i;
import net.minecraft.world.IWorld; //import net.minecraft.world.IWorld;
import net.minecraft.world.gen.ChunkGenerator; //import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.feature.Feature; //import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.NoFeatureConfig; //import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.server.ServerChunkProvider; //import net.minecraft.world.server.ServerChunkProvider;
import net.minecraftforge.event.world.SaplingGrowTreeEvent; //import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.Event; //import net.minecraftforge.eventbus.api.Event;
//
public class SaplingPlacer { //public class SaplingPlacer {
//
public static boolean placeTree(Feature<NoFeatureConfig> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) { // public static boolean placeTree(Feature<DefaultFeatureConfig> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
if (feature == null) { // if (feature == null) {
return false; // return false;
} // }
//
event.setResult(Event.Result.DENY); // event.setResult(Event.Result.DENY);
//
if (feature instanceof DecoratedFeature) { // if (feature instanceof DecoratedFeature) {
return placeDecorated((DecoratedFeature<?,?>) feature, event, dirs); // return placeDecorated((DecoratedFeature<?,?>) feature, event, dirs);
} // }
//
return placeNormal(feature, event, dirs); // return placeNormal(feature, event, dirs);
} // }
//
private static <W extends DecoratorWorld> boolean placeDecorated(DecoratedFeature<?, W> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) { // private static <W extends DecoratorWorld> boolean placeDecorated(DecoratedFeature<?, W> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
if (!(event.getWorld().getChunkProvider() instanceof ServerChunkProvider)) { // if (!(event.getWorld().getChunkProvider() instanceof ServerChunkProvider)) {
return false; // return false;
} // }
//
TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos()); // TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos());
W world = feature.wrap(buffer); // W world = feature.wrap(buffer);
//
ChunkGenerator<?> generator = ((ServerChunkProvider) event.getWorld().getChunkProvider()).getChunkGenerator(); // ChunkGenerator<?> generator = ((ServerChunkProvider) event.getWorld().getChunkProvider()).getChunkGenerator();
feature.placeFeature(world, generator, event.getRand(), event.getPos(), NoFeatureConfig.NO_FEATURE_CONFIG); // feature.placeFeature(world, generator, event.getRand(), event.getPos(), DefaultFeatureConfig.NO_FEATURE_CONFIG);
//
// check that the tree can grow here // // check that the tree can grow here
if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) { // if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) {
return false; // return false;
} // }
//
BlockPos translation = buffer.getBaseMin().add(getMin(dirs)); // BlockPos translation = buffer.getBaseMin().add(getMin(dirs));
//
// apply buffer to world with translation // // apply buffer to world with translation
applyBuffer(buffer, event.getWorld(), translation); // applyBuffer(buffer, event.getWorld(), translation);
//
// translate the decoration positions and apply in the world // // translate the decoration positions and apply in the world
world.setDelegate(event.getWorld()); // world.setDelegate(event.getWorld());
world.translate(translation); // world.translate(translation);
feature.decorate(world, event.getRand()); // feature.decorate(world, event.getRand());
return true; // return true;
} // }
//
private static boolean placeNormal(Feature<NoFeatureConfig> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) { // private static boolean placeNormal(Feature<DefaultFeatureConfig> feature, SaplingGrowTreeEvent event, Vec3i[] dirs) {
// apply the feature to a buffer // // apply the feature to a buffer
TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos()); // TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos());
buffer.placeFeature(feature, event.getPos(), event.getRand()); // buffer.placeFeature(feature, event.getPos(), event.getRand());
//
// check that the tree can grow here // // check that the tree can grow here
if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) { // if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) {
return false; // return false;
} // }
//
// get the min position in the 2x2 grid // // get the min position in the 2x2 grid
BlockPos translation = buffer.getBaseMin().add(getMin(dirs)); // BlockPos translation = buffer.getBaseMin().add(getMin(dirs));
//
// copy the feature from the buffer to the world while translating each block // // copy the feature from the buffer to the world while translating each block
applyBuffer(buffer, event.getWorld(), translation); // applyBuffer(buffer, event.getWorld(), translation);
return true; // return true;
} // }
//
private static void applyBuffer(TreeGrowBuffer buffer, IWorld world, BlockPos translation) { // private static void applyBuffer(TreeGrowBuffer buffer, IWorld world, BlockPos translation) {
try (BlockPos.PooledMutable pos = BlockPos.PooledMutable.retain()) { // try (BlockPos.PooledMutable pos = BlockPos.PooledMutable.retain()) {
for (TemplateFeature.BlockInfo block : buffer.getChanges()) { // for (TemplateFeature.BlockInfo block : buffer.getChanges()) {
int x = block.getPos().getX() + translation.getX(); // int x = block.getPos().getX() + translation.getX();
int y = block.getPos().getY(); // int y = block.getPos().getY();
int z = block.getPos().getZ() + translation.getZ(); // int z = block.getPos().getZ() + translation.getZ();
//
pos.setPos(x, y, z); // pos.setPos(x, y, z);
//
BlockState current = world.getBlockState(pos); // BlockState current = world.getBlockState(pos);
if (current.isSolid()) { // if (current.isSolid()) {
continue; // continue;
} // }
//
world.setBlockState(pos, block.getState(), 2); // world.setBlockState(pos, block.getState(), 2);
} // }
} // }
} // }
//
private static boolean overheadIsSolid(IWorld world, BlockPos pos, int topY) { // private static boolean overheadIsSolid(IWorld world, BlockPos pos, int topY) {
try (BlockPos.PooledMutable blockPos = BlockPos.PooledMutable.retain()) { // try (BlockPos.PooledMutable blockPos = BlockPos.PooledMutable.retain()) {
for (int y = pos.getY(); y <= topY; y++) { // for (int y = pos.getY(); y <= topY; y++) {
blockPos.setPos(pos.getX(), y, pos.getZ()); // blockPos.setPos(pos.getX(), y, pos.getZ());
BlockState state = world.getBlockState(pos); // BlockState state = world.getBlockState(pos);
if (state.isSolid()) { // if (state.isSolid()) {
return true; // return true;
} // }
} // }
return false; // return false;
} // }
} // }
//
private static Vec3i getMin(Vec3i[] dirs) { // private static Vec3i getMin(Vec3i[] dirs) {
Vec3i min = Vec3i.NULL_VECTOR; // Vec3i min = Vec3i.NULL_VECTOR;
for (Vec3i dir : dirs) { // for (Vec3i dir : dirs) {
if (dir.getX() < min.getX() && dir.getZ() <= min.getZ()) { // if (dir.getX() < min.getX() && dir.getZ() <= min.getZ()) {
min = dir; // min = dir;
continue; // continue;
} // }
if (dir.getZ() < min.getZ() && dir.getX() <= min.getX()) { // if (dir.getZ() < min.getZ() && dir.getX() <= min.getX()) {
min = dir; // min = dir;
} // }
} // }
return min; // return min;
} // }
} //}

View File

@ -28,13 +28,13 @@ package com.terraforged.mod.feature.tree;
import com.terraforged.feature.template.feature.TemplateFeature; import com.terraforged.feature.template.feature.TemplateFeature;
import com.terraforged.feature.util.WorldDelegate; import com.terraforged.feature.util.WorldDelegate;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
import net.minecraft.world.IWorld; 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.Feature;
import net.minecraft.world.gen.feature.IFeatureConfig; import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.server.ServerChunkProvider;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -74,21 +74,21 @@ public class TreeGrowBuffer extends WorldDelegate {
if (pos.getY() < this.pos.getY()) { if (pos.getY() < this.pos.getY()) {
return false; return false;
} }
if (state.isSolid()) { if (state.isOpaque()) {
recordPos(pos); recordPos(pos);
} }
changes.add(new TemplateFeature.BlockInfo(pos, state)); changes.add(new TemplateFeature.BlockInfo(pos, state));
return true; return true;
} }
public void placeFeature(Feature<NoFeatureConfig> feature, BlockPos pos, Random random) { public void placeFeature(Feature<DefaultFeatureConfig> feature, BlockPos pos, Random random) {
placeFeature(feature, pos, random, NoFeatureConfig.NO_FEATURE_CONFIG); placeFeature(feature, pos, random, DefaultFeatureConfig.DEFAULT);
} }
public <T extends IFeatureConfig> void placeFeature(Feature<T> feature, BlockPos pos, Random random, T config) { public <T extends FeatureConfig> void placeFeature(Feature<T> feature, BlockPos pos, Random random, T config) {
if (getChunkProvider() instanceof ServerChunkProvider) { if (getChunkManager() instanceof ServerChunkManager) {
ServerChunkProvider chunkProvider = (ServerChunkProvider) getChunkProvider(); ServerChunkManager chunkProvider = (ServerChunkManager) getChunkManager();
feature.place(this, chunkProvider.getChunkGenerator(), random, pos, config); feature.generate(this, chunkProvider.getChunkGenerator(), random, pos, config);
} }
} }

View File

@ -27,23 +27,23 @@ package com.terraforged.mod.gui;
import com.terraforged.mod.gui.element.CheckBox; import com.terraforged.mod.gui.element.CheckBox;
import com.terraforged.mod.gui.element.Element; 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.screen.Screen;
import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.text.TranslatableText;
public class OverlayScreen extends Screen implements OverlayRenderer { public class OverlayScreen extends Screen implements OverlayRenderer {
public boolean showTooltips = false; public boolean showTooltips = false;
public OverlayScreen() { public OverlayScreen() {
super(new TranslationTextComponent("")); super(new TranslatableText(""));
super.minecraft = Minecraft.getInstance(); super.minecraft = MinecraftClient.getInstance();
super.font = minecraft.fontRenderer; super.font = minecraft.textRenderer;
} }
@Override @Override
public <T extends Widget> T addButton(T buttonIn) { public <T extends AbstractButtonWidget> T addButton(T buttonIn) {
return super.addButton(buttonIn); return super.addButton(buttonIn);
} }
@ -57,7 +57,7 @@ public class OverlayScreen extends Screen implements OverlayRenderer {
@Override @Override
public void renderOverlays(Screen screen, int mouseX, int mouseY) { public void renderOverlays(Screen screen, int mouseX, int mouseY) {
for (Widget button : buttons) { for (AbstractButtonWidget button : buttons) {
if (button.isMouseOver(mouseX, mouseY)) { if (button.isMouseOver(mouseX, mouseY)) {
if (button instanceof Element) { if (button instanceof Element) {
screen.renderTooltip(((Element) button).getTooltip(), mouseX, mouseY); screen.renderTooltip(((Element) button).getTooltip(), mouseX, mouseY);

View File

@ -26,33 +26,31 @@
package com.terraforged.mod.gui; package com.terraforged.mod.gui;
import com.terraforged.mod.gui.element.Element; import com.terraforged.mod.gui.element.Element;
import com.terraforged.mod.gui.preview.Preview; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.list.AbstractOptionList; import net.minecraft.client.gui.widget.ElementListWidget;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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; private boolean hovered = false;
public ScrollPane(int slotHeightIn) { 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)); super.addEntry(new Entry(button));
} }
@Override @Override
public void renderOverlays(Screen screen, int x, int y) { public void renderOverlays(Screen screen, int x, int y) {
for (Entry entry : this.children()) { for (Entry entry : this.children()) {
if (entry.isMouseOver(x, y) && entry.option.isMouseOver(x, y)) { if (/*entry.isMouseOver(x, y) && todo lost*/ entry.option.isMouseOver(x, y)) {
Widget button = entry.option; AbstractButtonWidget button = entry.option;
if (button instanceof Element) { if (button instanceof Element) {
screen.renderTooltip(((Element) button).getTooltip(), x, y); screen.renderTooltip(((Element) button).getTooltip(), x, y);
return; return;
@ -74,7 +72,7 @@ public class ScrollPane extends AbstractOptionList<ScrollPane.Entry> implements
@Override @Override
protected int getScrollbarPosition() { protected int getScrollbarPosition() {
return getRight(); return getMaxPosition(); // todo old getRight
} }
@Override @Override
@ -82,16 +80,16 @@ public class ScrollPane extends AbstractOptionList<ScrollPane.Entry> implements
return hovered && super.mouseScrolled(x, y, direction); 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; this.option = option;
} }
@Override @Override
public List<? extends IGuiEventListener> children() { public List<? extends net.minecraft.client.gui.Element> children() {
return Collections.singletonList(option); return Collections.singletonList(option);
} }
@ -113,10 +111,10 @@ public class ScrollPane extends AbstractOptionList<ScrollPane.Entry> implements
option.y = top; option.y = top;
option.visible = true; option.visible = true;
option.setWidth(optionWidth); option.setWidth(optionWidth);
option.setHeight(height); // option.height = height; todo maybe use accessor
if (option instanceof Preview) { //if (option instanceof Preview) {
option.setHeight(option.getWidth()); // option.setHeight(option.getWidth());
} //}
option.render(mouseX, mouseY, partialTicks); option.render(mouseX, mouseY, partialTicks);
} }
} }

View File

@ -40,11 +40,11 @@ import com.terraforged.mod.gui.preview.PreviewPage;
import com.terraforged.mod.settings.SettingsHelper; import com.terraforged.mod.settings.SettingsHelper;
import com.terraforged.mod.settings.TerraSettings; import com.terraforged.mod.settings.TerraSettings;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.CreateWorldScreen;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.gui.screen.world.CreateWorldScreen;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -55,7 +55,8 @@ import java.io.Writer;
public class SettingsScreen extends OverlayScreen { 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 Page[] pages;
private final CreateWorldScreen parent; private final CreateWorldScreen parent;
@ -65,7 +66,7 @@ public class SettingsScreen extends OverlayScreen {
private int pageIndex = 0; private int pageIndex = 0;
public SettingsScreen(CreateWorldScreen parent) { public SettingsScreen(CreateWorldScreen parent) {
NBTHelper.deserialize(parent.chunkProviderSettingsJson, settings); NBTHelper.deserialize(parent.generatorOptionsTag, settings);
this.parent = parent; this.parent = parent;
this.pages = new Page[]{ this.pages = new Page[]{
new GeneratorPage(settings, preview), new GeneratorPage(settings, preview),
@ -105,21 +106,21 @@ public class SettingsScreen extends OverlayScreen {
} }
// -52 // -52
addButton(new Button(buttonsCenter - buttonWidth - buttonPad, buttonsRow, buttonWidth, buttonHeight, "Cancel" addButton(new ButtonWidget(buttonsCenter - buttonWidth - buttonPad, buttonsRow, buttonWidth, buttonHeight, "Cancel"
, b -> onClose())); , b -> onClose()));
// +2 // +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) { for (Page page : pages) {
page.save(); page.save();
} }
parent.chunkProviderSettingsJson = NBTHelper.serializeCompact(settings); parent.generatorOptionsTag = NBTHelper.serializeCompact(settings);
onClose(); onClose();
})); }));
// -106 // -106
addButton(new Button(buttonsCenter - (buttonWidth * 2 + (buttonPad * 3)), buttonsRow, buttonWidth, addButton(new ButtonWidget(buttonsCenter - (buttonWidth * 2 + (buttonPad * 3)), buttonsRow, buttonWidth,
buttonHeight, "<<", NO_ACTION) { buttonHeight, "<<", NO_ACTION) {
@Override @Override
public void render(int mouseX, int mouseY, float partialTicks) { public void render(int mouseX, int mouseY, float partialTicks) {
@ -142,7 +143,7 @@ public class SettingsScreen extends OverlayScreen {
}); });
// +56 // +56
addButton(new Button(buttonsCenter + buttonWidth + (buttonPad * 3), buttonsRow, buttonWidth, buttonHeight, addButton(new ButtonWidget(buttonsCenter + buttonWidth + (buttonPad * 3), buttonsRow, buttonWidth, buttonHeight,
">>", NO_ACTION) { ">>", NO_ACTION) {
@Override @Override
public void render(int mouseX, int mouseY, float partialTicks) { 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 @Override
public void onClick(double mouseX, double mouseY) { public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY); super.onClick(mouseX, mouseY);
@ -236,20 +237,20 @@ public class SettingsScreen extends OverlayScreen {
page.close(); page.close();
} }
preview.close(); preview.close();
Minecraft.getInstance().displayGuiScreen(parent); MinecraftClient.getInstance().openScreen(parent);
} }
private void export(Settings settings) { private void export(Settings settings) {
for (Page page : pages) { for (Page page : pages) {
page.save(); page.save();
} }
CompoundNBT tag = NBTHelper.serializeCompact(settings); CompoundTag tag = NBTHelper.serializeCompact(settings);
JsonElement json = NBTHelper.toJson(tag); 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); File file = new File(config, SettingsHelper.SETTINGS_FILE_NAME);
try (Writer writer = new BufferedWriter(new FileWriter(file))) { try (Writer writer = new BufferedWriter(new FileWriter(file))) {
new GsonBuilder().setPrettyPrinting().create().toJson(json, writer); new GsonBuilder().setPrettyPrinting().create().toJson(json, writer);
Util.getOSType().openURI(file.getParentFile().toURI()); Util.getOperatingSystem().open(file.getParentFile().toURI());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -25,10 +25,10 @@
package com.terraforged.mod.gui.element; package com.terraforged.mod.gui.element;
import net.minecraft.nbt.CompoundNBT; import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListTag;
import net.minecraftforge.common.util.Constants; import net.minecraft.nbt.Tag;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -47,11 +47,11 @@ public interface Element {
return ID_COUNTER.getAndAdd(1); return ID_COUNTER.getAndAdd(1);
} }
static List<String> readTooltip(CompoundNBT value) { static List<String> readTooltip(CompoundTag value) {
if (value.contains("#comment")) { if (value.contains("#comment")) {
ListNBT comment = value.getList("#comment", Constants.NBT.TAG_STRING); ListTag comment = value.getList("#comment", NbtType.STRING);
return comment.stream() return comment.stream()
.map(INBT::getString) .map(Tag::asString)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
return Collections.emptyList(); return Collections.emptyList();

View File

@ -25,9 +25,9 @@
package com.terraforged.mod.gui.element; 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) { public TerraButton(String displayString) {
super(0, 0, 200, 20, displayString, b -> {}); super(0, 0, 200, 20, displayString, b -> {});

View File

@ -25,28 +25,27 @@
package com.terraforged.mod.gui.element; package com.terraforged.mod.gui.element;
import net.minecraft.client.Minecraft; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.font.TextRenderer;
public class TerraLabel extends TerraButton { public class TerraLabel extends TerraButton {
// private final GuiLabel label; // private final GuiLabel label;
public TerraLabel(String text) { public TerraLabel(String text) {
super(text); super(text);
visible = true; visible = true;
// label = new GuiLabel( // label = new GuiLabel(
// Collections.singletonList(text), // Collections.singletonList(text),
// 0xFFFFFF, // 0xFFFFFF,
// Minecraft.getInstance().fontRenderer // Minecraft.getInstance().fontRenderer
// ); // );
// label.visible = true; // label.visible = true;
} }
@Override @Override
public void render(int mouseX, int mouseY, float partialTicks) { public void render(int mouseX, int mouseY, float partialTicks) {
Minecraft minecraft = Minecraft.getInstance(); TextRenderer fontrenderer = MinecraftClient.getInstance().textRenderer;
FontRenderer fontrenderer = minecraft.fontRenderer; fontrenderer.drawWithShadow(getMessage(), x, y + (height - 8) / 2, 0xFFFFFF);
fontrenderer.drawStringWithShadow(getMessage(), x, y + (height - 8) / 2, 0xFFFFFF);
} }
} }

View File

@ -1,100 +1,102 @@
/* ///*
* // *
* MIT License // * MIT License
* // *
* Copyright (c) 2020 TerraForged // * Copyright (c) 2020 TerraForged
* // *
* Permission is hereby granted, free of charge, to any person obtaining a copy // * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal // * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights // * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is // * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: // * furnished to do so, subject to the following conditions:
* // *
* The above copyright notice and this permission notice shall be included in all // * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. // * copies or substantial portions of the Software.
* // *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // * 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 // * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. // * SOFTWARE.
*/ // */
//
package com.terraforged.mod.gui.element; //package com.terraforged.mod.gui.element;
//
import net.minecraft.nbt.CompoundNBT; //import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraftforge.fml.client.gui.widget.Slider; //import net.minecraft.nbt.CompoundTag;
//import net.minecraftforge.fml.client.gui.widget.Slider;
import java.util.List; //
//import java.util.List;
public abstract class TerraSlider extends Slider implements Slider.ISlider, Element { //
//// todo need to add forge slider lol
private final CompoundNBT value; //public abstract class TerraSlider extends AbstractButtonWidget implements Slider.ISlider, Element {
private final List<String> tooltip; //
// private final CompoundTag value;
private Runnable callback = () -> {}; // private final List<String> tooltip;
//
public TerraSlider(String prefix, CompoundNBT value, boolean decimal) { // private Runnable callback = () -> {};
super(0, 0, 100, 20, prefix, "", value.getFloat("#min"), value.getFloat("#max"), 0F, decimal, true, b -> {}); //
this.value = value; // public TerraSlider(String prefix, CompoundTag value, boolean decimal) {
this.parent = this; // super(0, 0, 100, 20, prefix, "", value.getFloat("#min"), value.getFloat("#max"), 0F, decimal, true, b -> {});
this.tooltip = Element.readTooltip(value); // this.value = value;
} // this.parent = this;
// this.tooltip = Element.readTooltip(value);
public TerraSlider callback(Runnable callback) { // }
this.callback = callback; //
return this; // public TerraSlider callback(Runnable callback) {
} // this.callback = callback;
// return this;
@Override // }
public List<String> getTooltip() { //
return tooltip; // @Override
} // public List<String> getTooltip() {
// return tooltip;
@Override // }
public void onChangeSliderValue(Slider slider) { //
onChange(slider, value); // @Override
} // public void onChangeSliderValue(Slider slider) {
// onChange(slider, value);
@Override // }
public void onRelease(double mouseX, double mouseY) { //
super.onRelease(mouseX, mouseY); // @Override
callback.run(); // 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 { // protected abstract void onChange(Slider slider, CompoundTag value);
//
public Int(String prefix, CompoundNBT value) { // public static class Int extends TerraSlider {
super(prefix, value, false); //
setValue(value.getInt("value")); // public Int(String prefix, CompoundTag value) {
updateSlider(); // super(prefix, value, false);
} // setValue(value.getInt("value"));
// updateSlider();
@Override // }
protected void onChange(Slider slider, CompoundNBT value) { //
value.putInt("value", slider.getValueInt()); // @Override
} // protected void onChange(Slider slider, CompoundTag value) {
} // value.putInt("value", slider.getValueInt());
// }
public static class Float extends TerraSlider { // }
//
public Float(String prefix, CompoundNBT value) { // public static class Float extends TerraSlider {
super(prefix, value, true); //
precision = 3; // public Float(String prefix, CompoundTag value) {
setValue(value.getFloat("value")); // super(prefix, value, true);
updateSlider(); // precision = 3;
} // setValue(value.getFloat("value"));
// updateSlider();
@Override // }
protected void onChange(Slider slider, CompoundNBT value) { //
int i = (int) (slider.getValue() * 1000); // @Override
float f = i / 1000F; // protected void onChange(Slider slider, CompoundTag value) {
value.putFloat("value", f); // int i = (int) (slider.getValue() * 1000);
} // float f = i / 1000F;
} // value.putFloat("value", f);
} // }
// }
//}

View File

@ -25,25 +25,26 @@
package com.terraforged.mod.gui.element; package com.terraforged.mod.gui.element;
import net.minecraft.client.Minecraft; import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.client.MinecraftClient;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.util.Constants; import net.minecraft.nbt.ListTag;
public class Toggle extends TerraButton { public class Toggle extends TerraButton {
private final String prefix; private final String prefix;
private final CompoundNBT value; private final CompoundTag value;
private final ListNBT options; private final ListTag options;
private int index; 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")); super(value.getString("value"));
this.value = value; this.value = value;
this.prefix = prefix; 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++) { for (int i = 0; i < options.size(); i++) {
String s = options.getString(i); String s = options.getString(i);
if (s.equals(value.getString("value"))) { if (s.equals(value.getString("value"))) {
@ -63,7 +64,7 @@ public class Toggle extends TerraButton {
public boolean mouseClicked(double mx, double my, int button) { public boolean mouseClicked(double mx, double my, int button) {
if (super.isValidClickButton(button)) { if (super.isValidClickButton(button)) {
int direction = button == 0 ? 1 : -1; int direction = button == 0 ? 1 : -1;
this.playDownSound(Minecraft.getInstance().getSoundHandler()); this.playDownSound(MinecraftClient.getInstance().getSoundManager());
this.onClick(mx, my, direction); this.onClick(mx, my, direction);
return true; return true;
} }

View File

@ -28,12 +28,12 @@ package com.terraforged.mod.gui.page;
import com.terraforged.mod.gui.OverlayScreen; import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.settings.TerraSettings; import com.terraforged.mod.settings.TerraSettings;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
public class FeaturePage extends BasePage { public class FeaturePage extends BasePage {
private final TerraSettings settings; private final TerraSettings settings;
private final CompoundNBT featureSettings; private final CompoundTag featureSettings;
public FeaturePage(TerraSettings settings) { public FeaturePage(TerraSettings settings) {
this.settings = settings; this.settings = settings;

View File

@ -29,13 +29,13 @@ import com.terraforged.core.settings.Settings;
import com.terraforged.mod.gui.OverlayScreen; import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.gui.preview.PreviewPage; import com.terraforged.mod.gui.preview.PreviewPage;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
public class FilterPage extends BasePage { public class FilterPage extends BasePage {
private final Settings settings; private final Settings settings;
private final PreviewPage preview; private final PreviewPage preview;
private final CompoundNBT filterSettings; private final CompoundTag filterSettings;
public FilterPage(Settings settings, PreviewPage preview) { public FilterPage(Settings settings, PreviewPage preview) {
this.settings = settings; this.settings = settings;

View File

@ -29,13 +29,13 @@ import com.terraforged.core.settings.Settings;
import com.terraforged.mod.gui.OverlayScreen; import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.gui.preview.PreviewPage; import com.terraforged.mod.gui.preview.PreviewPage;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
public class GeneratorPage extends BasePage { public class GeneratorPage extends BasePage {
private final Settings settings; private final Settings settings;
private final PreviewPage preview; private final PreviewPage preview;
private final CompoundNBT generatorSettings; private final CompoundTag generatorSettings;
public GeneratorPage(Settings settings, PreviewPage preview) { public GeneratorPage(Settings settings, PreviewPage preview) {
this.settings = settings; this.settings = settings;

View File

@ -30,23 +30,23 @@ import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.gui.ScrollPane; import com.terraforged.mod.gui.ScrollPane;
import com.terraforged.mod.gui.element.TerraButton; import com.terraforged.mod.gui.element.TerraButton;
import com.terraforged.mod.gui.element.TerraLabel; 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.gui.element.Toggle;
import com.terraforged.mod.util.nbt.NBTHelper; 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.screen.Screen;
import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.Tag;
import net.minecraftforge.common.util.Constants;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; 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_HEIGHT = 20;
private static final int SLIDER_PAD = 2; private static final int SLIDER_PAD = 2;
@ -126,50 +126,51 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer {
init(parent); 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); 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); AtomicInteger top = new AtomicInteger(y);
NBTHelper.stream(settings).forEach(value -> { NBTHelper.stream(settings).forEach(value -> {
String name = value.getString("#display"); String name = value.getString("#display");
Widget button = createButton(name, value, callback); AbstractButtonWidget button = createButton(name, value, callback);
if (button != null) { if (button != null) {
button.setWidth(column.width); button.setWidth(column.width);
button.setHeight(SLIDER_HEIGHT); // button.setHeight(SLIDER_HEIGHT); todo mixin
button.x = x; button.x = x;
button.y = top.getAndAdd(SLIDER_HEIGHT + SLIDER_PAD); button.y = top.getAndAdd(SLIDER_HEIGHT + SLIDER_PAD);
consumer.accept(button); consumer.accept(button);
} else if (deep) { } else if (deep) {
INBT child = value.get("value"); Tag child = value.get("value");
if (child == null || child.getId() != Constants.NBT.TAG_COMPOUND) { if (child == null || child.getType() != NbtType.COMPOUND) {
return; return;
} }
TerraLabel label = new TerraLabel(name); TerraLabel label = new TerraLabel(name);
label.x = x; label.x = x;
label.y = top.getAndAdd(SLIDER_HEIGHT + SLIDER_PAD); label.y = top.getAndAdd(SLIDER_HEIGHT + SLIDER_PAD);
consumer.accept(label); 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) { public AbstractButtonWidget createButton(String name, CompoundTag value, Runnable callback) {
INBT tag = value.get("value"); Tag tag = value.get("value");
if (tag == null) { if (tag == null) {
return null; return null;
} }
byte type = tag.getId(); byte type = tag.getType();
if (type == Constants.NBT.TAG_INT) { if (type == NbtType.INT) {
return new TerraSlider.Int(name + ": ", value).callback(callback); return new TerraButton(name);// todo slider return new TerraSlider.Int(name + ": ", value).callback(callback);
} else if (type == Constants.NBT.TAG_FLOAT) { } else if (type == NbtType.FLOAT) {
return new TerraSlider.Float(name + ": ", value).callback(callback); return new TerraButton(name);// todo slider return new TerraSlider.Float(name + ": ", value).callback(callback);
} else if (type == Constants.NBT.TAG_STRING && value.contains("#options")) { } else if (type == NbtType.STRING && value.contains("#options")) {
return new Toggle(name + ": ", value).callback(callback); return new Toggle(name + ": ", value).callback(callback);
} else if (type == Constants.NBT.TAG_STRING) { } else if (type == NbtType.STRING) {
return new TerraButton(name); return new TerraButton(name);
} else { } else {
return null; return null;

View File

@ -29,13 +29,13 @@ import com.terraforged.core.settings.Settings;
import com.terraforged.mod.gui.OverlayScreen; import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.gui.preview.PreviewPage; import com.terraforged.mod.gui.preview.PreviewPage;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
public class RiverPage extends BasePage { public class RiverPage extends BasePage {
private final Settings settings; private final Settings settings;
private final PreviewPage preview; private final PreviewPage preview;
private final CompoundNBT riverSettings; private final CompoundTag riverSettings;
public RiverPage(Settings settings, PreviewPage preview) { public RiverPage(Settings settings, PreviewPage preview) {
this.settings = settings; this.settings = settings;

View File

@ -28,12 +28,12 @@ package com.terraforged.mod.gui.page;
import com.terraforged.mod.gui.OverlayScreen; import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.settings.TerraSettings; import com.terraforged.mod.settings.TerraSettings;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
public class StructurePage extends BasePage { public class StructurePage extends BasePage {
private final TerraSettings settings; private final TerraSettings settings;
private final CompoundNBT structureSettings; private final CompoundTag structureSettings;
public StructurePage(TerraSettings settings) { public StructurePage(TerraSettings settings) {
this.settings = settings; this.settings = settings;

View File

@ -29,13 +29,13 @@ import com.terraforged.core.settings.Settings;
import com.terraforged.mod.gui.OverlayScreen; import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.gui.preview.PreviewPage; import com.terraforged.mod.gui.preview.PreviewPage;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
public class TerrainPage extends BasePage { public class TerrainPage extends BasePage {
private final Settings settings; private final Settings settings;
private final PreviewPage preview; private final PreviewPage preview;
private final CompoundNBT terrainSettings; private final CompoundTag terrainSettings;
public TerrainPage(Settings settings, PreviewPage preview) { public TerrainPage(Settings settings, PreviewPage preview) {
this.settings = settings; this.settings = settings;

View File

@ -38,20 +38,20 @@ import com.terraforged.core.world.terrain.Terrain;
import com.terraforged.core.world.terrain.Terrains; import com.terraforged.core.world.terrain.Terrains;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import me.dags.noise.util.NoiseUtil; import me.dags.noise.util.NoiseUtil;
import net.minecraft.client.Minecraft; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.AbstractGui; import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.renderer.texture.NativeImage; import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import java.awt.*; import java.awt.Color;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; 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 FACTOR = 4;
private static final int BLOCK_SIZE = 256;//Size.chunkToBlock(1 << FACTOR); 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 int offsetZ;
private final Random random = new Random(System.currentTimeMillis()); private final Random random = new Random(System.currentTimeMillis());
private final PreviewSettings previewSettings = new PreviewSettings(); 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 int seed;
private long lastUpdate = 0L; private long lastUpdate = 0L;
@ -73,7 +73,8 @@ public class Preview extends Button {
private String[] values = {"", "", ""}; private String[] values = {"", "", ""};
public Preview() { public Preview() {
super(0, 0, 0, 0, "", b -> {}); super(0, 0, 0, 0, "", b -> {
});
this.seed = random.nextInt(); this.seed = random.nextInt();
this.offsetX = random.nextInt(50000) - 25000; this.offsetX = random.nextInt(50000) - 25000;
this.offsetZ = random.nextInt(50000) - 25000; this.offsetZ = random.nextInt(50000) - 25000;
@ -87,6 +88,7 @@ public class Preview extends Button {
texture.close(); texture.close();
} }
@Override @Override
public void render(int mx, int my, float partialTicks) { public void render(int mx, int my, float partialTicks) {
preRender(); preRender();
@ -94,17 +96,18 @@ public class Preview extends Button {
texture.bindTexture(); texture.bindTexture();
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.enableRescaleNormal(); RenderSystem.enableRescaleNormal();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE,
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); 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(); RenderSystem.disableRescaleNormal();
updateLegend(mx, my); updateLegend(mx, my);
renderLegend(labels, values, x + 1, y + height + 2, 15, 0xFFFFFF); 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(); long time = System.currentTimeMillis();
if (time - lastUpdate < 50) { if (time - lastUpdate < 50) {
return; return;
@ -133,7 +136,7 @@ public class Preview extends Button {
} }
private void render(Region region) { private void render(Region region) {
NativeImage image = texture.getTextureData(); NativeImage image = texture.getImage();
if (image == null) { if (image == null) {
return; return;
} }
@ -146,17 +149,17 @@ public class Preview extends Button {
int width = region.getBlockSize().size; int width = region.getBlockSize().size;
region.iterate((cell, x, z) -> { region.iterate((cell, x, z) -> {
if (x < stroke || z < stroke || x >= width - stroke || z >= width - stroke) { 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 { } else {
Color color = renderer.color(cell, context); 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); NBTHelper.deserialize(prevSettings, previewSettings);
settings.generator.seed = seed; settings.generator.seed = seed;
this.settings = settings; this.settings = settings;
@ -172,7 +175,7 @@ public class Preview extends Button {
return renderer.generate(offsetX, offsetZ, 101 - previewSettings.zoom, false); 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) { if (region != null) {
int zoom = (101 - previewSettings.zoom); int zoom = (101 - previewSettings.zoom);
int width = Math.max(1, region.getBlockSize().size * zoom); int width = Math.max(1, region.getBlockSize().size * zoom);
@ -192,7 +195,7 @@ public class Preview extends Button {
} }
private float getLegendScale() { private float getLegendScale() {
int index = Minecraft.getInstance().gameSettings.guiScale - 1; int index = MinecraftClient.getInstance().options.guiScale - 1;
if (index < 0 || index >= LEGEND_SCALES.length) { if (index < 0 || index >= LEGEND_SCALES.length) {
// index=-1 == GuiScale(AUTO) which is the same as GuiScale(4) // 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 // 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.translatef(left, top, 0);
RenderSystem.scalef(scale, scale, 1); RenderSystem.scalef(scale, scale, 1);
FontRenderer renderer = Minecraft.getInstance().fontRenderer; TextRenderer renderer = MinecraftClient.getInstance().textRenderer;
int spacing = 0; int spacing = 0;
for (String s : labels) { for (String s : labels) {
spacing = Math.max(spacing, renderer.getStringWidth(s)); spacing = Math.max(spacing, renderer.getStringWidth(s));
@ -221,7 +224,7 @@ public class Preview extends Button {
String label = labels[i]; String label = labels[i];
String value = values[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); value = value.substring(0, value.length() - 1);
} }

View File

@ -30,7 +30,7 @@ import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.gui.element.TerraButton; import com.terraforged.mod.gui.element.TerraButton;
import com.terraforged.mod.gui.page.BasePage; import com.terraforged.mod.gui.page.BasePage;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -38,7 +38,7 @@ public class PreviewPage extends BasePage {
private final Preview preview = new Preview(); private final Preview preview = new Preview();
private final Settings settings = new Settings(); private final Settings settings = new Settings();
private final CompoundNBT previewerSettings = NBTHelper.serialize(new PreviewSettings()); private final CompoundTag previewerSettings = NBTHelper.serialize(new PreviewSettings());
public PreviewPage() { public PreviewPage() {
@ -65,7 +65,7 @@ public class PreviewPage extends BasePage {
preview.x = 0; preview.x = 0;
preview.y = 0; preview.y = 0;
preview.setWidth(256); 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); addElements(right.left, right.top, right, previewerSettings, right.scrollPane::addButton, this::update);
right.scrollPane.addButton(new TerraButton("New Seed") { right.scrollPane.addButton(new TerraButton("New Seed") {

View File

@ -32,15 +32,14 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.ConcretePowderBlock; import net.minecraft.block.ConcretePowderBlock;
import net.minecraft.block.material.Material; import net.minecraft.block.Material;
import net.minecraft.tags.BlockTags; import net.minecraft.tag.BlockTags;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; 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.ConfiguredFeature;
import net.minecraft.world.gen.feature.DecoratedFeatureConfig; import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
import net.minecraft.world.gen.feature.OreFeatureConfig; import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraftforge.common.Tags;
import net.minecraftforge.registries.IForgeRegistryEntry;
import java.util.Set; import java.util.Set;
@ -73,14 +72,11 @@ public class MaterialHelper {
} }
public static boolean isStone(Block block) { public static boolean isStone(Block block) {
return Tags.Blocks.STONE.contains(block) return block == Blocks.STONE || block == Blocks.ANDESITE || block == Blocks.GRANITE || block == Blocks.DIORITE;
&& !isBlacklisted(block)
&& !("" + block.getRegistryName()).contains("polished_");
} }
public static boolean isDirt(Block block) { public static boolean isDirt(Block block) {
return Tags.Blocks.DIRT.contains(block) return block == Blocks.DIRT || block == Blocks.COARSE_DIRT || block == Blocks.FARMLAND || isGrass(block);
&& !isBlacklisted(block);
} }
public static boolean isClay(Block block) { public static boolean isClay(Block block) {
@ -101,24 +97,19 @@ public class MaterialHelper {
} }
public static boolean isGravel(Block block) { 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) { public static boolean isOre(Block block) {
return Tags.Blocks.ORES.contains(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;
&& !isBlacklisted(block);
} }
public static boolean isBlacklisted(Block block) { public static boolean isBlacklisted(Block block) {
return BLACKLIST.contains(block); return BLACKLIST.contains(block);
} }
public static String getName(IForgeRegistryEntry<?> entry) { public static <T> String getNamespace(Registry<T> registry, T entry) {
return "" + entry.getRegistryName(); Identifier name = registry.getId(entry);
}
public static String getNamespace(IForgeRegistryEntry<?> entry) {
ResourceLocation name = entry.getRegistryName();
if (name == null) { if (name == null) {
return "unknown"; return "unknown";
} }
@ -128,14 +119,14 @@ public class MaterialHelper {
public static float getHardness(BlockState state) { public static float getHardness(BlockState state) {
try (ObjectPool.Item<DummyBlockReader> reader = DummyBlockReader.pooled()) { try (ObjectPool.Item<DummyBlockReader> reader = DummyBlockReader.pooled()) {
reader.getValue().set(state); reader.getValue().set(state);
return state.getBlockHardness(reader.getValue(), BlockPos.ZERO); return state.getHardness(reader.getValue(), BlockPos.ORIGIN);
} }
} }
public static boolean isCube(BlockState state) { public static boolean isCube(BlockState state) {
try (ObjectPool.Item<DummyBlockReader> reader = DummyBlockReader.pooled()) { try (ObjectPool.Item<DummyBlockReader> reader = DummyBlockReader.pooled()) {
reader.getValue().set(state); reader.getValue().set(state);
return state.isNormalCube(reader.getValue(), BlockPos.ZERO); return state.isSimpleFullBlock(reader.getValue(), BlockPos.ORIGIN);
} }
} }

View File

@ -30,8 +30,8 @@ import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.api.material.state.States; import com.terraforged.api.material.state.States;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.tags.Tag; import net.minecraft.tag.Tag;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraft.util.registry.Registry;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -51,7 +51,7 @@ public class Materials {
public Materials() { public Materials() {
Predicate<Block> filter = getTagFilter(); Predicate<Block> filter = getTagFilter();
for (Block block : ForgeRegistries.BLOCKS) { for (Block block : Registry.BLOCK) {
if (filter.test(block)) { if (filter.test(block)) {
continue; continue;
} }
@ -142,22 +142,22 @@ public class Materials {
} }
private static Set<Block> create(Tag<Block> tag) { private static Set<Block> create(Tag<Block> tag) {
return new HashSet<>(tag.getAllElements()); return new HashSet<>(tag.values());
} }
private static Predicate<Block> getTagFilter() { private static Predicate<Block> getTagFilter() {
Set<String> namespaces = new HashSet<>(); Set<String> namespaces = new HashSet<>();
collectNamespace(namespaces, MaterialTags.WG_ROCK.getAllElements()); collectNamespace(namespaces, MaterialTags.WG_ROCK.values());
collectNamespace(namespaces, MaterialTags.WG_EARTH.getAllElements()); collectNamespace(namespaces, MaterialTags.WG_EARTH.values());
collectNamespace(namespaces, MaterialTags.WG_EARTH.getAllElements()); collectNamespace(namespaces, MaterialTags.WG_EARTH.values());
collectNamespace(namespaces, MaterialTags.WG_SEDIMENT.getAllElements()); collectNamespace(namespaces, MaterialTags.WG_SEDIMENT.values());
collectNamespace(namespaces, MaterialTags.WG_ORE.getAllElements()); collectNamespace(namespaces, MaterialTags.WG_ORE.values());
return b -> namespaces.contains(MaterialHelper.getNamespace(b)); return b -> namespaces.contains(MaterialHelper.getNamespace(Registry.BLOCK, b));
} }
private static void collectNamespace(Set<String> set, Collection<Block> blocks) { private static void collectNamespace(Set<String> set, Collection<Block> blocks) {
for (Block block : blocks) { for (Block block : blocks) {
set.add(MaterialHelper.getNamespace(block)); set.add(MaterialHelper.getNamespace(Registry.BLOCK, block));
} }
} }
} }

View File

@ -2,11 +2,10 @@ package com.terraforged.mod.settings;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.terraforged.mod.Log; import com.terraforged.mod.Log;
import com.terraforged.mod.TerraWorld;
import com.terraforged.mod.util.nbt.NBTHelper; 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.IWorld;
import net.minecraft.world.storage.WorldInfo; import net.minecraft.world.level.LevelProperties;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -22,14 +21,15 @@ public class SettingsHelper {
dedicated = true; dedicated = true;
} }
public static int getVersion(WorldInfo info) { public static int getVersion(LevelProperties info) {
if (info.getGeneratorOptions().isEmpty()) { if (info.getGeneratorOptions().isEmpty()) {
// if options have not been set then the world has been created // if options have not been set then the world has been created
// during the current runtime .: is not legacy // 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()) { if (version.isEmpty()) {
// version tag is absent in legacy worlds .: is legacy // version tag is absent in legacy worlds .: is legacy
return 0; return 0;
@ -44,13 +44,13 @@ public class SettingsHelper {
Log.info("Loading generator settings from json"); Log.info("Loading generator settings from json");
return new Gson().fromJson(reader, TerraSettings.class); return new Gson().fromJson(reader, TerraSettings.class);
} catch (Throwable ignored) { } 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(); TerraSettings settings = new TerraSettings();
if (!info.getGeneratorOptions().isEmpty()) { if (!info.getGeneratorOptions().isEmpty()) {
NBTHelper.deserialize(info.getGeneratorOptions(), settings); NBTHelper.deserialize(info.getGeneratorOptions(), settings);
@ -58,10 +58,10 @@ public class SettingsHelper {
return settings; 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.version = version;
settings.generator.seed = info.getSeed(); settings.generator.seed = info.getSeed();
CompoundNBT options = NBTHelper.serialize(settings); CompoundTag options = NBTHelper.serialize(settings);
info.setGeneratorOptions(options); info.setGeneratorOptions(options);
} }
} }