move world handle into common module

This commit is contained in:
dfsek
2022-06-21 15:48:09 -07:00
parent 1a1000bbef
commit 2a6d130d20
4 changed files with 6 additions and 69 deletions

View File

@@ -49,14 +49,14 @@ import com.dfsek.terra.api.util.generic.Lazy;
import com.dfsek.terra.api.world.biome.PlatformBiome;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.handle.FabricItemHandle;
import com.dfsek.terra.fabric.handle.FabricWorldHandle;
import com.dfsek.terra.mod.handle.MinecraftWorldHandle;
import com.dfsek.terra.fabric.util.ProtoPlatformBiome;
public class PlatformImpl extends AbstractPlatform {
private static final Logger LOGGER = LoggerFactory.getLogger(PlatformImpl.class);
private final ItemHandle itemHandle = new FabricItemHandle();
private final WorldHandle worldHandle = new FabricWorldHandle();
private final WorldHandle worldHandle = new MinecraftWorldHandle();
private final Lazy<File> dataFolder = Lazy.lazy(() -> new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"));
private MinecraftServer server;

View File

@@ -49,14 +49,14 @@ import com.dfsek.terra.api.util.generic.Lazy;
import com.dfsek.terra.api.world.biome.PlatformBiome;
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
import com.dfsek.terra.forge.handle.ForgeItemHandle;
import com.dfsek.terra.forge.handle.ForgeWorldHandle;
import com.dfsek.terra.forge.util.ProtoPlatformBiome;
import com.dfsek.terra.mod.handle.MinecraftWorldHandle;
public class PlatformImpl extends AbstractPlatform {
private static final Logger LOGGER = LoggerFactory.getLogger(PlatformImpl.class);
private final ItemHandle itemHandle = new ForgeItemHandle();
private final WorldHandle worldHandle = new ForgeWorldHandle();
private final WorldHandle worldHandle = new MinecraftWorldHandle();
private final Lazy<File> dataFolder = Lazy.lazy(() -> new File("./config/Terra"));
public PlatformImpl() {

View File

@@ -1,59 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.forge.handle;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.Blocks;
import net.minecraft.command.argument.BlockArgumentParser;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.handle.WorldHandle;
public class ForgeWorldHandle implements WorldHandle {
private static final BlockState AIR = (BlockState) Blocks.AIR.getDefaultState();
@Override
public @NotNull BlockState createBlockState(@NotNull String data) {
try {
net.minecraft.block.BlockState state = BlockArgumentParser.block(Registry.BLOCK, data, true).blockState();
if(state == null) throw new IllegalArgumentException("Invalid data: " + data);
return (BlockState) state;
} catch(CommandSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
@Override
public @NotNull BlockState air() {
return AIR;
}
@Override
public @NotNull EntityType getEntity(@NotNull String id) {
Identifier identifier = Identifier.tryParse(id);
if(identifier == null) identifier = Identifier.tryParse(id);
return (EntityType) ForgeRegistries.ENTITIES.getHolder(identifier).orElseThrow().value();
}
}

View File

@@ -15,16 +15,12 @@
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.fabric.handle;
package com.dfsek.terra.mod.handle;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.Blocks;
import net.minecraft.command.argument.BlockArgumentParser;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.NotNull;
@@ -33,7 +29,7 @@ import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.handle.WorldHandle;
public class FabricWorldHandle implements WorldHandle {
public class MinecraftWorldHandle implements WorldHandle {
private static final BlockState AIR = (BlockState) Blocks.AIR.getDefaultState();