mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-03 14:26:27 +00:00
Bukkit Growing
This commit is contained in:
@@ -1,29 +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.listeners;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
|
||||
/**
|
||||
* Listener for events on all implementations.
|
||||
*/
|
||||
public class CommonListener implements Listener {
|
||||
public CommonListener() {
|
||||
}
|
||||
}
|
||||
@@ -1,104 +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.listeners;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
/**
|
||||
* Listener to load on Spigot servers, contains Villager crash prevention and hacky ender eye redirection.
|
||||
* <p>
|
||||
* (This is currently loaded on all servers; once Paper accepts the StructureLocateEvent PR this will only be loaded on servers without
|
||||
* StructureLocateEvent).
|
||||
*/
|
||||
public class SpigotListener implements Listener {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpigotListener.class);
|
||||
private final Platform platform;
|
||||
|
||||
public SpigotListener(Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEnderEye(EntitySpawnEvent e) {
|
||||
/*
|
||||
Entity entity = e.getEntity();
|
||||
if(e.getEntityType() == EntityType.ENDER_SIGNAL) {
|
||||
logger.info("Detected Ender Signal...");
|
||||
World w = BukkitAdapter.adapt(e.getEntity().getWorld());
|
||||
EnderSignal signal = (EnderSignal) entity;
|
||||
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(w.getConfig().getLocatable().get
|
||||
("STRONGHOLD"));
|
||||
if(config != null) {
|
||||
logger.info("Overriding Ender Signal...");
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()
|
||||
.toVector()), tw.getWorld(), 0, 500, location -> {
|
||||
if(location != null)
|
||||
signal.setTargetLocation(BukkitAdapter.adapt(location).toLocation(e.getLocation().getWorld()));
|
||||
logger.info("Location: {}", location);
|
||||
}, main);
|
||||
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
|
||||
} else
|
||||
logger.warn("No overrides are defined for Strongholds. Ender Signals will not work correctly.");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerChange(VillagerAcquireTradeEvent e) {
|
||||
if(!(e.getEntity() instanceof Villager))
|
||||
return;
|
||||
if(((Villager) e.getEntity()).getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||
logger.error("""
|
||||
.------------------------------------------------------------------------.
|
||||
| Prevented server crash by stopping Cartographer villager from |
|
||||
| spawning. Please upgrade to Paper, which has a StructureLocateEvent |
|
||||
| that fixes this issue at the source, and doesn't require us to do |
|
||||
| stupid band-aids. |
|
||||
|------------------------------------------------------------------------|
|
||||
""".strip());
|
||||
e.setCancelled(true); // Cancel leveling if the villager is a Cartographer, to prevent crashing server.
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerLevel(VillagerCareerChangeEvent e) {
|
||||
if(e.getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||
logger.error("""
|
||||
.------------------------------------------------------------------------.
|
||||
| Prevented server crash by stopping Cartographer villager from leveling |
|
||||
| up. Please upgrade to Paper, which has a StructureLocateEvent that |
|
||||
| fixes this issue at the source, and doesn't require us to do stupid |
|
||||
| band-aids. |
|
||||
|------------------------------------------------------------------------|
|
||||
""".strip());
|
||||
e.getEntity().setProfession(Villager.Profession.NITWIT); // Give villager new profession to prevent server crash.
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1;
|
||||
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VanillaBiomeProperties;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Holder;
|
||||
@@ -24,6 +22,9 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
@@ -31,6 +32,9 @@ import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
public class AwfulBukkitHacks {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AwfulBukkitHacks.class);
|
||||
|
||||
public static final Map<Holder<net.minecraft.world.level.biome.Biome>, Map<ResourceLocation,
|
||||
ProbabilityCollection<ConfiguredStructure>>>
|
||||
TERRA_BIOME_FERTILIZABLE_MAP = new HashMap<>();
|
||||
public static final Map<TagKey<Biome>, List<ResourceLocation>>
|
||||
TERRA_BIOME_TAG_MAP = new HashMap<>();
|
||||
|
||||
@@ -56,16 +60,19 @@ public class AwfulBukkitHacks {
|
||||
BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform);
|
||||
biomeRegistry.register(delegateKey, platform, Lifecycle.stable());
|
||||
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
|
||||
|
||||
|
||||
Map villagerMap = Reflection.VILLAGER_TYPE.getByBiome();
|
||||
|
||||
villagerMap.put(ResourceKey.create(Registry.BIOME_REGISTRY, delegateKey.location()),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), VillagerType.PLAINS));
|
||||
|
||||
TERRA_BIOME_FERTILIZABLE_MAP.put(Holder.direct(platform), vanillaBiomeProperties.getFertilizables());
|
||||
|
||||
for(ResourceLocation tag : vanillaBiomeProperties.getTags()) {
|
||||
TERRA_BIOME_TAG_MAP.getOrDefault(TagKey.create(Registry.BIOME_REGISTRY, tag), new ArrayList<>()).add(delegateKey.location());
|
||||
TERRA_BIOME_TAG_MAP.getOrDefault(TagKey.create(Registry.BIOME_REGISTRY, tag), new ArrayList<>()).add(
|
||||
delegateKey.location());
|
||||
}
|
||||
|
||||
|
||||
LOGGER.debug("Registered biome: " + delegateKey);
|
||||
} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockGrowEvent;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.util.FertilizableUtil;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class NMSInjectListener implements Listener {
|
||||
@@ -38,14 +48,30 @@ public class NMSInjectListener implements Listener {
|
||||
ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator();
|
||||
NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed());
|
||||
NMSChunkGeneratorDelegate custom = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed());
|
||||
|
||||
|
||||
custom.conf = vanilla.conf; // world config from Spigot
|
||||
|
||||
|
||||
serverWorld.getChunkSource().chunkMap.generator = custom;
|
||||
|
||||
|
||||
LOGGER.info("Successfully injected into world.");
|
||||
|
||||
|
||||
INJECT_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockGrow(BlockGrowEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Vector3Int pos = Vector3Int.of(block.getX(), block.getY(), block.getZ());
|
||||
ServerWorld world = BukkitAdapter.adapt(block.getWorld());
|
||||
event.setCancelled(FertilizableUtil.grow(world, new Random(), pos, ResourceLocation.tryParse(block.getType().getKey().asString())));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onStructureGow(StructureGrowEvent event) {
|
||||
Block block = event.getLocation().getBlock();
|
||||
Vector3Int pos = Vector3Int.of(block.getX(), block.getY(), block.getZ());
|
||||
ServerWorld world = BukkitAdapter.adapt(block.getWorld());
|
||||
event.setCancelled(FertilizableUtil.grow(world, new Random(), pos, ResourceLocation.tryParse(block.getType().getKey().asString())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,21 @@ import net.minecraft.world.level.biome.Biome.TemperatureModifier;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
|
||||
@Value("minecraft.fertilizables")
|
||||
@Default
|
||||
private Map<ResourceLocation, ProbabilityCollection<ConfiguredStructure>> fertilizables = Collections.emptyMap();
|
||||
|
||||
@Value("minecraft.tags")
|
||||
@Default
|
||||
private List<ResourceLocation> tags = null;
|
||||
@@ -98,6 +106,10 @@ public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
@Default
|
||||
private VillagerType villagerType = null;
|
||||
|
||||
public Map<ResourceLocation, ProbabilityCollection<ConfiguredStructure>> getFertilizables() {
|
||||
return fertilizables;
|
||||
}
|
||||
|
||||
public List<ResourceLocation> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_19_R1.util;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.bukkit.nms.v1_19_R1.AwfulBukkitHacks;
|
||||
|
||||
|
||||
public class FertilizableUtil {
|
||||
public static boolean grow(ServerWorld world, Random random, Vector3Int pos, ResourceLocation block) {
|
||||
Map<ResourceLocation, ProbabilityCollection<ConfiguredStructure>> fertilizables = AwfulBukkitHacks.TERRA_BIOME_FERTILIZABLE_MAP.get(world.getBiomeProvider().getBiome(pos, world.getSeed()));
|
||||
if (fertilizables != null) {
|
||||
ProbabilityCollection<ConfiguredStructure> probabilityCollection = fertilizables.get(block);
|
||||
if (probabilityCollection != null) {
|
||||
ConfiguredStructure structure = probabilityCollection.get(random);
|
||||
structure.getStructure().get(random).generate(pos, world, random, Rotation.NONE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
package com.dfsek.terra.mod.util;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.lifecycle.asm;
|
||||
|
||||
import com.dfsek.terra.mod.util.FertilizableUtil;
|
||||
|
||||
import net.gudenau.minecraft.asm.api.v1.Identifier;
|
||||
import net.gudenau.minecraft.asm.api.v1.Transformer;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -12,13 +10,13 @@ import org.objectweb.asm.tree.JumpInsnNode;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.dfsek.terra.lifecycle.util.ASMUtil;
|
||||
import com.dfsek.terra.lifecycle.util.LoaderUtil;
|
||||
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import com.dfsek.terra.mod.util.ASMUtil;
|
||||
import com.dfsek.terra.mod.util.FertilizableUtil;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.ACC_STATIC;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user