mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-16 21:30:08 +00:00
remove Tree
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.world;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
|
||||
public interface Tree {
|
||||
boolean plant(Vector3 l, World world, Random r);
|
||||
|
||||
Set<BlockType> getSpawnable();
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
cmd.setTabCompleter(command);
|
||||
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new CommonListener(terraPlugin), this); // Register master event listener
|
||||
Bukkit.getPluginManager().registerEvents(new CommonListener(), this); // Register master event listener
|
||||
PaperUtil.checkPaper(this);
|
||||
|
||||
try {
|
||||
|
||||
@@ -17,59 +17,13 @@
|
||||
|
||||
package com.dfsek.terra.bukkit.listeners;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.WorldConfig;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
import com.dfsek.terra.transform.MapTransform;
|
||||
import com.dfsek.terra.transform.TransformerImpl;
|
||||
import com.dfsek.terra.util.FastRandom;
|
||||
|
||||
|
||||
/**
|
||||
* Listener for events on all implementations.
|
||||
*/
|
||||
public class CommonListener implements Listener {
|
||||
private static final TransformerImpl<TreeType, String> TREE_TYPE_STRING_TRANSFORMER = new TransformerImpl.Builder<TreeType, String>()
|
||||
.addTransform(new MapTransform<TreeType, String>()
|
||||
.add(TreeType.COCOA_TREE, "JUNGLE_COCOA")
|
||||
.add(TreeType.BIG_TREE, "LARGE_OAK")
|
||||
.add(TreeType.TALL_REDWOOD, "LARGE_SPRUCE")
|
||||
.add(TreeType.REDWOOD, "SPRUCE")
|
||||
.add(TreeType.TREE, "OAK")
|
||||
.add(TreeType.MEGA_REDWOOD, "MEGA_SPRUCE")
|
||||
.add(TreeType.SWAMP, "SWAMP_OAK"))
|
||||
.addTransform(TreeType::toString).build();
|
||||
private final Platform platform;
|
||||
|
||||
public CommonListener(Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onSaplingGrow(StructureGrowEvent e) {
|
||||
if(e.isCancelled()) return;
|
||||
World bukkit = BukkitAdapter.adapt(e.getWorld());
|
||||
WorldConfig c = bukkit.getConfig();
|
||||
if(c.isDisableSaplings()) return;
|
||||
e.setCancelled(true);
|
||||
Block block = e.getLocation().getBlock();
|
||||
BlockData data = block.getBlockData();
|
||||
block.setType(Material.AIR);
|
||||
Tree tree = c.getRegistry(Tree.class).get(TREE_TYPE_STRING_TRANSFORMER.translate(e.getSpecies()));
|
||||
org.bukkit.Location location = e.getLocation();
|
||||
if(!tree.plant(new Vector3(location.getX(), location.getY(), location.getZ()), BukkitAdapter.adapt(e.getWorld()), new FastRandom()))
|
||||
block.setBlockData(data);
|
||||
public CommonListener() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +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.bukkit.world;
|
||||
|
||||
import org.bukkit.TreeType;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
|
||||
public class BukkitTree implements Tree {
|
||||
private final TreeType delegate;
|
||||
private final MaterialSet spawnable;
|
||||
private final Platform platform;
|
||||
|
||||
public BukkitTree(TreeType delegate, Platform platform) {
|
||||
this.delegate = delegate;
|
||||
this.platform = platform;
|
||||
this.spawnable = getSpawnable(delegate);
|
||||
}
|
||||
|
||||
private MaterialSet getSpawnable(TreeType type) {
|
||||
WorldHandle handle = platform.getWorldHandle();
|
||||
return switch(type) {
|
||||
case CRIMSON_FUNGUS -> MaterialSet.get(handle.createBlockData("minecraft:crimson_nylium"));
|
||||
case WARPED_FUNGUS -> MaterialSet.get(handle.createBlockData("minecraft:warped_nylium"));
|
||||
case BROWN_MUSHROOM, RED_MUSHROOM -> MaterialSet.get(handle.createBlockData("minecraft:mycelium"),
|
||||
handle.createBlockData("minecraft:grass_block"),
|
||||
handle.createBlockData("minecraft:podzol"));
|
||||
case CHORUS_PLANT -> MaterialSet.get(handle.createBlockData("minecraft:end_stone"));
|
||||
default -> MaterialSet.get(handle.createBlockData("minecraft:grass_block"), handle.createBlockData("minecraft:dirt"),
|
||||
handle.createBlockData("minecraft:podzol"));
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public boolean plant(Vector3 l, World world, Random r) {
|
||||
try(ProfileFrame ignore = platform.getProfiler().profile("bukkit_tree:" + delegate.toString().toLowerCase(Locale.ROOT))) {
|
||||
return BukkitAdapter.adapt(world).generateTree(BukkitAdapter.adapt(l).toLocation(BukkitAdapter.adapt(world)), delegate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
}
|
||||
@@ -20,29 +20,21 @@ package com.dfsek.terra.fabric;
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair.Mutable;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair.Mutable;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
@@ -73,22 +65,6 @@ public final class FabricAddon implements BaseAddon {
|
||||
} catch(ConfigException e) {
|
||||
logger.error("Error loading config template", e);
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
logger.info("Injecting structures into Terra");
|
||||
|
||||
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
|
||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
|
||||
try {
|
||||
event.getPack()
|
||||
.getCheckedRegistry(Tree.class)
|
||||
.register(entry.getKey().getValue().toString(), (Tree) entry.getValue());
|
||||
logger.info("Injected ConfiguredFeature {} as Tree.", entry.getKey().getValue());
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.put(event.getPack(), Mutable.of(template, null));
|
||||
})
|
||||
.global();
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.fabric.mixin.implementations;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.fabric.FabricEntryPoint;
|
||||
|
||||
|
||||
@Mixin(ConfiguredFeature.class)
|
||||
@Implements(@Interface(iface = Tree.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class ConfiguredFeatureMixin {
|
||||
@Shadow
|
||||
public abstract boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos);
|
||||
|
||||
@SuppressWarnings({ "ConstantConditions", "try" })
|
||||
public boolean terra$plant(Vector3 l, World world, Random r) {
|
||||
String id = BuiltinRegistries.CONFIGURED_FEATURE.getId((ConfiguredFeature<?, ?>) (Object) this).toString();
|
||||
try(ProfileFrame ignore = FabricEntryPoint.getPlatform().getProfiler().profile("fabric_tree:" + id.toLowerCase(Locale.ROOT))) {
|
||||
StructureWorldAccess fabricWorldAccess = ((StructureWorldAccess) world);
|
||||
ChunkGenerator generatorWrapper = ((ServerWorldAccess) world).toServerWorld().getChunkManager().getChunkGenerator();
|
||||
return generate(fabricWorldAccess, generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
public Set<BlockType> terra$getSpawnable() {
|
||||
return MaterialSet.get(FabricEntryPoint.getPlatform().getWorldHandle().createBlockData("minecraft:grass_block"),
|
||||
FabricEntryPoint.getPlatform().getWorldHandle().createBlockData("minecraft:podzol"),
|
||||
FabricEntryPoint.getPlatform().getWorldHandle().createBlockData("minecraft:mycelium"));
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
"access.StateAccessor",
|
||||
"implementations.BiomeMixin",
|
||||
"implementations.ConfiguredFeatureMixin",
|
||||
"implementations.block.BlockEntityMixin",
|
||||
"implementations.block.BlockMixin",
|
||||
"implementations.block.state.LootableContainerBlockEntityMixin",
|
||||
|
||||
Reference in New Issue
Block a user