diff --git a/build.gradle b/build.gradle index eb3bf3474..62a4ffdbb 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:[5.1.39,)' + classpath 'net.minecraftforge.gradle:ForgeGradle:[5.1.39,5.2.0)' classpath "dev.vankka:gradle-plugin:1.2.1" } } @@ -49,20 +49,19 @@ ext { COREMODS_VERSION = '5.0.1' EVENTBUS_VERSION = '5.0.3' MODLAUNCHER_VERSION = '9.1.3' - SECUREJARHANDLER_VERSION = '1.0.3' + SECUREJARHANDLER_VERSION = '1.0.8' BOOTSTRAPLAUNCHER_VERSION = '1.0.0' - ASM_VERSION = '9.2' + ASM_VERSION = '9.5' INSTALLER_VERSION = '2.1.+' MIXIN_VERSION = '0.8.5' - JARJAR_VERSION = '0.3.0' + JARJAR_VERSION = '0.3.19' GIT_INFO = gradleutils.gitInfo - FORGE_VERSION = "40.2.2" + FORGE_VERSION = "40.2.4" VERSION = "1.18.2-$FORGE_VERSION" CATSERVER_VERSION = "1.18.2-" + gitVersion // FML_VERSION = gradleutils.getFilteredMCTagOffsetBranchVersion(true, 'FML', MC_VERSION) - SPECIAL_SOURCE = 'net.md-5:SpecialSource:1.10.0' BINPATCH_TOOL = 'net.minecraftforge:binarypatcher:1.0.12:fatjar' INSTALLER_TOOLS = 'net.minecraftforge:installertools:1.2.10' JAR_SPLITTER = 'net.minecraftforge:jarsplitter:1.1.4' @@ -195,6 +194,7 @@ def sharedDeps = { moduleonly "org.ow2.asm:asm-util:${ASM_VERSION}" moduleonly "org.ow2.asm:asm-analysis:${ASM_VERSION}" moduleonly "cpw.mods:bootstraplauncher:${BOOTSTRAPLAUNCHER_VERSION}" + moduleonly "net.minecraftforge:JarJarFileSystems:${JARJAR_VERSION}" installer "cpw.mods:securejarhandler:${SECUREJARHANDLER_VERSION}" installer "org.ow2.asm:asm:${ASM_VERSION}" @@ -220,7 +220,8 @@ def sharedDeps = { installer 'org.jline:jline-terminal-jansi:3.12.1' installer "org.spongepowered:mixin:${MIXIN_VERSION}" installer 'org.openjdk.nashorn:nashorn-core:15.3' - installer "net.minecraftforge:JarJar:${JARJAR_VERSION}" + installer "net.minecraftforge:JarJarSelector:${JARJAR_VERSION}" + installer "net.minecraftforge:JarJarMetadata:${JARJAR_VERSION}" // bukkit moduleonly 'commons-lang:commons-lang:2.6' @@ -247,12 +248,6 @@ def sharedDeps = { installer 'org.lwjgl:lwjgl-opengl:3.2.2' installer 'org.lwjgl:lwjgl-stb:3.2.2' */ - - autolibraries BIN_PATCHER - autolibraries SPECIAL_SOURCE - autolibraries INSTALLER_TOOLS - autolibraries JAR_SPLITTER - autolibraries FART } def sharedFmlonlyForge = { Project prj -> @@ -393,6 +388,7 @@ def sharedFmlonlyForge = { Project prj -> run.jvmArgs '--add-modules', 'ALL-MODULE-PATH' // Additions to these JVM module args should be mirrored to server_files/args.txt and other similar blocks in the buildscript run.jvmArgs '--add-opens', 'java.base/java.util.jar=cpw.mods.securejarhandler' + run.jvmArgs '--add-opens', 'java.base/java.lang.invoke=cpw.mods.securejarhandler' run.jvmArgs '--add-exports', 'java.base/sun.security.util=cpw.mods.securejarhandler' run.jvmArgs '--add-exports', 'jdk.naming.dns/com.sun.jndi.dns=java.naming' } @@ -606,6 +602,7 @@ project(':fmlonly') { '--add-modules', 'ALL-MODULE-PATH', // Additions to these JVM module args should be mirrored to server_files/args.txt and other similar blocks in the buildscript '--add-opens', 'java.base/java.util.jar=cpw.mods.securejarhandler', + '--add-opens', 'java.base/java.lang.invoke=cpw.mods.securejarhandler', '--add-exports', 'java.base/sun.security.util=cpw.mods.securejarhandler', '--add-exports', 'jdk.naming.dns/com.sun.jndi.dns=java.naming' ] @@ -1258,6 +1255,7 @@ project(':forge') { '--add-modules', 'ALL-MODULE-PATH', // Additions to these JVM module args should be mirrored to server_files/args.txt and other similar blocks in the buildscript '--add-opens', 'java.base/java.util.jar=cpw.mods.securejarhandler', + '--add-opens', 'java.base/java.lang.invoke=cpw.mods.securejarhandler', '--add-exports', 'java.base/sun.security.util=cpw.mods.securejarhandler', '--add-exports', 'jdk.naming.dns/com.sun.jndi.dns=java.naming' ] diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 19adbbe7a..a954e0075 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -3,8 +3,8 @@ repositories { mavenCentral() } dependencies { - implementation 'org.ow2.asm:asm:9.1' - implementation 'org.ow2.asm:asm-tree:9.1' + implementation 'org.ow2.asm:asm:9.5' + implementation 'org.ow2.asm:asm-tree:9.5' implementation 'net.minecraftforge:srgutils:0.4.+' implementation 'commons-io:commons-io:2.8.0' implementation 'com.google.code.gson:gson:2.10' diff --git a/fmlloader/build.gradle b/fmlloader/build.gradle index bdd5699a5..67414c808 100644 --- a/fmlloader/build.gradle +++ b/fmlloader/build.gradle @@ -26,7 +26,8 @@ dependencies { api('com.electronwill.night-config:toml:3.6.4') api('cpw.mods:modlauncher:9.0.+') api('net.minecraftforge:coremods:5.0.+') - api "net.minecraftforge:JarJar:${JARJAR_VERSION}" + api "net.minecraftforge:JarJarSelector:${JARJAR_VERSION}" + api "net.minecraftforge:JarJarMetadata:${JARJAR_VERSION}" implementation("cpw.mods:securejarhandler:${SECUREJARHANDLER_VERSION}") implementation('org.apache.logging.log4j:log4j-core:2.17.0') annotationProcessor('org.apache.logging.log4j:log4j-core:2.17.0') diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java index 8cf7a832e..4b5254d32 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/JarInJarDependencyLocator.java @@ -5,6 +5,7 @@ package net.minecraftforge.fml.loading.moddiscovery; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import net.minecraftforge.fml.loading.EarlyLoadingException; import net.minecraftforge.forgespi.language.IModInfo; @@ -16,10 +17,15 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.jetbrains.annotations.NotNull; +import java.net.URI; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Path; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -34,20 +40,16 @@ public String name() } @Override - public List scanMods(final Iterable loadedMods) { + public List scanMods(final Iterable loadedMods) + { final List sources = Lists.newArrayList(); loadedMods.forEach(sources::add); - final List dependenciesToLoad = JarSelector.detectAndSelect( - sources, - this::loadResourceFromModFile, - this::loadModFileFrom, - this::identifyMod, - this::exception - ); + final List dependenciesToLoad = JarSelector.detectAndSelect(sources, this::loadResourceFromModFile, this::loadModFileFrom, this::identifyMod, this::exception); - if (dependenciesToLoad.isEmpty()) { + if (dependenciesToLoad.isEmpty()) + { LOGGER.info("No dependencies to load found. Skipping!"); return Collections.emptyList(); } @@ -68,35 +70,66 @@ protected String getDefaultJarModType() return IModFile.Type.GAMELIBRARY.name(); } + @SuppressWarnings("resource") + @Override + protected Optional loadModFileFrom(final IModFile file, final Path path) + { + try + { + final Path pathInModFile = file.findResource(path.toString()); + final URI filePathUri = new URI("jij:" + (pathInModFile.toAbsolutePath().toUri().getRawSchemeSpecificPart())).normalize(); + final Map outerFsArgs = ImmutableMap.of("packagePath", pathInModFile); + final FileSystem zipFS = FileSystems.newFileSystem(filePathUri, outerFsArgs); + final Path pathInFS = zipFS.getPath("/"); + return createMod(pathInFS); + } + catch (Exception e) + { + LOGGER.error("Failed to load mod file {} from {}", path, file.getFileName()); + + throw new RuntimeException("Failed to load mod file " + file.getFileName(), e); + } + } + protected EarlyLoadingException exception(Collection> failedDependencies) { final List errors = failedDependencies.stream() - .filter(entry -> !entry.sources().isEmpty()) //Should never be the case, but just to be sure - .map(entry -> new EarlyLoadingException.ExceptionData( - getErrorTranslationKey(entry), - entry.identifier().group() + ":" + entry.identifier().artifact(), - entry.sources() - .stream() - .flatMap(this::getModWithVersionRangeStream) - .map(this::formatError) - .collect(Collectors.joining(", ")))).toList(); + .filter(entry -> !entry.sources().isEmpty()) //Should never be the case, but just to be sure + .map(this::buildExceptionData) + .toList(); return new EarlyLoadingException(failedDependencies.size() + " Dependency restrictions were not met.", null, errors); } + @NotNull + private EarlyLoadingException.ExceptionData buildExceptionData(final JarSelector.ResolutionFailureInformation entry) + { + return new EarlyLoadingException.ExceptionData( + getErrorTranslationKey(entry), + entry.identifier().group() + ":" + entry.identifier().artifact(), + entry.sources() + .stream() + .flatMap(this::getModWithVersionRangeStream) + .map(this::formatError) + .collect(Collectors.joining(", ")) + ); + } + @NotNull private String getErrorTranslationKey(final JarSelector.ResolutionFailureInformation entry) { - return entry.failureReason() == JarSelector.FailureReason.VERSION_RESOLUTION_FAILED - ? "fml.dependencyloading.conflictingdependencies" - : "fml.dependencyloading.mismatchedcontaineddependencies"; + return entry.failureReason() == JarSelector.FailureReason.VERSION_RESOLUTION_FAILED ? + "fml.dependencyloading.conflictingdependencies" : + "fml.dependencyloading.mismatchedcontaineddependencies"; } @NotNull private Stream getModWithVersionRangeStream(final JarSelector.SourceWithRequestedVersionRange file) { - return file.sources().stream().map(IModFile::getModFileInfo) + return file.sources() + .stream() + .map(IModFile::getModFileInfo) .flatMap(modFileInfo -> modFileInfo.getMods().stream()) .map(modInfo -> new ModWithVersionRange(modInfo, file.requestedVersionRange(), file.includedVersion())); } @@ -104,10 +137,20 @@ private Stream getModWithVersionRangeStream(final JarSelect @NotNull private String formatError(final ModWithVersionRange modWithVersionRange) { - return "\u00a7e" + modWithVersionRange.modInfo().getModId() + "\u00a7r - \u00a74" - + modWithVersionRange.versionRange().toString() + "\u00a74 - \u00a72" - + modWithVersionRange.artifactVersion().toString() + "\u00a72"; + return "\u00a7e" + modWithVersionRange.modInfo().getModId() + "\u00a7r - \u00a74" + modWithVersionRange.versionRange().toString() + "\u00a74 - \u00a72" + modWithVersionRange.artifactVersion().toString() + "\u00a72"; + } + + @Override + protected String identifyMod(final IModFile modFile) + { + if (modFile.getModFileInfo() == null || modFile.getModInfos().isEmpty()) + { + return modFile.getFileName(); + } + + return modFile.getModInfos().stream().map(IModInfo::getModId).collect(Collectors.joining()); } - private record ModWithVersionRange(IModInfo modInfo, VersionRange versionRange, ArtifactVersion artifactVersion) {} + private record ModWithVersionRange(IModInfo modInfo, VersionRange versionRange, ArtifactVersion artifactVersion) + {} } diff --git a/foxlaunch/src/main/java/foxlaunch/DataManager.java b/foxlaunch/src/main/java/foxlaunch/DataManager.java index 65dbc945e..ea4cf60d4 100644 --- a/foxlaunch/src/main/java/foxlaunch/DataManager.java +++ b/foxlaunch/src/main/java/foxlaunch/DataManager.java @@ -52,6 +52,7 @@ public static void setup() { librariesWithoutLaunchMap.put("minecraft_server.1.18.2.jar", new File("foxlaunch-data/")); librariesWithoutLaunchMap.put("commons-lang-2.6.jar", new File("libraries/commons-lang/commons-lang/2.6/")); librariesMap.put("bootstraplauncher-1.0.0.jar", new File("libraries/cpw/mods/bootstraplauncher/1.0.0/")); + librariesMap.put("JarJarFileSystems-0.3.19.jar", new File("libraries/net/minecraftforge/JarJarFileSystems/0.3.19/")); versionData.put("minecraft", Objects.requireNonNull(serverJar.getManifest().getAttributes("net/minecraftforge/versions/mcp/").getValue(Attributes.Name.SPECIFICATION_VERSION))); versionData.put("mcp", Objects.requireNonNull(serverJar.getManifest().getAttributes("net/minecraftforge/versions/mcp/").getValue(Attributes.Name.IMPLEMENTATION_VERSION))); diff --git a/foxlaunch/src/main/java/foxlaunch/FoxServerLauncher.java b/foxlaunch/src/main/java/foxlaunch/FoxServerLauncher.java index 3928b3855..baccf021e 100644 --- a/foxlaunch/src/main/java/foxlaunch/FoxServerLauncher.java +++ b/foxlaunch/src/main/java/foxlaunch/FoxServerLauncher.java @@ -36,7 +36,7 @@ public static void main(String[] args) throws Throwable { LegacyLauncher.loadJars(); System.setProperty("java.net.preferIPv6Addresses", "system"); - System.setProperty("ignoreList", "bootstraplauncher-1.0.0.jar,securejarhandler-1.0.3.jar,asm-commons-9.2.jar,asm-util-9.2.jar,asm-analysis-9.2.jar,asm-tree-9.2.jar,asm-9.2.jar"); + System.setProperty("ignoreList", "bootstraplauncher-1.0.0.jar,securejarhandler-1.0.8.jar,asm-commons-9.5.jar,asm-util-9.5.jar,asm-analysis-9.5.jar,asm-tree-9.5.jar,asm-9.5.jar,JarJarFileSystems-0.3.19.jar"); System.setProperty("libraryDirectory", "libraries"); System.setProperty("legacyClassPath", String.join(Utils.isWindows() ? ";" : ":", DataManager.getLibrariesMap().entrySet().stream().map(entry -> entry.getValue().getAbsolutePath() + "/" + entry.getKey()).toArray(String[]::new))); diff --git a/foxlaunch/src/main/java/foxlaunch/legacy/InstallTool.java b/foxlaunch/src/main/java/foxlaunch/legacy/InstallTool.java index 0734101cd..0f745e564 100644 --- a/foxlaunch/src/main/java/foxlaunch/legacy/InstallTool.java +++ b/foxlaunch/src/main/java/foxlaunch/legacy/InstallTool.java @@ -27,10 +27,10 @@ public static boolean install(String minecraftVersion, String mcpVersion, String Utils.pathToURL("libraries/net/md-5/SpecialSource/1.10.0/SpecialSource-1.10.0.jar"), Utils.pathToURL("libraries/net/sf/jopt-simple/jopt-simple/5.0.4/jopt-simple-5.0.4.jar"), Utils.pathToURL("libraries/com/google/guava/guava/31.0.1-jre/guava-31.0.1-jre.jar"), - Utils.pathToURL("libraries/org/ow2/asm/asm-commons/9.2/asm-commons-9.2.jar"), - Utils.pathToURL("libraries/org/ow2/asm/asm-analysis/9.2/asm-analysis-9.2.jar"), - Utils.pathToURL("libraries/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar"), - Utils.pathToURL("libraries/org/ow2/asm/asm/9.2/asm-9.2.jar") + Utils.pathToURL("libraries/org/ow2/asm/asm-commons/9.5/asm-commons-9.5.jar"), + Utils.pathToURL("libraries/org/ow2/asm/asm-analysis/9.5/asm-analysis-9.5.jar"), + Utils.pathToURL("libraries/org/ow2/asm/asm-tree/9.5/asm-tree-9.5.jar"), + Utils.pathToURL("libraries/org/ow2/asm/asm/9.5/asm-9.5.jar") }; URL[] libJarSplitter = new URL[] { @@ -43,10 +43,10 @@ public static boolean install(String minecraftVersion, String mcpVersion, String Utils.pathToURL("foxlaunch-libs/ForgeAutoRenamingTool-0.1.22.jar"), Utils.pathToURL("foxlaunch-libs/srgutils-0.4.11.jar"), Utils.pathToURL("libraries/net/sf/jopt-simple/jopt-simple/5.0.4/jopt-simple-5.0.4.jar"), - Utils.pathToURL("libraries/org/ow2/asm/asm-commons/9.2/asm-commons-9.2.jar"), - Utils.pathToURL("libraries/org/ow2/asm/asm-analysis/9.2/asm-analysis-9.2.jar"), - Utils.pathToURL("libraries/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar"), - Utils.pathToURL("libraries/org/ow2/asm/asm/9.2/asm-9.2.jar") + Utils.pathToURL("libraries/org/ow2/asm/asm-commons/9.5/asm-commons-9.5.jar"), + Utils.pathToURL("libraries/org/ow2/asm/asm-analysis/9.5/asm-analysis-9.5.jar"), + Utils.pathToURL("libraries/org/ow2/asm/asm-tree/9.5/asm-tree-9.5.jar"), + Utils.pathToURL("libraries/org/ow2/asm/asm/9.5/asm-9.5.jar") }; URL[] libBinaryPatcher = new URL[] { diff --git a/foxlaunch/src/main/java/foxlaunch/legacy/LegacyLauncher.java b/foxlaunch/src/main/java/foxlaunch/legacy/LegacyLauncher.java index ac88ec0e1..189b2854b 100644 --- a/foxlaunch/src/main/java/foxlaunch/legacy/LegacyLauncher.java +++ b/foxlaunch/src/main/java/foxlaunch/legacy/LegacyLauncher.java @@ -32,15 +32,19 @@ public static boolean setup() { } public static void loadJars() throws Exception { - JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm/9.2/asm-9.2.jar"); - JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar"); - JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm-analysis/9.2/asm-analysis-9.2.jar"); - JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm-util/9.2/asm-util-9.2.jar"); - JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm-commons/9.2/asm-commons-9.2.jar"); - JVMHack.addModuleDynamic("libraries/cpw/mods/securejarhandler/1.0.3/securejarhandler-1.0.3.jar"); + JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm/9.5/asm-9.5.jar"); + JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm-tree/9.5/asm-tree-9.5.jar"); + JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm-analysis/9.5/asm-analysis-9.5.jar"); + JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm-util/9.5/asm-util-9.5.jar"); + JVMHack.addModuleDynamic("libraries/org/ow2/asm/asm-commons/9.5/asm-commons-9.5.jar"); + JVMHack.addModuleDynamic("libraries/cpw/mods/securejarhandler/1.0.8/securejarhandler-1.0.8.jar"); JVMHack.addModuleDynamic("libraries/cpw/mods/bootstraplauncher/1.0.0/bootstraplauncher-1.0.0.jar"); + JVMHack.addModuleDynamic("libraries/net/minecraftforge/JarJarFileSystems/0.3.19/JarJarFileSystems-0.3.19.jar"); JVMHack.addModuleOptionDynamic("addExportsToAllUnnamed", "cpw.mods.bootstraplauncher", "cpw.mods.bootstraplauncher", null); + JVMHack.addModuleOptionDynamic("addOpens", "java.base", "java.util.jar", "cpw.mods.securejarhandler"); + JVMHack.addModuleOptionDynamic("addOpens", "java.base", "java.lang.invoke", "cpw.mods.securejarhandler"); + JVMHack.addModuleOptionDynamic("addExports", "java.base", "sun.security.util", "cpw.mods.securejarhandler"); JarLoader.loadJar(new File("libraries/commons-lang/commons-lang/2.6/commons-lang-2.6.jar")); } diff --git a/patches/minecraft/net/minecraft/core/dispenser/DefaultDispenseItemBehavior.java.patch b/patches/minecraft/net/minecraft/core/dispenser/DefaultDispenseItemBehavior.java.patch index a714af9e7..37666e4ff 100644 --- a/patches/minecraft/net/minecraft/core/dispenser/DefaultDispenseItemBehavior.java.patch +++ b/patches/minecraft/net/minecraft/core/dispenser/DefaultDispenseItemBehavior.java.patch @@ -1,15 +1,6 @@ --- a/net/minecraft/core/dispenser/DefaultDispenseItemBehavior.java +++ b/net/minecraft/core/dispenser/DefaultDispenseItemBehavior.java -@@ -1,14 +_,28 @@ - package net.minecraft.core.dispenser; - --import net.minecraft.core.BlockSource; --import net.minecraft.core.Direction; --import net.minecraft.core.Position; -+import catserver.server.CatServerCaptures; -+import net.minecraft.core.*; -+import net.minecraft.server.level.ServerLevel; - import net.minecraft.world.entity.item.ItemEntity; +@@ -7,8 +_,22 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.DispenserBlock; @@ -32,7 +23,7 @@ public final ItemStack m_6115_(BlockSource p_123391_, ItemStack p_123392_) { ItemStack itemstack = this.m_7498_(p_123391_, p_123392_); this.m_6823_(p_123391_); -@@ -18,13 +_,28 @@ +@@ -18,16 +_,25 @@ protected ItemStack m_7498_(BlockSource p_123385_, ItemStack p_123386_) { Direction direction = p_123385_.m_6414_().m_61143_(DispenserBlock.f_52659_); @@ -47,23 +38,23 @@ return p_123386_; } -+ // CatServer start public static void m_123378_(Level p_123379_, ItemStack p_123380_, int p_123381_, Direction p_123382_, Position p_123383_) { -+ internalSpawnItem(p_123379_, p_123380_, p_123381_, p_123382_, new BlockSourceImpl((ServerLevel) p_123379_, new BlockPos(p_123383_)), p_123383_); -+ } -+ -+ public static boolean spawnItemCb(Level level, ItemStack itemStack, int i, Direction direction, BlockSource source, boolean dropper) { -+ CatServerCaptures.getCatServerCaptures().captureDropper(dropper); -+ return internalSpawnItem(level, itemStack, i, direction, source, DispenserBlock.m_52720_(source)); +- double d0 = p_123383_.m_7096_(); +- double d1 = p_123383_.m_7098_(); +- double d2 = p_123383_.m_7094_(); ++ spawnItemCb(p_123379_, p_123380_, p_123381_, p_123382_, new net.minecraft.core.BlockSourceImpl((net.minecraft.server.level.ServerLevel) p_123379_, new net.minecraft.core.BlockPos(p_123383_)), false); // CatServer + } + -+ private static boolean internalSpawnItem(Level p_123379_, ItemStack p_123380_, int p_123381_, Direction p_123382_, BlockSource blockSource, Position p_123383_) { ++ public static boolean spawnItemCb(Level p_123379_, ItemStack p_123380_, int p_123381_, Direction p_123382_, BlockSource blockSource, boolean dropper) { + if (p_123380_.m_41619_()) return true; + // CraftBukkit end - double d0 = p_123383_.m_7096_(); - double d1 = p_123383_.m_7098_(); - double d2 = p_123383_.m_7094_(); -@@ -37,8 +_,44 @@ ++ double d0 = blockSource.m_7096_(); ++ double d1 = blockSource.m_7098_(); ++ double d2 = blockSource.m_7094_(); + if (p_123382_.m_122434_() == Direction.Axis.Y) { + d1 -= 0.125D; + } else { +@@ -37,7 +_,40 @@ ItemEntity itementity = new ItemEntity(p_123379_, d0, d1, d2, p_123380_); double d3 = p_123379_.f_46441_.nextDouble() * 0.1D + 0.2D; itementity.m_20334_(p_123379_.f_46441_.nextGaussian() * (double)0.0075F * (double)p_123381_ + (double)p_123382_.m_122429_() * d3, p_123379_.f_46441_.nextGaussian() * (double)0.0075F * (double)p_123381_ + (double)0.2F, p_123379_.f_46441_.nextGaussian() * (double)0.0075F * (double)p_123381_ + (double)p_123382_.m_122431_() * d3); @@ -85,8 +76,6 @@ + itementity.m_32045_(CraftItemStack.asNMSCopy(event.getItem())); + itementity.m_20256_(CraftVector.toNMS(event.getVelocity())); + -+ boolean dropper = CatServerCaptures.getCatServerCaptures().getCaptureDropper(); // CatServer -+ + if (!dropper && !event.getItem().getType().equals(craftItem.getType())) { + // Chain to handler for new item + ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); @@ -104,7 +93,5 @@ + return true; + //CraftBukkit end } -+ // CatServer end protected void m_6823_(BlockSource p_123384_) { - p_123384_.m_7727_().m_46796_(1000, p_123384_.m_7961_(), 0); diff --git a/patches/minecraft/net/minecraft/server/level/ChunkMap.java.patch b/patches/minecraft/net/minecraft/server/level/ChunkMap.java.patch index 3ba50ff48..951721dd9 100644 --- a/patches/minecraft/net/minecraft/server/level/ChunkMap.java.patch +++ b/patches/minecraft/net/minecraft/server/level/ChunkMap.java.patch @@ -1,13 +1,5 @@ --- a/net/minecraft/server/level/ChunkMap.java +++ b/net/minecraft/server/level/ChunkMap.java -@@ -1,5 +_,7 @@ - package net.minecraft.server.level; - -+import catserver.server.CatServerCaptures; -+import catserver.server.utils.CatServerCallbackExecutor; - import com.google.common.collect.ImmutableList; - import com.google.common.collect.Iterables; - import com.google.common.collect.Lists; @@ -108,7 +_,7 @@ public static final int f_140127_ = 33 + ChunkStatus.m_62421_(); public static final int f_143033_ = 31; @@ -36,7 +28,7 @@ private final Long2LongMap f_202981_ = new Long2LongOpenHashMap(); private final Queue f_140125_ = Queues.newConcurrentLinkedQueue(); int f_140126_; -+ public final CatServerCallbackExecutor callbackExecutor = new CatServerCallbackExecutor(); // CatServer ++ public final catserver.server.utils.CatServerCallbackExecutor callbackExecutor = new catserver.server.utils.CatServerCallbackExecutor(); // CatServer public ChunkMap(ServerLevel p_143040_, LevelStorageSource.LevelStorageAccess p_143041_, DataFixer p_143042_, StructureManager p_143043_, Executor p_143044_, BlockableEventLoop p_143045_, LightChunkGetter p_143046_, ChunkGenerator p_143047_, ChunkProgressListener p_143048_, ChunkStatusUpdateListener p_143049_, Supplier p_143050_, int p_143051_, boolean p_143052_) { super(p_143041_.m_197394_(p_143040_.m_46472_()).resolve("region"), p_143042_, p_143052_); @@ -136,30 +128,23 @@ builder.add(serverplayer); } } -@@ -925,14 +_,22 @@ - } +@@ -926,11 +_,15 @@ } -+ // CatServer start -+ private boolean playerIsCloseEnoughForSpawning(ServerPlayer p_183752_, ChunkPos p_183753_, double range) { // Spigot -+ CatServerCaptures.getCatServerCaptures().captureBlockRange(range); -+ return this.m_183751_(p_183752_, p_183753_); + private boolean m_183751_(ServerPlayer p_183752_, ChunkPos p_183753_) { ++ return this.playerIsCloseEnoughForSpawning(p_183752_, p_183753_, 16384.0D); // CatServer + } + - private boolean m_183751_(ServerPlayer p_183752_, ChunkPos p_183753_) { ++ private boolean playerIsCloseEnoughForSpawning(ServerPlayer p_183752_, ChunkPos p_183753_, double range) { // Spigot if (p_183752_.m_5833_()) { return false; } else { -+ var range = CatServerCaptures.getCatServerCaptures().getCaptureBlockRange(); // CatServer double d0 = m_140226_(p_183753_, p_183752_); - return d0 < 16384.0D; + return d0 < range; } } -+ // CatServer end - private boolean m_140329_(ServerPlayer p_140330_) { - return p_140330_.m_5833_() && !this.f_140133_.m_46469_().m_46207_(GameRules.f_46146_); @@ -1070,9 +_,10 @@ } diff --git a/patches/minecraft/net/minecraft/server/level/ServerEntity.java.patch b/patches/minecraft/net/minecraft/server/level/ServerEntity.java.patch index 8a059a7d1..ed00caf25 100644 --- a/patches/minecraft/net/minecraft/server/level/ServerEntity.java.patch +++ b/patches/minecraft/net/minecraft/server/level/ServerEntity.java.patch @@ -145,7 +145,7 @@ this.f_8510_.f_19864_ = false; } -@@ -189,16 +_,27 @@ +@@ -189,16 +_,25 @@ public void m_8534_(ServerPlayer p_8535_) { this.f_8510_.m_6452_(p_8535_); p_8535_.f_8906_.m_141995_(new ClientboundRemoveEntitiesPacket(this.f_8510_.m_142049_())); @@ -153,15 +153,14 @@ } public void m_8541_(ServerPlayer p_8542_) { -+ CatServerCaptures.getCatServerCaptures().captureServerPlayer(p_8542_); // CatServer - this.m_8536_(p_8542_.f_8906_::m_141995_); +- this.m_8536_(p_8542_.f_8906_::m_141995_); ++ this.sendPairingData(p_8542_.f_8906_::m_141995_, p_8542_); // CatServer this.f_8510_.m_6457_(p_8542_); + net.minecraftforge.event.ForgeEventFactory.onStartEntityTracking(this.f_8510_, p_8542_); } public void m_8536_(Consumer> p_8537_) { -+ var player = CatServerCaptures.getCatServerCaptures().getCaptureServerPlayer(); -+ this.sendPairingData(p_8537_, player); ++ this.sendPairingData(p_8537_, null); // CatServer + } + + public void sendPairingData(Consumer> p_8537_, ServerPlayer entityplayer) { // CraftBukkit - add player @@ -180,7 +179,7 @@ Collection collection = ((LivingEntity)this.f_8510_).m_21204_().m_22170_(); + + // CraftBukkit start - If sending own attributes send scaled health instead of current maximum health -+ if (this.f_8510_.m_142049_() == entityplayer.m_142049_()) { ++ if (entityplayer != null && this.f_8510_.m_142049_() == entityplayer.m_142049_()) { // CatServer - Check player is null + ((ServerPlayer) this.f_8510_).getBukkitEntity().injectScaledMaxHealth(collection, false); + } + // CraftBukkit end diff --git a/patches/minecraft/net/minecraft/server/level/ServerLevel.java.patch b/patches/minecraft/net/minecraft/server/level/ServerLevel.java.patch index 6b8ba9f11..09e730cf6 100644 --- a/patches/minecraft/net/minecraft/server/level/ServerLevel.java.patch +++ b/patches/minecraft/net/minecraft/server/level/ServerLevel.java.patch @@ -1,67 +1,9 @@ --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1,5 +_,7 @@ - package net.minecraft.server.level; - -+import catserver.server.CatServerCaptures; -+import catserver.server.level.CustomDerivedLevelData; - import com.google.common.annotations.VisibleForTesting; - import com.google.common.collect.Lists; - import com.mojang.datafixers.DataFixer; -@@ -14,6 +_,7 @@ - import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; - import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; - import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry; -+ - import java.io.IOException; - import java.io.Writer; - import java.nio.file.Files; -@@ -26,6 +_,7 @@ - import java.util.Set; - import java.util.UUID; - import java.util.concurrent.Executor; -+import java.util.concurrent.atomic.AtomicReference; - import java.util.function.BooleanSupplier; - import java.util.function.Function; - import java.util.function.Predicate; -@@ -33,6 +_,7 @@ - import java.util.stream.Stream; - import javax.annotation.Nonnull; - import javax.annotation.Nullable; -+ - import net.minecraft.CrashReport; - import net.minecraft.Util; - import net.minecraft.core.BlockPos; -@@ -71,6 +_,7 @@ - import net.minecraft.util.ProgressListener; - import net.minecraft.util.Unit; - import net.minecraft.util.profiling.ProfilerFiller; -+import net.minecraft.world.Container; - import net.minecraft.world.DifficultyInstance; - import net.minecraft.world.damagesource.DamageSource; - import net.minecraft.world.entity.Entity; -@@ -87,7 +_,6 @@ - import net.minecraft.world.entity.animal.Animal; - import net.minecraft.world.entity.animal.WaterAnimal; - import net.minecraft.world.entity.animal.horse.SkeletonHorse; --import net.minecraft.world.entity.boss.EnderDragonPart; - import net.minecraft.world.entity.boss.enderdragon.EnderDragon; - import net.minecraft.world.entity.npc.Npc; - import net.minecraft.world.entity.player.Player; -@@ -136,1408 +_,1800 @@ - import net.minecraft.world.level.portal.PortalForcer; - import net.minecraft.world.level.saveddata.maps.MapIndex; - import net.minecraft.world.level.saveddata.maps.MapItemSavedData; --import net.minecraft.world.level.storage.DimensionDataStorage; --import net.minecraft.world.level.storage.LevelStorageSource; --import net.minecraft.world.level.storage.ServerLevelData; -+import net.minecraft.world.level.storage.*; - import net.minecraft.world.phys.AABB; - import net.minecraft.world.phys.Vec3; - import net.minecraft.world.phys.shapes.BooleanOp; - import net.minecraft.world.phys.shapes.Shapes; - import net.minecraft.world.phys.shapes.VoxelShape; +@@ -147,1397 +_,1795 @@ import net.minecraft.world.ticks.LevelTicks; + import org.slf4j.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.WeatherType; +import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; @@ -71,8 +13,7 @@ +import org.bukkit.event.server.MapInitializeEvent; +import org.bukkit.event.weather.LightningStrikeEvent; +import org.bukkit.event.world.TimeSkipEvent; - import org.slf4j.Logger; - ++ public class ServerLevel extends Level implements WorldGenLevel { - public static final BlockPos f_8562_ = new BlockPos(100, 50, 0); - private static final int f_184049_ = 12000; @@ -216,7 +157,7 @@ + private final boolean f_8561_; + private net.minecraftforge.common.util.WorldCapabilityData capabilityData; + // CraftBukkit start -+ public PrimaryLevelData worldDataServer; ++ public net.minecraft.world.level.storage.PrimaryLevelData worldDataServer; + private int tickPosition; + public final LevelStorageSource.LevelStorageAccess convertable; + public final UUID uuid; @@ -232,10 +173,10 @@ + this.pvpMode = p_203762_.m_129799_(); + this.uuid = WorldUUID.getUUID(p_203762_.f_129744_.m_197394_(p_203766_).toFile()); // CatServer + // CatServer start -+ if (p_203765_ instanceof PrimaryLevelData primaryLevelData) { ++ if (p_203765_ instanceof net.minecraft.world.level.storage.PrimaryLevelData primaryLevelData) { + this.worldDataServer = primaryLevelData; -+ } else if (p_203765_ instanceof DerivedLevelData derivedLevelData) { -+ this.worldDataServer = CustomDerivedLevelData.wrap(derivedLevelData); ++ } else if (p_203765_ instanceof net.minecraft.world.level.storage.DerivedLevelData derivedLevelData) { ++ this.worldDataServer = catserver.server.level.CustomDerivedLevelData.wrap(derivedLevelData); + } + if (generator != null) { + p_203769_ = new org.bukkit.craftbukkit.v1_18_R2.generator.CustomChunkGenerator(this, p_203769_, generator); @@ -291,10 +232,10 @@ + this.pvpMode = p_203762_.m_129799_(); + this.uuid = WorldUUID.getUUID(p_203762_.f_129744_.m_197394_(p_203766_).toFile()); // CatServer + // CatServer start -+ if (p_203765_ instanceof PrimaryLevelData primaryLevelData) { ++ if (p_203765_ instanceof net.minecraft.world.level.storage.PrimaryLevelData primaryLevelData) { + this.worldDataServer = primaryLevelData; -+ } else if (p_203765_ instanceof DerivedLevelData derivedLevelData) { -+ this.worldDataServer = CustomDerivedLevelData.wrap(derivedLevelData); ++ } else if (p_203765_ instanceof net.minecraft.world.level.storage.DerivedLevelData derivedLevelData) { ++ this.worldDataServer = catserver.server.level.CustomDerivedLevelData.wrap(derivedLevelData); + } + if (generator != null) { + p_203769_ = new org.bukkit.craftbukkit.v1_18_R2.generator.CustomChunkGenerator(this, p_203769_, generator); @@ -1685,39 +1626,34 @@ + } + + // CatServer start -+ public boolean addFreshEntity(Entity p_8837_, CreatureSpawnEvent.SpawnReason reason) { -+ CatServerCaptures.getCatServerCaptures().captureSpawnReason(reason); -+ return this.m_7967_(p_8837_); -+ } -+ + public boolean m_7967_(Entity p_8837_) { -+ var reason = CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); -+ if (reason == null) reason = CreatureSpawnEvent.SpawnReason.DEFAULT; -+ return this.addEntity(p_8837_, reason); // CraftBukkit ++ CreatureSpawnEvent.SpawnReason reason = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); ++ return this.addFreshEntity(p_8837_, reason == null ? CreatureSpawnEvent.SpawnReason.DEFAULT : reason); + } + -+ public boolean addWithUUID(Entity p_8848_, CreatureSpawnEvent.SpawnReason reason) { -+ CatServerCaptures.getCatServerCaptures().captureSpawnReason(reason); -+ return this.m_8847_(p_8848_); ++ public boolean addFreshEntity(Entity p_8837_, CreatureSpawnEvent.SpawnReason reason) { ++ return this.addEntity(p_8837_, reason); + } + + public boolean m_8847_(Entity p_8848_) { -+ var reason = CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); -+ if (reason == null) reason = CreatureSpawnEvent.SpawnReason.DEFAULT; -+ return this.addEntity(p_8848_, reason); // CraftBukkit ++ CreatureSpawnEvent.SpawnReason reason = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); ++ return this.addEntity(p_8848_, reason == null ? CreatureSpawnEvent.SpawnReason.DEFAULT : reason); + } + -+ public void addDuringTeleport(Entity p_143335_, CreatureSpawnEvent.SpawnReason reason) { -+ // CraftBukkit start ++ public boolean addWithUUID(Entity p_8848_, CreatureSpawnEvent.SpawnReason reason) { ++ return this.addEntity(p_8848_, reason); ++ } ++ // CatServer end ++ ++ public void m_143334_(Entity p_143335_) { ++ CreatureSpawnEvent.SpawnReason reason = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); + // SPIGOT-6415: Don't call spawn event for entities which travel trough worlds, + // since it is only an implementation detail, that a new entity is created when + // they are traveling between worlds. -+ CatServerCaptures.getCatServerCaptures().captureSpawnReason(reason); -+ this.m_143334_(p_143335_); ++ this.addDuringTeleport(p_143335_, reason == null ? null : reason); + } + -+ public void m_143334_(Entity p_143335_) { -+ var reason = CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); ++ public void addDuringTeleport(Entity p_143335_, CreatureSpawnEvent.SpawnReason reason) { + this.addEntity(p_143335_, reason); + } + // CatServer end @@ -1808,23 +1744,25 @@ + } + + // CatServer start -+ private AtomicReference catserver$addEntityReason = new AtomicReference<>(); -+ -+ public boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) { -+ this.catserver$addEntityReason.set(spawnReason); -+ return this.m_8872_(entity); -+ } -+ ++ // Must use CatServerCaptures here to compatible with mixin inject + private boolean m_8872_(Entity p_8873_) { ++ CreatureSpawnEvent.SpawnReason spawnReason = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); ++ // CatServer start - Thread safety check ++ if (!f_8548_.m_18695_()) { ++ catserver.server.CatServer.LOGGER.debug("Async add entity captured!", new RuntimeException()); ++ f_8548_.processQueue.add(() -> addEntity(p_8873_, spawnReason)); ++ return true; ++ } ++ // CatServer end + if (p_8873_.m_146910_()) { -+ //LOGGER.warn("Tried to add entity {} but it was marked as removed already", (Object)EntityType.getKey(p_8873_.getType())); ++ // LOGGER.warn("Tried to add entity {} but it was marked as removed already", (Object)EntityType.getKey(p_8873_.getType())); + return false; + } else { + // SPIGOT-6415: Don't call spawn event when reason is null. For example when an entity teleports to a new world. -+ var spawnReason = this.catserver$addEntityReason.getAndSet(null); // CatServer + if (spawnReason != null && !CraftEventFactory.doEntityAddEventCalling(this, p_8873_, spawnReason)) { + return false; + } ++ // CraftBukkit end + if (this.f_143244_.m_157533_(p_8873_)) { + p_8873_.onAddedToWorld(); + return true; @@ -1833,33 +1771,39 @@ + } + } + } -+ // CatServer end -+ -+ // CatServer start -+ private CreatureSpawnEvent.SpawnReason catserver$bukkitReason = CreatureSpawnEvent.SpawnReason.DEFAULT; + -+ public boolean tryAddFreshEntityWithPassengers(Entity p_8861_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) { -+ this.catserver$bukkitReason = reason; -+ return m_8860_(p_8861_); ++ private boolean addEntity(Entity p_8873_, CreatureSpawnEvent.SpawnReason spawnReason) { ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureSpawnReason(spawnReason); ++ try { ++ return m_8872_(p_8873_); ++ } finally { ++ // CatServer - Make sure reset ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); ++ } + } ++ // CatServer end + + public boolean m_8860_(Entity p_8861_) { ++ // CraftBukkit start ++ CreatureSpawnEvent.SpawnReason reason = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); ++ return tryAddFreshEntityWithPassengers(p_8861_, reason == null ? org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT : reason); ++ } ++ ++ public boolean tryAddFreshEntityWithPassengers(Entity p_8861_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) { ++ // CraftBukkit end + if (p_8861_.m_142428_().map(Entity::m_142081_).anyMatch(this.f_143244_::m_157550_)) { + return false; + } else { -+ var reason = this.catserver$bukkitReason; -+ this.catserver$bukkitReason = null; // CatServer - reset + this.addFreshEntityWithPassengers(p_8861_, reason); // CraftBukkit + return true; + } + } -+ // CatServer end + + public void m_8712_(LevelChunk p_8713_) { + // Spigot Start + for (net.minecraft.world.level.block.entity.BlockEntity tileentity : p_8713_.m_62954_().values()) { + if (tileentity instanceof net.minecraft.world.Container) { -+ for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(catserver.server.inventory.CatInventoryUtils.getViewers((Container) tileentity))) { // CatServer ++ for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(catserver.server.inventory.CatInventoryUtils.getViewers((net.minecraft.world.Container) tileentity))) { // CatServer + h.closeInventory(); + } + } diff --git a/patches/minecraft/net/minecraft/server/level/ServerPlayer.java.patch b/patches/minecraft/net/minecraft/server/level/ServerPlayer.java.patch index a7770c30d..02446914e 100644 --- a/patches/minecraft/net/minecraft/server/level/ServerPlayer.java.patch +++ b/patches/minecraft/net/minecraft/server/level/ServerPlayer.java.patch @@ -44,7 +44,7 @@ import net.minecraft.world.level.block.HorizontalDirectionalBlock; import net.minecraft.world.level.block.NetherPortalBlock; import net.minecraft.world.level.block.entity.BlockEntity; -@@ -132,1393 +_,1945 @@ +@@ -132,1393 +_,1951 @@ import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.PlayerTeam; import net.minecraft.world.scores.Score; @@ -1524,8 +1524,15 @@ + + @Nullable + public Entity changeDimension(ServerLevel p_9180_, PlayerTeleportEvent.TeleportCause cause) { ++ // CatServer start + CatServerCaptures.getCatServerCaptures().captureChangeDimCause(cause); -+ return this.changeDimension(p_9180_, p_9180_.m_8871_()); ++ try { ++ return this.changeDimension(p_9180_, p_9180_.m_8871_()); ++ } finally { ++ // CatServer - Make sure reset ++ CatServerCaptures.getCatServerCaptures().getCaptureChangeDimCause(); ++ } ++ // CatServer end + } + + @Nullable @@ -1569,9 +1576,7 @@ + } + Location enter = this.getBukkitEntity().getLocation(); + Location exit = (exitLevel[0] == null) ? null : new Location(exitLevel[0].getWorld(), portalinfo.f_77676_.f_82479_, portalinfo.f_77676_.f_82480_, portalinfo.f_77676_.f_82481_, portalinfo.f_77678_, portalinfo.f_77679_); -+ var cause = CatServerCaptures.getCatServerCaptures().getCaptureChangeDimCause(); -+ if (cause == null) cause = PlayerTeleportEvent.TeleportCause.UNKNOWN; -+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, cause); ++ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, CatServerCaptures.getCatServerCaptures().getCaptureChangeDimCause()); + Bukkit.getServer().getPluginManager().callEvent(tpEvent); + if (tpEvent.isCancelled() || tpEvent.getTo() == null) { + return null; @@ -1656,17 +1661,11 @@ + + } + -+ protected Optional getExitPortal(ServerLevel p_184131_, BlockPos p_184132_, boolean p_184133_, WorldBorder p_184134_, int searchRadius, boolean canCreatePortal, int createRadius) { // CraftBukkit -+ CatServerCaptures.getCatServerCaptures().capturePortalSearchRadius(searchRadius); -+ CatServerCaptures.getCatServerCaptures().captureCanCreatePortal(canCreatePortal); -+ CatServerCaptures.getCatServerCaptures().capturePortalRadius(createRadius); -+ return this.m_183318_(p_184131_, p_184132_, p_184133_, p_184134_); ++ protected Optional m_183318_(ServerLevel p_184131_, BlockPos p_184132_, boolean p_184133_, WorldBorder p_184134_) { ++ return this.getExitPortal(p_184131_, p_184132_, p_184133_, p_184134_, p_184133_ ? 16 : 128, true, 16); // CatServer + } + -+ protected Optional m_183318_(ServerLevel p_184131_, BlockPos p_184132_, boolean p_184133_, WorldBorder p_184134_) { -+ var searchRadius = CatServerCaptures.getCatServerCaptures().getCapturePortalSearchRadius(); -+ var canCreatePortal = CatServerCaptures.getCatServerCaptures().getCaptureCanCreatePortal(); -+ var createRadius = CatServerCaptures.getCatServerCaptures().getCapturePortalRadius(); ++ protected Optional getExitPortal(ServerLevel p_184131_, BlockPos p_184132_, boolean p_184133_, WorldBorder p_184134_, int searchRadius, boolean canCreatePortal, int createRadius) { // CraftBukkit + Optional optional = super.getExitPortal(p_184131_, p_184132_, p_184133_, p_184134_, searchRadius, canCreatePortal, createRadius); // CraftBukkit + if (optional.isPresent() || !canCreatePortal) { // CraftBukkit + return optional; @@ -1717,6 +1716,13 @@ + this.f_36096_.m_38946_(); + } + ++ // CatServer start ++ public boolean isForceSleep; // CatServer ++ public Either startSleepInBed(BlockPos p_36203_, boolean force) { ++ isForceSleep = force; ++ return m_7720_(p_36203_); // CatServer - Call origin method ++ } ++ // CatServer end + public Either m_7720_(BlockPos p_9115_) { + Direction enumdirection = this.f_19853_.m_8055_(p_9115_).m_61143_(HorizontalDirectionalBlock.f_54117_); + Either bedResult = null; @@ -1761,10 +1767,10 @@ + return bedResult; // return immediately if the result is not bypassable by plugins + } + -+ boolean force = CatServerCaptures.getCatServerCaptures().getCaptureIsForceSleep(); // CatServer -+ if (force) { ++ if (isForceSleep) { + bedResult = Either.right(Unit.INSTANCE); + } ++ isForceSleep = false; // CatServer - Reset + + bedResult = org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callPlayerBedEnterEvent(this, p_9115_, bedResult); + if (bedResult.left().isPresent()) { diff --git a/patches/minecraft/net/minecraft/world/entity/Entity.java.patch b/patches/minecraft/net/minecraft/world/entity/Entity.java.patch index 4d56d92d8..217a5af61 100644 --- a/patches/minecraft/net/minecraft/world/entity/Entity.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/Entity.java.patch @@ -891,7 +891,7 @@ } public boolean m_7306_(Entity p_20356_) { -@@ -2237,32 +_,66 @@ +@@ -2237,32 +_,80 @@ @Nullable public Entity m_5489_(ServerLevel p_20118_) { @@ -900,8 +900,23 @@ + + @Nullable + public Entity teleportTo(ServerLevel p_20118_, BlockPos blockPosition) { -+ CatServerCaptures.getCatServerCaptures().captureBlockPos(blockPosition); -+ return this.changeDimension(p_20118_, p_20118_.m_8871_()); ++ // CatServer start ++ float yRot = this.f_19857_; ++ float xRot = this.f_19858_; ++ return this.changeDimension(p_20118_, new net.minecraftforge.common.util.ITeleporter() { ++ public Entity placeEntity(Entity entity, ServerLevel currentWorld, ServerLevel destWorld, float yaw, java.util.function.Function repositionEntity) { ++ return p_20118_.m_8871_().placeEntity(entity, currentWorld, destWorld, yaw, repositionEntity); ++ } ++ ++ public PortalInfo getPortalInfo(Entity entity, ServerLevel destWorld, java.util.function.Function defaultPortalInfo) { ++ return new PortalInfo(new Vec3(blockPosition.m_123341_(), blockPosition.m_123342_(), blockPosition.m_123343_()), Vec3.f_82478_, yRot, xRot).putCB(p_20118_, null); ++ } ++ ++ public boolean playTeleportSound(ServerPlayer player, ServerLevel sourceWorld, ServerLevel destWorld) { ++ return p_20118_.m_8871_().playTeleportSound(player, sourceWorld, destWorld); ++ } ++ }); ++ // CatServer end + } + + @Nullable @@ -917,8 +932,7 @@ + // CatServer end this.f_19853_.m_46473_().m_6180_("reposition"); - PortalInfo portalinfo = this.m_7937_(p_20118_); -+ var bukkitPos = CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); -+ PortalInfo portalinfo = bukkitPos == null ? teleporter.getPortalInfo(this, p_20118_, this::m_7937_) : new PortalInfo(new Vec3(bukkitPos.m_123341_(), bukkitPos.m_123342_(), bukkitPos.m_123343_()), Vec3.f_82478_, this.f_19857_, this.f_19858_).putCB(p_20118_, null); // CatServer ++ PortalInfo portalinfo = teleporter.getPortalInfo(this, p_20118_, this::m_7937_); if (portalinfo == null) { return null; } else { diff --git a/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch b/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch index 3fb582c64..66c519896 100644 --- a/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch @@ -1,12 +1,5 @@ --- a/net/minecraft/world/entity/EntityType.java +++ b/net/minecraft/world/entity/EntityType.java -@@ -1,5 +_,6 @@ - package net.minecraft.world.entity; - -+import catserver.server.CatServerCaptures; - import com.google.common.collect.ImmutableSet; - import com.mojang.logging.LogUtils; - import java.util.List; @@ -146,14 +_,15 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.shapes.Shapes; @@ -58,28 +51,31 @@ } @Nullable -@@ -314,10 +_,20 @@ - } +@@ -315,9 +_,15 @@ @Nullable -+ public T spawn(ServerLevel p_20601_, @Nullable CompoundTag p_20602_, @Nullable Component p_20603_, @Nullable Player p_20604_, BlockPos p_20605_, MobSpawnType p_20606_, boolean p_20607_, boolean p_20608_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { -+ CatServerCaptures.getCatServerCaptures().captureSpawnReason(spawnReason); -+ return this.m_20600_(p_20601_, p_20602_, p_20603_, p_20604_, p_20605_, p_20606_, p_20607_, p_20608_); + public T m_20600_(ServerLevel p_20601_, @Nullable CompoundTag p_20602_, @Nullable Component p_20603_, @Nullable Player p_20604_, BlockPos p_20605_, MobSpawnType p_20606_, boolean p_20607_, boolean p_20608_) { ++ return this.spawn(p_20601_, p_20602_, p_20603_, p_20604_, p_20605_, p_20606_, p_20607_, p_20608_, CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); // CatServer + } + + @Nullable - public T m_20600_(ServerLevel p_20601_, @Nullable CompoundTag p_20602_, @Nullable Component p_20603_, @Nullable Player p_20604_, BlockPos p_20605_, MobSpawnType p_20606_, boolean p_20607_, boolean p_20608_) { ++ public T spawn(ServerLevel p_20601_, @Nullable CompoundTag p_20602_, @Nullable Component p_20603_, @Nullable Player p_20604_, BlockPos p_20605_, MobSpawnType p_20606_, boolean p_20607_, boolean p_20608_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { T t = this.m_20655_(p_20601_, p_20602_, p_20603_, p_20604_, p_20605_, p_20606_, p_20607_, p_20608_); if (t != null) { - p_20601_.m_47205_(t); -+ if (t instanceof net.minecraft.world.entity.Mob && net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn((net.minecraft.world.entity.Mob) t, p_20601_, p_20605_.m_123341_(), p_20605_.m_123342_(), p_20605_.m_123343_(), null, p_20606_)) return null; -+ var spawnReason = CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); -+ if (spawnReason == null) spawnReason = CreatureSpawnEvent.SpawnReason.SPAWNER_EGG; + p_20601_.addFreshEntityWithPassengers(t, spawnReason); + return !t.m_146910_() ? t : null; // Don't return an entity when CreatureSpawnEvent is canceled } return t; +@@ -342,6 +_,7 @@ + Mob mob = (Mob)t; + mob.f_20885_ = mob.m_146908_(); + mob.f_20883_ = mob.m_146908_(); ++ if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(mob, p_20656_, (float) mob.m_20185_(), (float) mob.m_20186_(), (float) mob.m_20189_(), null, p_20661_)) + mob.m_6518_(p_20656_, p_20656_.m_6436_(mob.m_142538_()), p_20661_, (SpawnGroupData)null, p_20657_); + mob.m_8032_(); + } @@ -350,7 +_,7 @@ t.m_6593_(p_20658_); } diff --git a/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch b/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch index 54cd84ebc..4a34d0bc8 100644 --- a/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch @@ -206,18 +206,15 @@ this.m_8127_(); } } else if (this.m_20146_() < this.m_6062_()) { -@@ -618,13 +_,22 @@ - this.f_147183_ = p_147245_; +@@ -619,8 +_,14 @@ } -+ // CatServer start -+ protected void equipEventAndSound(ItemStack p_147219_, boolean silent) { -+ CatServerCaptures.getCatServerCaptures().captureIsSlient(silent); -+ this.m_147218_(p_147219_); + protected void m_147218_(ItemStack p_147219_) { ++ // CraftBukkit start ++ this.equipEventAndSound(p_147219_, false); + } + - protected void m_147218_(ItemStack p_147219_) { -+ var slient = CatServerCaptures.getCatServerCaptures().getCaptureIsSlient(); ++ protected void equipEventAndSound(ItemStack p_147219_, boolean slient) { SoundEvent soundevent = p_147219_.m_150920_(); - if (!p_147219_.m_41619_() && soundevent != null && !this.m_5833_()) { + if (!p_147219_.m_41619_() && soundevent != null && !this.m_5833_() && !slient) { @@ -225,11 +222,6 @@ this.m_146850_(GameEvent.f_157811_); this.m_5496_(soundevent, 1.0F, 1.0F); } - } -+ // CatServer end - - public void m_7380_(CompoundTag p_21145_) { - p_21145_.m_128350_("Health", this.m_21223_()); @@ -673,6 +_,17 @@ } } @@ -336,23 +328,21 @@ return d0; } -@@ -840,21 +_,36 @@ - this.f_19804_.m_135381_(f_20962_, 0); +@@ -841,14 +_,27 @@ } -+ // CatServer start -+ public boolean removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause) { -+ CatServerCaptures.getCatServerCaptures().capturePotionEffectCause(cause); -+ return this.m_21219_(); + public boolean m_21219_() { ++ // CraftBukkit start ++ return this.removeAllEffects(EntityPotionEffectEvent.Cause.UNKNOWN); + } + - public boolean m_21219_() { ++ public boolean removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause) { ++ // CraftBukkit end if (this.f_19853_.f_46443_) { return false; } else { Iterator iterator = this.f_20945_.values().iterator(); - -+ var cause = CatServerCaptures.getCatServerCaptures().getCapturePotionEffectCause(); boolean flag; for(flag = false; iterator.hasNext(); flag = true) { - this.m_7285_(iterator.next()); @@ -368,14 +358,7 @@ iterator.remove(); } - return flag; - } - } -+ // CatServer end - - public Collection m_21220_() { - return this.f_20945_.values(); -@@ -877,25 +_,57 @@ +@@ -877,25 +_,55 @@ return this.m_147207_(p_21165_, (Entity)null); } @@ -383,14 +366,12 @@ + return this.addEffect(mobeffect, null, cause); + } + -+ // CatServer start -+ public boolean addEffect(MobEffectInstance p_147208_, @Nullable Entity p_147209_, EntityPotionEffectEvent.Cause cause) { -+ CatServerCaptures.getCatServerCaptures().capturePotionEffectCause(cause); -+ return this.m_147207_(p_147208_, p_147209_); + public boolean m_147207_(MobEffectInstance p_147208_, @Nullable Entity p_147209_) { ++ // CraftBukkit start ++ return this.addEffect(p_147208_, p_147209_, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN); + } + - public boolean m_147207_(MobEffectInstance p_147208_, @Nullable Entity p_147209_) { -+ var cause = CatServerCaptures.getCatServerCaptures().getCapturePotionEffectCause(); ++ public boolean addEffect(MobEffectInstance p_147208_, @Nullable Entity p_147209_, EntityPotionEffectEvent.Cause cause) { + if (isTickingEffects) { + effectsToProcess.add(new ProcessableEffect(p_147208_, cause)); + return true; @@ -434,20 +415,18 @@ if (this.m_6336_() == MobType.f_21641_) { MobEffect mobeffect = p_21197_.m_19544_(); if (mobeffect == MobEffects.f_19605_ || mobeffect == MobEffects.f_19614_) { -@@ -922,13 +_,40 @@ +@@ -922,13 +_,37 @@ return this.m_6336_() == MobType.f_21641_; } + // CatServer start -+ @Nullable -+ public MobEffectInstance removeEffectNoUpdate(@Nullable MobEffect p_21164_, EntityPotionEffectEvent.Cause cause) { -+ CatServerCaptures.getCatServerCaptures().capturePotionEffectCause(cause); -+ return m_6234_(p_21164_); -+ } -+ @Nullable public MobEffectInstance m_6234_(@Nullable MobEffect p_21164_) { -+ var cause = CatServerCaptures.getCatServerCaptures().getCapturePotionEffectCause(); ++ return removeEffectNoUpdate(p_21164_, EntityPotionEffectEvent.Cause.UNKNOWN); ++ } ++ ++ @Nullable ++ public MobEffectInstance removeEffectNoUpdate(@Nullable MobEffect p_21164_, EntityPotionEffectEvent.Cause cause) { + if (isTickingEffects) { + effectsToProcess.add(new ProcessableEffect(p_21164_, cause)); + return null; @@ -463,15 +442,14 @@ return this.f_20945_.remove(p_21164_); } -+ public boolean removeEffect(MobEffect p_21196_, EntityPotionEffectEvent.Cause cause) { -+ CatServerCaptures.getCatServerCaptures().capturePotionEffectCause(cause); -+ return m_21195_(p_21196_); -+ } -+ public boolean m_21195_(MobEffect p_21196_) { - MobEffectInstance mobeffectinstance = this.m_6234_(p_21196_); ++ // CraftBukkit start ++ return removeEffect(p_21196_, EntityPotionEffectEvent.Cause.UNKNOWN); ++ } ++ ++ public boolean removeEffect(MobEffect p_21196_, EntityPotionEffectEvent.Cause cause) { + if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.PotionEvent.PotionRemoveEvent(this, p_21196_))) return false; -+ var cause = CatServerCaptures.getCatServerCaptures().getCapturePotionEffectCause(); // CatServer + MobEffectInstance mobeffectinstance = this.removeEffectNoUpdate(p_21196_, cause); // CraftBukkit if (mobeffectinstance != null) { this.m_7285_(mobeffectinstance); @@ -484,23 +462,21 @@ protected void m_142540_(MobEffectInstance p_147190_, @Nullable Entity p_147191_) { this.f_20948_ = true; -@@ -963,19 +_,56 @@ +@@ -963,19 +_,53 @@ } + // CatServer start -+ public void heal(float p_21116_, EntityRegainHealthEvent.RegainReason regainReason) { -+ CatServerCaptures.getCatServerCaptures().captureRegainReason(regainReason); -+ this.m_5634_(p_21116_); + public void m_5634_(float p_21116_) { ++ this.heal(p_21116_, EntityRegainHealthEvent.RegainReason.CUSTOM); + } + - public void m_5634_(float p_21116_) { ++ public void heal(float p_21116_, EntityRegainHealthEvent.RegainReason regainReason) { + p_21116_ = net.minecraftforge.event.ForgeEventFactory.onLivingHeal(this, p_21116_); + if (p_21116_ <= 0) return; float f = this.m_21223_(); if (f > 0.0F) { - this.m_21153_(f + p_21116_); -+ var regainReason = CatServerCaptures.getCatServerCaptures().getCaptureRegainReason(); + EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), p_21116_, regainReason); + // Suppress during worldgen + if (this.valid) { @@ -509,7 +485,6 @@ + if (!event.isCancelled()) { + this.m_21153_((float) (this.m_21223_() + event.getAmount())); + } -+ // CraftBukkit end } - } @@ -1126,20 +1101,22 @@ public CombatTracker m_21231_() { return this.f_20944_; } -@@ -1557,9 +_,21 @@ +@@ -1557,9 +_,23 @@ return this.f_19804_.m_135370_(f_20940_); } + // CatServer start + public final void setArrowCount(int p_21318_, boolean flag) { -+ CatServerCaptures.getCatServerCaptures().captureArrowFlag(flag); -+ this.m_21317_(p_21318_); ++ ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, m_21234_(), p_21318_, flag); ++ if (event.isCancelled()) { ++ return; ++ } ++ this.f_19804_.m_135381_(f_20940_, event.getNewAmount()); + } + public final void m_21317_(int p_21318_) { - this.f_19804_.m_135381_(f_20940_, p_21318_); -+ var flag = CatServerCaptures.getCatServerCaptures().getCaptureArrowFlag(); -+ ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, m_21234_(), p_21318_, flag); ++ ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, m_21234_(), p_21318_, false); + if (event.isCancelled()) { + return; + } @@ -1443,15 +1420,21 @@ if (this.f_20935_.m_41781_()) { this.m_21329_(); } -@@ -2976,6 +_,12 @@ +@@ -2976,6 +_,18 @@ return this.f_20937_; } + // CatServer start + public Optional randomTeleport(double p_20985_, double p_20986_, double p_20987_, boolean p_20988_, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { + CatServerCaptures.getCatServerCaptures().captureTeleportCause(cause); -+ return Optional.of(this.m_20984_(p_20985_, p_20986_, p_20987_, p_20988_)); ++ try { ++ return Optional.of(this.m_20984_(p_20985_, p_20986_, p_20987_, p_20988_)); ++ } finally { ++ // CatServer - Make sure reset ++ CatServerCaptures.getCatServerCaptures().getCaptureTeleportCause(); ++ } + } ++ // CatServer end + public boolean m_20984_(double p_20985_, double p_20986_, double p_20987_, boolean p_20988_) { double d0 = this.m_20185_(); diff --git a/patches/minecraft/net/minecraft/world/entity/Mob.java.patch b/patches/minecraft/net/minecraft/world/entity/Mob.java.patch index 92f3e18dd..eead72cfd 100644 --- a/patches/minecraft/net/minecraft/world/entity/Mob.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/Mob.java.patch @@ -1,12 +1,6 @@ --- a/net/minecraft/world/entity/Mob.java +++ b/net/minecraft/world/entity/Mob.java -@@ -1,11 +_,13 @@ - package net.minecraft.world.entity; - -+import catserver.server.CatServerCaptures; - import com.google.common.collect.Maps; - import java.util.Arrays; - import java.util.Map; +@@ -6,6 +_,7 @@ import java.util.Optional; import java.util.Random; import java.util.UUID; @@ -170,7 +164,7 @@ boolean flag = this.m_7808_(p_21541_, itemstack); - if (flag && this.m_7252_(p_21541_)) { + // CraftBukkit start -+ var entityitem = CatServerCaptures.getCatServerCaptures().getCaptureItemEntity(); ++ var entityitem = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureItemEntity(); + boolean canPickup = flag && this.m_7252_(p_21541_); + if (entityitem != null) { + canPickup = !org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, !canPickup).isCancelled(); @@ -190,7 +184,7 @@ } + public boolean equipItemIfPossible(ItemStack p_21541_, ItemEntity itemEntity) { -+ CatServerCaptures.getCatServerCaptures().captureItemEntity(itemEntity); ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureItemEntity(itemEntity); + return this.m_21540_(p_21541_); + } + diff --git a/patches/minecraft/net/minecraft/world/entity/decoration/ArmorStand.java.patch b/patches/minecraft/net/minecraft/world/entity/decoration/ArmorStand.java.patch index f7a344871..400c0aa46 100644 --- a/patches/minecraft/net/minecraft/world/entity/decoration/ArmorStand.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/decoration/ArmorStand.java.patch @@ -49,11 +49,15 @@ public void m_6210_() { double d0 = this.m_20185_(); double d1 = this.m_20186_(); -@@ -143,16 +_,21 @@ +@@ -142,17 +_,20 @@ + } public void m_8061_(EquipmentSlot p_31584_, ItemStack p_31585_) { ++ this.setItemSlot(p_31584_, p_31585_, false); ++ } ++ ++ public void setItemSlot(EquipmentSlot p_31584_, ItemStack p_31585_, boolean silent) { this.m_181122_(p_31585_); -+ var silent = CatServerCaptures.getCatServerCaptures().getCaptureIsSlient(); switch(p_31584_.m_20743_()) { case HAND: - this.m_147218_(p_31585_); @@ -65,11 +69,7 @@ + this.equipEventAndSound(p_31585_, silent); // CraftBukkit this.f_31539_.set(p_31584_.m_20749_(), p_31585_); } -+ } - -+ public void setItemSlot(EquipmentSlot p_31584_, ItemStack p_31585_, boolean silent) { -+ CatServerCaptures.getCatServerCaptures().captureIsSlient(silent); -+ this.m_8061_(p_31584_, p_31585_); +- } public boolean m_7066_(ItemStack p_31638_) { diff --git a/patches/minecraft/net/minecraft/world/entity/item/FallingBlockEntity.java.patch b/patches/minecraft/net/minecraft/world/entity/item/FallingBlockEntity.java.patch index 0df871b7d..d7ab75fa5 100644 --- a/patches/minecraft/net/minecraft/world/entity/item/FallingBlockEntity.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/item/FallingBlockEntity.java.patch @@ -28,19 +28,14 @@ private int f_31940_ = 40; private float f_149641_; @Nullable -@@ -72,10 +_,19 @@ - this.m_31959_(this.m_142538_()); +@@ -73,9 +_,14 @@ } -+ // CatServer start -+ public static FallingBlockEntity fall(Level p_201972_, BlockPos p_201973_, BlockState p_201974_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { -+ CatServerCaptures.getCatServerCaptures().captureSpawnReason(spawnReason); -+ return FallingBlockEntity.m_201971_(p_201972_, p_201973_, p_201974_); + public static FallingBlockEntity m_201971_(Level p_201972_, BlockPos p_201973_, BlockState p_201974_) { ++ return FallingBlockEntity.fall(p_201972_, p_201973_, p_201974_, CreatureSpawnEvent.SpawnReason.DEFAULT); // CatServer + } + - public static FallingBlockEntity m_201971_(Level p_201972_, BlockPos p_201973_, BlockState p_201974_) { -+ var spawnReason = CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); -+ if (spawnReason == null) spawnReason = CreatureSpawnEvent.SpawnReason.DEFAULT; ++ public static FallingBlockEntity fall(Level p_201972_, BlockPos p_201973_, BlockState p_201974_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { FallingBlockEntity fallingblockentity = new FallingBlockEntity(p_201972_, (double)p_201973_.m_123341_() + 0.5D, (double)p_201973_.m_123342_(), (double)p_201973_.m_123343_() + 0.5D, p_201974_.m_61138_(BlockStateProperties.f_61362_) ? p_201974_.m_61124_(BlockStateProperties.f_61362_, Boolean.valueOf(false)) : p_201974_); + if (CraftEventFactory.callEntityChangeBlockEvent(fallingblockentity, p_201973_, p_201974_.m_60819_().m_76188_()).isCancelled()) return fallingblockentity; // CraftBukkit p_201972_.m_7731_(p_201973_, p_201974_.m_60819_().m_76188_(), 3); diff --git a/patches/minecraft/net/minecraft/world/entity/monster/Slime.java.patch b/patches/minecraft/net/minecraft/world/entity/monster/Slime.java.patch index ba12b6fd9..c242afe09 100644 --- a/patches/minecraft/net/minecraft/world/entity/monster/Slime.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/monster/Slime.java.patch @@ -55,7 +55,7 @@ for(int l = 0; l < k; ++l) { float f1 = ((float)(l % 2) - 0.5F) * f; float f2 = ((float)(l / 2) - 0.5F) * f; -@@ -196,8 +_,17 @@ +@@ -196,8 +_,21 @@ slime.m_20331_(this.m_20147_()); slime.m_7839_(j, true); slime.m_7678_(this.m_20185_() + (double)f1, this.m_20186_() + 0.5D, this.m_20189_() + (double)f2, this.f_19796_.nextFloat() * 360.0F, 0.0F); @@ -69,7 +69,11 @@ + return; + } + for (LivingEntity living : slimes) { -+ this.f_19853_.addFreshEntity(living, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason ++ // CatServer start - Fix mixin inject ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureSpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); ++ this.f_19853_.m_7967_(living); ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); // CatServer - Make sure reset ++ // CatServer end + } + // CraftBukkit end } diff --git a/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch b/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch index 003ddad67..2349234b2 100644 --- a/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch @@ -151,7 +151,7 @@ super.m_6667_(p_36152_); this.m_20090_(); if (!this.m_5833_()) { -@@ -625,7 +_,13 @@ +@@ -625,7 +_,37 @@ @Nullable public ItemEntity m_36176_(ItemStack p_36177_, boolean p_36178_) { @@ -161,42 +161,36 @@ + + @Nullable + public ItemEntity drop(ItemStack p_36179_, boolean p_36180_, boolean p_36181_, boolean callEvent) { -+ CatServerCaptures.getCatServerCaptures().captureIsCallEvent(callEvent); -+ return m_7197_(p_36179_, p_36180_, p_36181_); ++ ItemEntity itementity = m_7197_(p_36179_, p_36180_, p_36181_); ++ // CraftBukkit start - fire PlayerDropItemEvent ++ if (!callEvent) { // SPIGOT-2942: Add boolean to call event ++ return itementity; ++ } ++ org.bukkit.entity.Player player = (org.bukkit.entity.Player) this.getBukkitEntity(); ++ Item drop = (Item) itementity.getBukkitEntity(); ++ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop); ++ this.f_19853_.getCraftServer().getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand(); ++ if (p_36181_ && (cur == null || cur.getAmount() == 0)) { ++ // The complete stack was dropped ++ player.getInventory().setItemInHand(drop.getItemStack()); ++ } else if (p_36181_ && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) { ++ // Only one item is dropped ++ cur.setAmount(cur.getAmount() + 1); ++ player.getInventory().setItemInHand(cur); ++ } else { ++ // Fallback ++ player.getInventory().addItem(drop.getItemStack()); ++ } ++ return null; ++ } ++ // CraftBukkit end ++ return itementity; } @Nullable -@@ -659,11 +_,42 @@ - itementity.m_20334_((double)(-f3 * f2 * 0.3F) + Math.cos((double)f5) * (double)f6, (double)(-f8 * 0.3F + 0.1F + (this.f_19796_.nextFloat() - this.f_19796_.nextFloat()) * 0.1F), (double)(f4 * f2 * 0.3F) + Math.sin((double)f5) * (double)f6); - } - -+ // CraftBukkit start - fire PlayerDropItemEvent -+ var callEvent = CatServerCaptures.getCatServerCaptures().getCaptureIsCallEvent(); -+ if (!callEvent) { // SPIGOT-2942: Add boolean to call event -+ return itementity; -+ } -+ org.bukkit.entity.Player player = (org.bukkit.entity.Player) this.getBukkitEntity(); -+ Item drop = (Item) itementity.getBukkitEntity(); -+ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop); -+ this.f_19853_.getCraftServer().getPluginManager().callEvent(event); -+ if (event.isCancelled()) { -+ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand(); -+ if (p_36181_ && (cur == null || cur.getAmount() == 0)) { -+ // The complete stack was dropped -+ player.getInventory().setItemInHand(drop.getItemStack()); -+ } else if (p_36181_ && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) { -+ // Only one item is dropped -+ cur.setAmount(cur.getAmount() + 1); -+ player.getInventory().setItemInHand(cur); -+ } else { -+ // Fallback -+ player.getInventory().addItem(drop.getItemStack()); -+ } -+ return null; -+ } -+ // CraftBukkit end -+ - return itementity; +@@ -663,7 +_,12 @@ } } @@ -608,21 +602,14 @@ this.m_5810_(); this.f_19853_.m_7605_(this, (byte)30); } -@@ -1253,13 +_,21 @@ - public void m_141945_(ItemStack p_150098_, ItemStack p_150099_, ClickAction p_150100_) { - } - -+ // CraftBukkit start -+ public Player forceSleep(boolean isForceSleep) { -+ CatServerCaptures.getCatServerCaptures().captureIsForceSleep(isForceSleep); -+ return this; -+ } -+ - public Either m_7720_(BlockPos p_36203_) { - this.m_5802_(p_36203_); +@@ -1258,8 +_,14 @@ this.f_36110_ = 0; return Either.right(Unit.INSTANCE); } ++ // CraftBukkit start ++ public Either startSleepInBed(BlockPos p_36203_, boolean force) { ++ return m_7720_(p_36203_); // CatServer - Call origin method ++ } + // CraftBukkit end public void m_6145_(boolean p_36226_, boolean p_36227_) { @@ -810,18 +797,15 @@ public FoodData m_36324_() { return this.f_36097_; -@@ -1658,16 +_,22 @@ - } +@@ -1659,15 +_,19 @@ } -+ public void setItemSlot(EquipmentSlot p_36161_, ItemStack p_36162_, boolean silent) { -+ CatServerCaptures.getCatServerCaptures().captureIsSlient(silent); -+ this.m_8061_(p_36161_, p_36162_); + public void m_8061_(EquipmentSlot p_36161_, ItemStack p_36162_) { ++ this.setItemSlot(p_36161_, p_36162_, false); + } + - public void m_8061_(EquipmentSlot p_36161_, ItemStack p_36162_) { ++ public void setItemSlot(EquipmentSlot p_36161_, ItemStack p_36162_, boolean silent) { this.m_181122_(p_36162_); -+ var silent = CatServerCaptures.getCatServerCaptures().getCaptureIsSlient(); if (p_36161_ == EquipmentSlot.MAINHAND) { - this.m_147218_(p_36162_); + this.equipEventAndSound(p_36162_, silent); // CraftBukkit diff --git a/patches/minecraft/net/minecraft/world/food/FoodData.java.patch b/patches/minecraft/net/minecraft/world/food/FoodData.java.patch index 4e3e2bf91..89f5a4c4b 100644 --- a/patches/minecraft/net/minecraft/world/food/FoodData.java.patch +++ b/patches/minecraft/net/minecraft/world/food/FoodData.java.patch @@ -67,7 +67,7 @@ } } -@@ -40,29 +_,39 @@ +@@ -40,29 +_,37 @@ if (this.f_38697_ > 0.0F) { this.f_38697_ = Math.max(this.f_38697_ - 1.0F, 0.0F); } else if (difficulty != Difficulty.PEACEFUL) { @@ -88,9 +88,9 @@ - if (this.f_38699_ >= 10) { + if (this.f_38699_ >= this.saturatedRegenRate) { // CraftBukkit float f = Math.min(this.f_38697_, 6.0F); -+ CatServerCaptures.getCatServerCaptures().captureRegainReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason - p_38711_.m_5634_(f / 6.0F); +- p_38711_.m_5634_(f / 6.0F); - this.m_38703_(f); ++ p_38711_.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason + //this.addExhaustion(f); + p_38711_.causeFoodExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent this.f_38699_ = 0; @@ -98,10 +98,10 @@ } else if (flag && this.f_38696_ >= 18 && p_38711_.m_36325_()) { ++this.f_38699_; - if (this.f_38699_ >= 80) { -+ if (this.f_38699_ >= this.unsaturatedRegenRate) { // CraftBukkit - add regen rate manipulation -+ CatServerCaptures.getCatServerCaptures().captureRegainReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason - p_38711_.m_5634_(1.0F); +- p_38711_.m_5634_(1.0F); - this.m_38703_(6.0F); ++ if (this.f_38699_ >= this.unsaturatedRegenRate) { // CraftBukkit - add regen rate manipulation ++ p_38711_.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason + // this.addExhaustion(6.0F); + p_38711_.causeFoodExhaustion(p_38711_.f_19853_.spigotConfig.regenExhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent this.f_38699_ = 0; diff --git a/patches/minecraft/net/minecraft/world/item/BucketItem.java.patch b/patches/minecraft/net/minecraft/world/item/BucketItem.java.patch index 7a83968ad..b44d5196b 100644 --- a/patches/minecraft/net/minecraft/world/item/BucketItem.java.patch +++ b/patches/minecraft/net/minecraft/world/item/BucketItem.java.patch @@ -1,11 +1,10 @@ --- a/net/minecraft/world/item/BucketItem.java +++ b/net/minecraft/world/item/BucketItem.java -@@ -1,10 +_,14 @@ +@@ -1,10 +_,13 @@ package net.minecraft.world.item; import javax.annotation.Nullable; + -+import catserver.server.CatServerCaptures; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -91,33 +90,39 @@ this.m_142131_(p_40704_, p_40703_, itemstack, blockpos2); if (p_40704_ instanceof ServerPlayer) { CriteriaTriggers.f_10591_.m_59469_((ServerPlayer)p_40704_, blockpos2, itemstack); -@@ -98,6 +_,13 @@ +@@ -98,6 +_,22 @@ public void m_142131_(@Nullable Player p_150711_, Level p_150712_, ItemStack p_150713_, BlockPos p_150714_) { } + public boolean emptyContents(Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_, Direction direction, BlockPos clicked, ItemStack itemstack) { -+ CatServerCaptures.getCatServerCaptures().captureDirection(direction); -+ CatServerCaptures.getCatServerCaptures().captureBlockPos(clicked); -+ CatServerCaptures.getCatServerCaptures().captureItemStack(itemstack); -+ return this.m_142073_(p_150716_, p_150717_, p_150718_, p_150719_); ++ // CatServer start ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureDirection(direction); ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureBlockPos(clicked); ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureItemStack(itemstack); ++ try { ++ return this.m_142073_(p_150716_, p_150717_, p_150718_, p_150719_); ++ } finally { ++ // CatServer - Make sure reset ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureDirection(); ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureItemStack(); ++ } ++ // CatServer end + } + public boolean m_142073_(@Nullable Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_) { if (!(this.f_40687_ instanceof FlowingFluid)) { return false; -@@ -107,8 +_,24 @@ +@@ -107,8 +_,21 @@ Material material = blockstate.m_60767_(); boolean flag = blockstate.m_60722_(this.f_40687_); boolean flag1 = blockstate.m_60795_() || flag || block instanceof LiquidBlockContainer && ((LiquidBlockContainer)block).m_6044_(p_150717_, p_150718_, blockstate, this.f_40687_); + // CraftBukkit start -+ var clicked = CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); -+ var enumdirection = CatServerCaptures.getCatServerCaptures().getCaptureDirection(); -+ var itemstack = CatServerCaptures.getCatServerCaptures().getCaptureItemStack(); -+ if (clicked == null) clicked = BlockPos.f_121853_; -+ if (enumdirection == null) enumdirection = Direction.UP; -+ if (itemstack == null) itemstack = ItemStack.f_41583_; ++ var clicked = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); ++ var enumdirection = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureDirection(); ++ var itemstack = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureItemStack(); + if (flag1 && p_150716_ != null) { -+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) p_150717_, p_150716_, p_150718_, clicked, enumdirection, itemstack); ++ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) p_150717_, p_150716_, p_150718_, clicked == null ? BlockPos.f_121853_ : clicked, enumdirection == null ? enumdirection = Direction.UP : enumdirection, itemstack == null ? ItemStack.f_41583_ : itemstack); + if (event.isCancelled()) { + ((ServerPlayer) p_150716_).f_8906_.m_141995_(new ClientboundBlockUpdatePacket(p_150717_, p_150718_)); // SPIGOT-4238: needed when looking through entity + ((ServerPlayer) p_150716_).getBukkitEntity().updateInventory(); // SPIGOT-4541 diff --git a/patches/minecraft/net/minecraft/world/item/ItemStack.java.patch b/patches/minecraft/net/minecraft/world/item/ItemStack.java.patch index d91a4a4ac..d65e13662 100644 --- a/patches/minecraft/net/minecraft/world/item/ItemStack.java.patch +++ b/patches/minecraft/net/minecraft/world/item/ItemStack.java.patch @@ -1,65 +1,10 @@ --- a/net/minecraft/world/item/ItemStack.java +++ b/net/minecraft/world/item/ItemStack.java -@@ -8,15 +_,13 @@ - import com.mojang.brigadier.exceptions.CommandSyntaxException; - import com.mojang.logging.LogUtils; - import com.mojang.serialization.Codec; -+import com.mojang.serialization.Dynamic; - import com.mojang.serialization.codecs.RecordCodecBuilder; - import java.text.DecimalFormat; - import java.text.DecimalFormatSymbols; --import java.util.Collection; --import java.util.List; --import java.util.Locale; --import java.util.Optional; --import java.util.Random; -+import java.util.*; - import java.util.Map.Entry; -+import java.util.concurrent.atomic.AtomicReference; - import java.util.function.Consumer; - import java.util.stream.Collectors; - import java.util.stream.Stream; -@@ -26,10 +_,12 @@ - import net.minecraft.advancements.CriteriaTriggers; - import net.minecraft.commands.arguments.blocks.BlockStateParser; - import net.minecraft.core.BlockPos; -+import net.minecraft.core.Direction; - import net.minecraft.core.Holder; - import net.minecraft.core.Registry; - import net.minecraft.nbt.CompoundTag; - import net.minecraft.nbt.ListTag; -+import net.minecraft.nbt.NbtOps; - import net.minecraft.nbt.Tag; - import net.minecraft.network.chat.Component; - import net.minecraft.network.chat.ComponentUtils; -@@ -38,11 +_,16 @@ - import net.minecraft.network.chat.Style; - import net.minecraft.network.chat.TextComponent; - import net.minecraft.network.chat.TranslatableComponent; -+import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; - import net.minecraft.resources.ResourceLocation; -+import net.minecraft.server.MinecraftServer; -+import net.minecraft.server.level.ServerLevel; - import net.minecraft.server.level.ServerPlayer; - import net.minecraft.sounds.SoundEvent; -+import net.minecraft.sounds.SoundSource; - import net.minecraft.stats.Stats; - import net.minecraft.tags.TagKey; -+import net.minecraft.util.datafix.fixes.References; - import net.minecraft.world.InteractionHand; - import net.minecraft.world.InteractionResult; - import net.minecraft.world.InteractionResultHolder; -@@ -67,12 +_,25 @@ - import net.minecraft.world.item.enchantment.Enchantments; - import net.minecraft.world.level.ItemLike; - import net.minecraft.world.level.Level; --import net.minecraft.world.level.block.Block; -+import net.minecraft.world.level.block.*; -+import net.minecraft.world.level.block.entity.BlockEntity; -+import net.minecraft.world.level.block.entity.SignBlockEntity; -+import net.minecraft.world.level.block.entity.SkullBlockEntity; - import net.minecraft.world.level.block.state.BlockState; +@@ -72,7 +_,18 @@ import net.minecraft.world.level.block.state.pattern.BlockInWorld; + import org.slf4j.Logger; + +-public final class ItemStack { +import org.bukkit.Location; +import org.bukkit.SoundCategory; +import org.bukkit.TreeType; @@ -70,9 +15,7 @@ +import org.bukkit.event.block.BlockFertilizeEvent; +import org.bukkit.event.player.PlayerItemDamageEvent; +import org.bukkit.event.world.StructureGrowEvent; - import org.slf4j.Logger; - --public final class ItemStack { ++ +public final class ItemStack extends net.minecraftforge.common.capabilities.CapabilityProvider implements net.minecraftforge.common.extensions.IForgeItemStack { public static final Codec f_41582_ = RecordCodecBuilder.create((p_41697_) -> { return p_41697_.group(Registry.f_122827_.m_194605_().fieldOf("id").forGetter((p_150946_) -> { @@ -124,7 +67,7 @@ + if (0 < version && version < CraftMagicNumbers.INSTANCE.getDataVersion()) { + CompoundTag savedStack = new CompoundTag(); + this.m_41739_(savedStack); -+ savedStack = (CompoundTag) MinecraftServer.getServer().f_129759_.update(References.f_16782_, new Dynamic(NbtOps.f_128958_, savedStack), version, CraftMagicNumbers.INSTANCE.getDataVersion()).getValue(); ++ savedStack = (CompoundTag) net.minecraft.server.MinecraftServer.getServer().f_129759_.update(net.minecraft.util.datafix.fixes.References.f_16782_, new com.mojang.serialization.Dynamic(net.minecraft.nbt.NbtOps.f_128958_, savedStack), version, CraftMagicNumbers.INSTANCE.getDataVersion()).getValue(); + this.load(savedStack); + } } @@ -179,7 +122,7 @@ } public boolean m_204117_(TagKey p_204118_) { -@@ -206,17 +_,165 @@ +@@ -206,6 +_,15 @@ } public InteractionResult m_41661_(UseOnContext p_41662_) { @@ -187,13 +130,6 @@ + return onItemUse(p_41662_, (c) -> m_41720_().m_6225_(p_41662_)); + } + -+ // CatServer start - fire hand -+ private AtomicReference catserver$useHand = new AtomicReference<>(InteractionHand.MAIN_HAND); -+ public InteractionResult useOn(UseOnContext p_41662_, InteractionHand hand) { -+ this.catserver$useHand.set(hand); -+ return onItemUse(p_41662_, (c) -> m_41720_().m_6225_(p_41662_)); -+ } -+ + public InteractionResult onItemUseFirst(UseOnContext p_41662_) { + return onItemUse(p_41662_, (c) -> m_41720_().onItemUseFirst(this, p_41662_)); + } @@ -202,151 +138,15 @@ Player player = p_41662_.m_43723_(); BlockPos blockpos = p_41662_.m_8083_(); BlockInWorld blockinworld = new BlockInWorld(p_41662_.m_43725_(), blockpos, false); - if (player != null && !player.m_150110_().f_35938_ && !this.m_204121_(p_41662_.m_43725_().m_5962_().m_175515_(Registry.f_122901_), blockinworld)) { +@@ -213,7 +_,7 @@ return InteractionResult.PASS; } else { -+ var enumhand = this.catserver$useHand.getAndSet(InteractionHand.MAIN_HAND); -+ // CraftBukkit start - handle all block place event logic here -+ CompoundTag oldData = this.getTagClone(); -+ int oldCount = this.m_41613_(); -+ ServerLevel world = (ServerLevel) p_41662_.m_43725_(); -+ if (!(this.m_41720_() instanceof BucketItem || this.m_41720_() instanceof SolidBucketItem)) { // if not bucket -+ world.captureBlockStates = true; -+ // special case bonemeal -+ if (this.m_41720_() == Items.f_42499_) { -+ world.captureTreeGeneration = true; -+ } -+ } Item item = this.m_41720_(); - InteractionResult interactionresult = item.m_6225_(p_41662_); + InteractionResult interactionresult = callback.apply(p_41662_); -+ CompoundTag newData = this.getTagClone(); -+ int newCount = this.m_41613_(); -+ this.m_41764_(oldCount); -+ this.setTagClone(oldData); -+ world.captureBlockStates = false; -+ if (interactionresult.m_19077_() && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) { -+ world.captureTreeGeneration = false; -+ Location location = new Location(world.getWorld(), blockpos.m_123341_(), blockpos.m_123342_(), blockpos.m_123343_()); -+ TreeType treeType = SaplingBlock.treeType; -+ SaplingBlock.treeType = null; -+ List blocks = new java.util.ArrayList<>(world.capturedBlockStates.values()); -+ world.capturedBlockStates.clear(); -+ StructureGrowEvent structureEvent = null; -+ if (treeType != null) { -+ boolean isBonemeal = m_41720_() == Items.f_42499_; -+ structureEvent = new StructureGrowEvent(location, treeType, isBonemeal, (org.bukkit.entity.Player) player.getBukkitEntity(), blocks); -+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent); -+ } -+ BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(CraftBlock.at(world, blockpos), (org.bukkit.entity.Player) player.getBukkitEntity(), blocks); -+ fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled()); -+ org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent); -+ if (!fertilizeEvent.isCancelled()) { -+ // Change the stack to its new contents if it hasn't been tampered with. -+ if (this.m_41613_() == oldCount && Objects.equals(this.f_41590_, oldData)) { -+ this.m_41751_(newData); -+ this.m_41764_(newCount); -+ } -+ for (org.bukkit.block.BlockState blockstate : blocks) { -+ blockstate.update(true); -+ } -+ } -+ SignItem.openSign = null; // SPIGOT-6758 - Reset on early return -+ return interactionresult; -+ } -+ world.captureTreeGeneration = false; if (player != null && interactionresult.m_146666_()) { -- player.m_36246_(Stats.f_12982_.m_12902_(item)); -+ //player.awardStat(Stats.ITEM_USED.get(item)); -+ org.bukkit.event.block.BlockPlaceEvent placeEvent = null; -+ List blocks = new java.util.ArrayList<>(world.capturedBlockStates.values()); -+ world.capturedBlockStates.clear(); -+ if (blocks.size() > 1) { -+ placeEvent = org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callBlockMultiPlaceEvent(world, player, enumhand, blocks, blockpos.m_123341_(), blockpos.m_123342_(), blockpos.m_123343_()); -+ } else if (blocks.size() == 1) { -+ placeEvent = org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callBlockPlaceEvent(world, player, enumhand, blocks.get(0), blockpos.m_123341_(), blockpos.m_123342_(), blockpos.m_123343_()); -+ } -+ if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) { -+ interactionresult = InteractionResult.FAIL; // cancel placement -+ // PAIL: Remove this when MC-99075 fixed -+ placeEvent.getPlayer().updateInventory(); -+ // revert back all captured blocks -+ world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710 -+ for (org.bukkit.block.BlockState blockstate : blocks) { -+ blockstate.update(true, false); -+ } -+ world.preventPoiUpdated = false; -+ // Brute force all possible updates -+ BlockPos placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition(); -+ for (Direction dir : Direction.values()) { -+ ((ServerPlayer) player).f_8906_.m_141995_(new ClientboundBlockUpdatePacket(world, placedPos.m_142300_(dir))); -+ } -+ SignItem.openSign = null; // SPIGOT-6758 - Reset on early return -+ } else { -+ // Change the stack to its new contents if it hasn't been tampered with. -+ if (this.m_41613_() == oldCount && Objects.equals(this.f_41590_, oldData)) { -+ this.m_41751_(newData); -+ this.m_41764_(newCount); -+ } -+ for (Map.Entry e : world.capturedTileEntities.entrySet()) { -+ world.m_151523_(e.getValue()); -+ } -+ for (org.bukkit.block.BlockState blockstate : blocks) { -+ int updateFlag = ((CraftBlockState) blockstate).getFlag(); -+ BlockState oldBlock = ((CraftBlockState) blockstate).getHandle(); -+ BlockPos newblockposition = ((CraftBlockState) blockstate).getPosition(); -+ BlockState block = world.m_8055_(newblockposition); -+ if (!(block.m_60734_() instanceof BaseEntityBlock)) { // Containers get placed automatically -+ block.m_60734_().m_6807_(block, world, newblockposition, oldBlock, true); -+ } -+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.m_8055_(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point -+ } -+ // Special case juke boxes as they update their tile entity. Copied from ItemRecord. -+ // PAIL: checkme on updates. -+ if (this.f_41589_ instanceof RecordItem) { -+ ((JukeboxBlock) Blocks.f_50131_).m_54269_(world, blockpos, world.m_8055_(blockpos), this); -+ world.m_5898_(null, 1010, blockpos, Item.m_41393_(this.f_41589_)); -+ this.m_41774_(1); -+ player.m_36220_(Stats.f_12965_); -+ } -+ if (this.f_41589_ == Items.f_42679_) { // Special case skulls to allow wither spawns to be cancelled -+ BlockPos bp = blockpos; -+ if (!world.m_8055_(blockpos).m_60767_().m_76336_()) { -+ if (!world.m_8055_(blockpos).m_60767_().m_76333_()) { -+ bp = null; -+ } else { -+ bp = bp.m_142300_(p_41662_.m_43719_()); -+ } -+ } -+ if (bp != null) { -+ BlockEntity te = world.m_7702_(bp); -+ if (te instanceof SkullBlockEntity) { -+ WitherSkullBlock.m_58255_(world, bp, (SkullBlockEntity) te); -+ } -+ } -+ } -+ // SPIGOT-4678 -+ if (this.f_41589_ instanceof SignItem && SignItem.openSign != null) { -+ try { -+ player.m_7739_((SignBlockEntity) world.m_7702_(SignItem.openSign)); -+ } finally { -+ SignItem.openSign = null; -+ } -+ } -+ // SPIGOT-1288 - play sound stripped from ItemBlock -+ if (this.f_41589_ instanceof BlockItem) { -+ SoundType soundeffecttype = ((BlockItem) this.f_41589_).m_40614_().m_49962_(null); -+ world.m_5594_(player, blockpos, soundeffecttype.m_56777_(), SoundSource.BLOCKS, (soundeffecttype.m_56773_() + 1.0F) / 2.0F, soundeffecttype.m_56774_() * 0.8F); -+ } -+ player.m_36246_(Stats.f_12982_.m_12902_(item)); -+ } + player.m_36246_(Stats.f_12982_.m_12902_(item)); } -+ world.capturedTileEntities.clear(); -+ world.capturedBlockStates.clear(); -+ // CraftBukkit end - - return interactionresult; - } @@ -242,11 +_,15 @@ p_41740_.m_128365_("tag", this.f_41590_.m_6426_()); } diff --git a/patches/minecraft/net/minecraft/world/item/SignItem.java.patch b/patches/minecraft/net/minecraft/world/item/SignItem.java.patch index c2b15aa4c..bebb80a56 100644 --- a/patches/minecraft/net/minecraft/world/item/SignItem.java.patch +++ b/patches/minecraft/net/minecraft/world/item/SignItem.java.patch @@ -9,11 +9,10 @@ public SignItem(Item.Properties p_43126_, Block p_43127_, Block p_43128_) { super(p_43127_, p_43128_, p_43126_); } -@@ -16,7 +_,9 @@ - protected boolean m_7274_(BlockPos p_43130_, Level p_43131_, @Nullable Player p_43132_, ItemStack p_43133_, BlockState p_43134_) { +@@ -17,6 +_,9 @@ boolean flag = super.m_7274_(p_43130_, p_43131_, p_43132_, p_43133_, p_43134_); if (!p_43131_.f_46443_ && !flag && p_43132_ != null) { -- p_43132_.m_7739_((SignBlockEntity)p_43131_.m_7702_(p_43130_)); + p_43132_.m_7739_((SignBlockEntity)p_43131_.m_7702_(p_43130_)); + // CraftBukkit start - SPIGOT-4678 + SignItem.openSign = p_43130_; + // CraftBukkit end diff --git a/patches/minecraft/net/minecraft/world/level/NaturalSpawner.java.patch b/patches/minecraft/net/minecraft/world/level/NaturalSpawner.java.patch index c0e368b2c..4761c70fc 100644 --- a/patches/minecraft/net/minecraft/world/level/NaturalSpawner.java.patch +++ b/patches/minecraft/net/minecraft/world/level/NaturalSpawner.java.patch @@ -1,12 +1,5 @@ --- a/net/minecraft/world/level/NaturalSpawner.java +++ b/net/minecraft/world/level/NaturalSpawner.java -@@ -1,5 +_,6 @@ - package net.minecraft.world.level; - -+import catserver.server.CatServerCaptures; - import com.mojang.logging.LogUtils; - import it.unimi.dsi.fastutil.objects.Object2IntMap; - import it.unimi.dsi.fastutil.objects.Object2IntMaps; @@ -44,9 +_,14 @@ import net.minecraft.world.level.levelgen.structure.BuiltinStructures; import net.minecraft.world.level.material.FluidState; @@ -59,7 +52,7 @@ p_47030_.m_46473_().m_7238_(); } -@@ -179,13 +_,22 @@ +@@ -179,13 +_,23 @@ } mob.m_7678_(d0, (double)i, d1, p_47040_.f_46441_.nextFloat() * 360.0F, 0.0F); @@ -72,10 +65,11 @@ - ++l1; + // CraftBukkit start + // CatServer - fix Botania mixin injection -+ CatServerCaptures.getCatServerCaptures().captureSpawnReason(CreatureSpawnEvent.SpawnReason.NATURAL); ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureSpawnReason(CreatureSpawnEvent.SpawnReason.NATURAL); p_47040_.m_47205_(mob); - p_47044_.m_47100_(mob, p_47041_); - if (j >= mob.m_5792_()) { ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureSpawnReason(); // CatServer - Make sure reset + // CatServer end + if (!mob.m_146910_()) { + ++j; @@ -138,19 +132,17 @@ flag = true; } } -@@ -492,8 +_,16 @@ +@@ -492,8 +_,14 @@ return this.f_47113_; } + // CraftBukkit start -+ boolean canSpawnForCategory(MobCategory p_186549_, ChunkPos p_186550_, int limit) { -+ CatServerCaptures.getCatServerCaptures().captureSpawnerLimit(limit); -+ return m_186548_(p_186549_, p_186550_); -+ } -+ boolean m_186548_(MobCategory p_186549_, ChunkPos p_186550_) { - int i = p_186549_.m_21608_() * this.f_47110_ / NaturalSpawner.f_46978_; -+ var limit = CatServerCaptures.getCatServerCaptures().getCaptureLimit(); ++ return canSpawnForCategory(p_186549_, p_186550_, p_186549_.m_21608_()); // CatServer ++ } ++ ++ boolean canSpawnForCategory(MobCategory p_186549_, ChunkPos p_186550_, int limit) { + int i = limit * this.f_47110_ / NaturalSpawner.f_46978_; + // CraftBukkit end if (this.f_47111_.getInt(p_186549_) >= i) { diff --git a/patches/minecraft/net/minecraft/world/level/block/BigDripleafBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/BigDripleafBlock.java.patch index 01497ae04..c02b03dc6 100644 --- a/patches/minecraft/net/minecraft/world/level/block/BigDripleafBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/BigDripleafBlock.java.patch @@ -1,12 +1,5 @@ --- a/net/minecraft/world/level/block/BigDripleafBlock.java +++ b/net/minecraft/world/level/block/BigDripleafBlock.java -@@ -1,5 +_,6 @@ - package net.minecraft.world.level.block; - -+import catserver.server.CatServerCaptures; - import com.google.common.collect.ImmutableMap; - import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; - import it.unimi.dsi.fastutil.objects.Object2IntMap; @@ -39,6 +_,8 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; @@ -58,25 +51,23 @@ } else if (tilt == Tilt.FULL) { m_152313_(p_152256_, p_152257_, p_152258_); } -@@ -190,8 +_,16 @@ +@@ -190,8 +_,14 @@ return p_152303_.m_20096_() && p_152303_.m_20182_().f_82480_ > (double)((float)p_152302_.m_123342_() + 0.6875F); } + // CraftBukkit start -+ private void setTiltAndScheduleTick(BlockState p_152283_, Level p_152284_, BlockPos p_152285_, Tilt p_152286_, @Nullable SoundEvent p_152287_, @Nullable Entity entity) { -+ catserver.server.CatServerCaptures.getCatServerCaptures().captureEntity(entity); // CatServer -+ this.m_152282_(p_152283_, p_152284_, p_152285_, p_152286_, p_152287_); -+ } -+ private void m_152282_(BlockState p_152283_, Level p_152284_, BlockPos p_152285_, Tilt p_152286_, @Nullable SoundEvent p_152287_) { - m_152277_(p_152283_, p_152284_, p_152285_, p_152286_); -+ var entity = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureEntity(); // CatServer ++ this.setTiltAndScheduleTick(p_152283_, p_152284_, p_152285_, p_152286_, p_152287_, null); ++ } ++ ++ private void setTiltAndScheduleTick(BlockState p_152283_, Level p_152284_, BlockPos p_152285_, Tilt p_152286_, @Nullable SoundEvent p_152287_, @Nullable Entity entity) { + if (!setTilt(p_152283_, p_152284_, p_152285_, p_152286_, entity)) return; + // CraftBukkit end if (p_152287_ != null) { m_152232_(p_152284_, p_152285_, p_152287_); } -@@ -204,20 +_,37 @@ +@@ -204,19 +_,27 @@ } private static void m_152313_(BlockState p_152314_, Level p_152315_, BlockPos p_152316_) { @@ -85,24 +76,17 @@ if (p_152314_.m_61143_(f_152201_) != Tilt.NONE) { m_152232_(p_152315_, p_152316_, SoundEvents.f_144132_); } -+ } - -+ // CatServer start -+ private static boolean catserver$setTiltReturnValue; -+ private static boolean setTilt(BlockState p_152278_, Level p_152279_, BlockPos p_152280_, Tilt p_152281_, @Nullable Entity entity) { -+ catserver.server.CatServerCaptures.getCatServerCaptures().captureEntity(entity); // CatServer -+ m_152277_(p_152278_, p_152279_, p_152280_, p_152281_); -+ var tempBoolean = catserver$setTiltReturnValue; -+ catserver$setTiltReturnValue = false; -+ return tempBoolean; +- } private static void m_152277_(BlockState p_152278_, Level p_152279_, BlockPos p_152280_, Tilt p_152281_) { -+ var entity = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureEntity(); // CatServer ++ m_152277_(p_152278_, p_152279_, p_152280_, p_152281_); // CatServer ++ } ++ ++ private static boolean setTilt(BlockState p_152278_, Level p_152279_, BlockPos p_152280_, Tilt p_152281_, @Nullable Entity entity) { + if (entity != null) { + if (CraftEventFactory.callEntityChangeBlockEvent(entity, p_152280_, p_152278_.m_61124_(f_152201_, p_152281_)).isCancelled()) { -+ catserver$setTiltReturnValue = false; -+ return; ++ return false; + } + } p_152279_.m_7731_(p_152280_, p_152278_.m_61124_(f_152201_, p_152281_), 2); @@ -110,9 +94,7 @@ p_152279_.m_151555_(GameEvent.f_157792_, p_152280_); } - -+ catserver$setTiltReturnValue = true; ++ return true; } -+ // CatServer end public VoxelShape m_5939_(BlockState p_152307_, BlockGetter p_152308_, BlockPos p_152309_, CollisionContext p_152310_) { - return f_152208_.get(p_152307_.m_61143_(f_152201_)); diff --git a/patches/minecraft/net/minecraft/world/level/block/CaveVines.java.patch b/patches/minecraft/net/minecraft/world/level/block/CaveVines.java.patch index f7a0306dd..6606aa1fc 100644 --- a/patches/minecraft/net/minecraft/world/level/block/CaveVines.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/CaveVines.java.patch @@ -1,12 +1,11 @@ --- a/net/minecraft/world/level/block/CaveVines.java +++ b/net/minecraft/world/level/block/CaveVines.java -@@ -1,11 +_,15 @@ +@@ -1,11 +_,14 @@ package net.minecraft.world.level.block; +import java.util.Collections; import java.util.function.ToIntFunction; + -+import catserver.server.CatServerCaptures; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; @@ -29,7 +28,7 @@ BooleanProperty f_152949_ = BlockStateProperties.f_155977_; + static InteractionResult use(BlockState p_152954_, Level p_152955_, BlockPos p_152956_, Entity entity) { -+ CatServerCaptures.getCatServerCaptures().captureEntity(entity); ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureEntity(entity); + return m_152953_(p_152954_, p_152955_, p_152956_); + } + @@ -37,9 +36,9 @@ if (p_152954_.m_61143_(f_152949_)) { - Block.m_49840_(p_152955_, p_152956_, new ItemStack(Items.f_151079_, 1)); + // Block.popResource(p_152955_, p_152956_, new ItemStack(Items.GLOW_BERRIES, 1)); -+ // CraftBukkit start -+ var entity = CatServerCaptures.getCatServerCaptures().getCaptureEntity(); -+ if (org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callEntityChangeBlockEvent(entity, p_152956_, (BlockState) p_152954_.m_61124_(CaveVines.f_152949_, false)).isCancelled()) { ++ // CatServer start ++ var entity = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureEntity(); // CatServer ++ if (entity != null && org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callEntityChangeBlockEvent(entity, p_152956_, (BlockState) p_152954_.m_61124_(CaveVines.f_152949_, false)).isCancelled()) { + return InteractionResult.SUCCESS; + } + if (entity instanceof Player) { @@ -53,7 +52,7 @@ + } else { + Block.m_49840_(p_152955_, p_152956_, new ItemStack(Items.f_151079_, 1)); + } -+ // CraftBukkit end ++ // CatServer end float f = Mth.m_144924_(p_152955_.f_46441_, 0.8F, 1.2F); p_152955_.m_5594_((Player)null, p_152956_, SoundEvents.f_144088_, SoundSource.BLOCKS, 1.0F, f); p_152955_.m_7731_(p_152956_, p_152954_.m_61124_(f_152949_, Boolean.valueOf(false)), 2); diff --git a/patches/minecraft/net/minecraft/world/level/block/ComposterBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/ComposterBlock.java.patch index 845f2facb..7be6cf891 100644 --- a/patches/minecraft/net/minecraft/world/level/block/ComposterBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/ComposterBlock.java.patch @@ -1,12 +1,5 @@ --- a/net/minecraft/world/level/block/ComposterBlock.java +++ b/net/minecraft/world/level/block/ComposterBlock.java -@@ -1,5 +_,6 @@ - package net.minecraft.world.level.block; - -+import catserver.server.CatServerCaptures; - import it.unimi.dsi.fastutil.objects.Object2FloatMap; - import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; - import java.util.Random; @@ -17,6 +_,7 @@ import net.minecraft.world.SimpleContainer; import net.minecraft.world.WorldlyContainer; @@ -24,7 +17,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder { public static final int f_153088_ = 8; -@@ -213,25 +_,52 @@ +@@ -213,7 +_,7 @@ return InteractionResult.m_19078_(p_51950_.f_46443_); } else if (i == 8) { @@ -33,23 +26,21 @@ return InteractionResult.m_19078_(p_51950_.f_46443_); } else { return InteractionResult.PASS; - } +@@ -221,17 +_,40 @@ } -+ public static BlockState insertItem(BlockState p_51930_, ServerLevel p_51931_, ItemStack p_51932_, BlockPos p_51933_, Entity entity) { -+ CatServerCaptures.getCatServerCaptures().captureEntity(entity); -+ return m_51929_(p_51930_, p_51931_, p_51932_, p_51933_); + public static BlockState m_51929_(BlockState p_51930_, ServerLevel p_51931_, ItemStack p_51932_, BlockPos p_51933_) { ++ return insertItem(p_51930_, p_51931_, p_51932_, p_51933_, null); + } + - public static BlockState m_51929_(BlockState p_51930_, ServerLevel p_51931_, ItemStack p_51932_, BlockPos p_51933_) { ++ public static BlockState insertItem(BlockState p_51930_, ServerLevel p_51931_, ItemStack p_51932_, BlockPos p_51933_, Entity entity) { int i = p_51930_.m_61143_(f_51913_); if (i < 7 && f_51914_.containsKey(p_51932_.m_41720_())) { - BlockState blockstate = m_51983_(p_51930_, p_51931_, p_51933_, p_51932_); + // CraftBukkit start -+ var entity = CatServerCaptures.getCatServerCaptures().getCaptureEntity(); + double rand = p_51931_.m_5822_().nextDouble(); + BlockState iblockdata1 = addItem(p_51930_, DummyGeneratorAccess.INSTANCE, p_51933_, p_51932_, rand); -+ if (p_51930_ == iblockdata1 || org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callEntityChangeBlockEvent(entity, p_51933_, iblockdata1).isCancelled()) { ++ if (p_51930_ == iblockdata1 || (entity != null && org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callEntityChangeBlockEvent(entity, p_51933_, iblockdata1).isCancelled())) { // CatServer + return p_51930_; + } + iblockdata1 = addItem(p_51930_, (LevelAccessor) p_51931_, p_51933_, p_51932_, rand); @@ -62,14 +53,12 @@ } } -+ public static BlockState extractProduce(BlockState p_51999_, Level p_52000_, BlockPos p_52001_, Entity entity) { -+ CatServerCaptures.getCatServerCaptures().captureEntity(entity); -+ return m_51998_(p_51999_, p_52000_, p_52001_); + public static BlockState m_51998_(BlockState p_51999_, Level p_52000_, BlockPos p_52001_) { ++ return extractProduce(p_51999_, p_52000_, p_52001_, null); + } + - public static BlockState m_51998_(BlockState p_51999_, Level p_52000_, BlockPos p_52001_) { ++ public static BlockState extractProduce(BlockState p_51999_, Level p_52000_, BlockPos p_52001_, Entity entity) { + // CraftBukkit start -+ var entity = CatServerCaptures.getCatServerCaptures().getCaptureEntity(); + if (entity != null) { + BlockState bukkitState = m_52002_(p_51999_, DummyGeneratorAccess.INSTANCE, p_52001_); + if (org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callEntityChangeBlockEvent(entity, p_52001_, bukkitState).isCancelled()) { diff --git a/patches/minecraft/net/minecraft/world/level/block/FireBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/FireBlock.java.patch index ccc2040d3..a1738d881 100644 --- a/patches/minecraft/net/minecraft/world/level/block/FireBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/FireBlock.java.patch @@ -1,12 +1,5 @@ --- a/net/minecraft/world/level/block/FireBlock.java +++ b/net/minecraft/world/level/block/FireBlock.java -@@ -1,5 +_,6 @@ - package net.minecraft.world.level.block; - -+import catserver.server.CatServerCaptures; - import com.google.common.collect.ImmutableMap; - import it.unimi.dsi.fastutil.objects.Object2IntMap; - import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; @@ -26,6 +_,12 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; @@ -143,7 +136,7 @@ } } } -@@ -204,32 +_,43 @@ +@@ -204,32 +_,48 @@ return p_53429_.m_46758_(p_53430_) || p_53429_.m_46758_(p_53430_.m_142125_()) || p_53429_.m_46758_(p_53430_.m_142126_()) || p_53429_.m_46758_(p_53430_.m_142127_()) || p_53429_.m_46758_(p_53430_.m_142128_()); } @@ -164,13 +157,15 @@ if (p_53435_.nextInt(p_53434_) < i) { BlockState blockstate = p_53432_.m_8055_(p_53433_); + // CraftBukkit start -+ var sourceposition = CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); -+ org.bukkit.block.Block theBlock = p_53432_.getWorld().getBlockAt(p_53433_.m_123341_(), p_53433_.m_123342_(), p_53433_.m_123343_()); -+ org.bukkit.block.Block sourceBlock = p_53432_.getWorld().getBlockAt(sourceposition.m_123341_(), sourceposition.m_123342_(), sourceposition.m_123343_()); -+ BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock); -+ p_53432_.getCraftServer().getPluginManager().callEvent(event); -+ if (event.isCancelled()) { -+ return; ++ var sourceposition = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); ++ if (sourceposition != null) { // CatServer - Check pos is null ++ org.bukkit.block.Block theBlock = p_53432_.getWorld().getBlockAt(p_53433_.m_123341_(), p_53433_.m_123342_(), p_53433_.m_123343_()); ++ org.bukkit.block.Block sourceBlock = p_53432_.getWorld().getBlockAt(sourceposition.m_123341_(), sourceposition.m_123342_(), sourceposition.m_123343_()); ++ BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock); ++ p_53432_.getCraftServer().getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ return; ++ } + } + // CraftBukkit end if (p_53435_.nextInt(p_53436_ + 10) < 5 && !p_53432_.m_46758_(p_53433_)) { @@ -190,8 +185,11 @@ + } + private void tryCatchFire(Level p_53432_, BlockPos p_53433_, int p_53434_, Random p_53435_, int p_53436_, Direction face, BlockPos bukkitPos) { // CraftBukkit add sourceposition -+ CatServerCaptures.getCatServerCaptures().captureBlockPos(bukkitPos); ++ // CatServer start ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureBlockPos(bukkitPos); + this.tryCatchFire(p_53432_, p_53433_, p_53434_, p_53435_, p_53436_, face); ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); // CatServer - Make sure reset ++ // CatServer end } private BlockState m_53437_(LevelAccessor p_53438_, BlockPos p_53439_, int p_53440_) { diff --git a/patches/minecraft/net/minecraft/world/level/block/MultifaceBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/MultifaceBlock.java.patch index c2f1599d7..bb6425f3b 100644 --- a/patches/minecraft/net/minecraft/world/level/block/MultifaceBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/MultifaceBlock.java.patch @@ -1,12 +1,5 @@ --- a/net/minecraft/world/level/block/MultifaceBlock.java +++ b/net/minecraft/world/level/block/MultifaceBlock.java -@@ -1,5 +_,6 @@ - package net.minecraft.world.level.block; - -+import catserver.server.CatServerCaptures; - import com.google.common.collect.ImmutableMap; - import com.google.common.collect.Lists; - import com.google.common.collect.Maps; @@ -190,7 +_,7 @@ Optional> optional = this.m_153855_(p_153867_, p_153868_, p_153869_, p_153870_, p_153871_); if (optional.isPresent()) { @@ -16,25 +9,36 @@ } else { return false; } -@@ -231,6 +_,11 @@ +@@ -231,6 +_,18 @@ } } + private boolean spreadToFace(LevelAccessor p_153835_, BlockPos p_153836_, Direction p_153837_, boolean p_153838_, BlockPos source) { -+ CatServerCaptures.getCatServerCaptures().captureBlockPos(source); -+ return this.m_153834_(p_153835_, p_153836_, p_153837_, p_153838_); ++ // CatServer start ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureBlockPos(source); ++ try { ++ return this.m_153834_(p_153835_, p_153836_, p_153837_, p_153838_); ++ } finally { ++ // CatServer - Make sure reset ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); // CatServer ++ } ++ // CatServer end + } + private boolean m_153834_(LevelAccessor p_153835_, BlockPos p_153836_, Direction p_153837_, boolean p_153838_) { BlockState blockstate = p_153835_.m_8055_(p_153836_); BlockState blockstate1 = this.m_153940_(blockstate, p_153835_, p_153836_, p_153837_); -@@ -239,7 +_,8 @@ +@@ -239,7 +_,12 @@ p_153835_.m_46865_(p_153836_).m_8113_(p_153836_); } - return p_153835_.m_7731_(p_153836_, blockstate1, 2); -+ var source = CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); // CatServer -+ return org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.handleBlockSpreadEvent(p_153835_, source, p_153836_, blockstate1, 2); // CraftBukkit ++ var source = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); // CatServer ++ if (source != null) { ++ return org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.handleBlockSpreadEvent(p_153835_, source, p_153836_, blockstate1, 2); // CraftBukkit ++ } else { ++ return p_153835_.m_7731_(p_153836_, blockstate1, 2); ++ } } else { return false; } diff --git a/patches/minecraft/net/minecraft/world/level/block/NoteBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/NoteBlock.java.patch index b7e990ba5..4dd867442 100644 --- a/patches/minecraft/net/minecraft/world/level/block/NoteBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/NoteBlock.java.patch @@ -1,12 +1,5 @@ --- a/net/minecraft/world/level/block/NoteBlock.java +++ b/net/minecraft/world/level/block/NoteBlock.java -@@ -1,5 +_,6 @@ - package net.minecraft.world.level.block; - -+import catserver.server.CatServerCaptures; - import net.minecraft.core.BlockPos; - import net.minecraft.core.Direction; - import net.minecraft.core.particles.ParticleTypes; @@ -43,7 +_,8 @@ boolean flag = p_55042_.m_46753_(p_55043_); if (flag != p_55041_.m_61143_(f_55012_)) { @@ -17,19 +10,16 @@ } p_55042_.m_7731_(p_55043_, p_55041_.m_61124_(f_55012_, Boolean.valueOf(flag)), 3); -@@ -51,9 +_,20 @@ - +@@ -52,19 +_,29 @@ } -+ private void playNote(Level p_55020_, BlockPos p_55021_, BlockState blockState) { -+ CatServerCaptures.getCatServerCaptures().captureBlockState(blockState); -+ this.m_55019_(p_55020_, p_55021_); + private void m_55019_(Level p_55020_, BlockPos p_55021_) { ++ this.playNote(p_55020_, p_55021_, p_55020_.m_8055_(p_55021_)); // CatServer + } + - private void m_55019_(Level p_55020_, BlockPos p_55021_) { ++ private void playNote(Level p_55020_, BlockPos p_55021_, BlockState blockState) { if (p_55020_.m_8055_(p_55021_.m_7494_()).m_60795_()) { - p_55020_.m_7696_(p_55021_, this, 0, 0); -+ var blockState = CatServerCaptures.getCatServerCaptures().getCaptureBlockState(); // CatServer + // CraftBukkit start + org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.callNotePlayEvent(p_55020_, p_55021_, blockState.m_61143_(f_55011_), blockState.m_61143_(f_55013_)); + if (!event.isCancelled()) { @@ -37,9 +27,10 @@ + } + // CraftBukkit end } - +- } -@@ -62,9 +_,11 @@ + + public InteractionResult m_6227_(BlockState p_55034_, Level p_55035_, BlockPos p_55036_, Player p_55037_, InteractionHand p_55038_, BlockHitResult p_55039_) { if (p_55035_.f_46443_) { return InteractionResult.SUCCESS; } else { diff --git a/patches/minecraft/net/minecraft/world/level/block/PointedDripstoneBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/PointedDripstoneBlock.java.patch index 958370f51..4cad3c3b3 100644 --- a/patches/minecraft/net/minecraft/world/level/block/PointedDripstoneBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/PointedDripstoneBlock.java.patch @@ -1,12 +1,5 @@ --- a/net/minecraft/world/level/block/PointedDripstoneBlock.java +++ b/net/minecraft/world/level/block/PointedDripstoneBlock.java -@@ -1,5 +_,6 @@ - package net.minecraft.world.level.block; - -+import catserver.server.CatServerCaptures; - import com.google.common.annotations.VisibleForTesting; - import java.util.Optional; - import java.util.Random; @@ -42,6 +_,8 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; @@ -38,7 +31,7 @@ } else { super.m_142072_(p_154047_, p_154048_, p_154049_, p_154050_, p_154051_); } -@@ -341,14 +_,20 @@ +@@ -341,7 +_,7 @@ if (m_154143_(blockstate, p_154038_.m_122424_())) { m_154230_(blockstate, p_154036_, blockpos); } else if (blockstate.m_60795_() || blockstate.m_60713_(Blocks.f_49990_)) { @@ -46,21 +39,19 @@ + createDripstone(p_154036_, blockpos, p_154038_, DripstoneThickness.TIP, p_154037_); // CraftBukkit } -+ } -+ -+ private static void createDripstone(LevelAccessor p_154088_, BlockPos p_154089_, Direction p_154090_, DripstoneThickness p_154091_, BlockPos source) { // CraftBukkit -+ CatServerCaptures.getCatServerCaptures().captureBlockPos(source); -+ m_154087_(p_154088_, p_154089_, p_154090_, p_154091_); } - - private static void m_154087_(LevelAccessor p_154088_, BlockPos p_154089_, Direction p_154090_, DripstoneThickness p_154091_) { - BlockState blockstate = Blocks.f_152588_.m_49966_().m_61124_(f_154009_, p_154090_).m_61124_(f_154010_, p_154091_).m_61124_(f_154011_, Boolean.valueOf(p_154088_.m_6425_(p_154089_).m_76152_() == Fluids.f_76193_)); -- p_154088_.m_7731_(p_154089_, blockstate, 3); -+ var source = CatServerCaptures.getCatServerCaptures().getCaptureBlockPos(); // CatServer -+ org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.handleBlockSpreadEvent(p_154088_, source, p_154089_, blockstate, 3); // CraftBukkit +@@ -351,6 +_,11 @@ + p_154088_.m_7731_(p_154089_, blockstate, 3); } ++ private static void createDripstone(LevelAccessor p_154088_, BlockPos p_154089_, Direction p_154090_, DripstoneThickness p_154091_, BlockPos source) { // CraftBukkit ++ BlockState blockstate = Blocks.f_152588_.m_49966_().m_61124_(f_154009_, p_154090_).m_61124_(f_154010_, p_154091_).m_61124_(f_154011_, Boolean.valueOf(p_154088_.m_6425_(p_154089_).m_76152_() == Fluids.f_76193_)); ++ org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory.handleBlockSpreadEvent(p_154088_, source, p_154089_, blockstate, 3); // CraftBukkit ++ } ++ private static void m_154230_(BlockState p_154231_, LevelAccessor p_154232_, BlockPos p_154233_) { + BlockPos blockpos; + BlockPos blockpos1; @@ -362,8 +_,8 @@ blockpos1 = p_154233_.m_7495_(); } diff --git a/patches/minecraft/net/minecraft/world/level/block/RedStoneOreBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/RedStoneOreBlock.java.patch index a351c798e..38b40b2f9 100644 --- a/patches/minecraft/net/minecraft/world/level/block/RedStoneOreBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/RedStoneOreBlock.java.patch @@ -1,23 +1,6 @@ --- a/net/minecraft/world/level/block/RedStoneOreBlock.java +++ b/net/minecraft/world/level/block/RedStoneOreBlock.java -@@ -1,6 +_,8 @@ - package net.minecraft.world.level.block; - - import java.util.Random; -+ -+import catserver.server.CatServerCaptures; - import net.minecraft.core.BlockPos; - import net.minecraft.core.Direction; - import net.minecraft.core.particles.DustParticleOptions; -@@ -12,14 +_,14 @@ - import net.minecraft.world.item.BlockItem; - import net.minecraft.world.item.ItemStack; - import net.minecraft.world.item.context.BlockPlaceContext; --import net.minecraft.world.item.enchantment.EnchantmentHelper; --import net.minecraft.world.item.enchantment.Enchantments; - import net.minecraft.world.level.Level; - import net.minecraft.world.level.block.state.BlockBehaviour; - import net.minecraft.world.level.block.state.BlockState; +@@ -20,6 +_,8 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.phys.BlockHitResult; @@ -26,7 +9,7 @@ public class RedStoneOreBlock extends Block { public static final BooleanProperty f_55450_ = RedstoneTorchBlock.f_55674_; -@@ -30,29 +_,54 @@ +@@ -30,20 +_,34 @@ } public void m_6256_(BlockState p_55467_, Level p_55468_, BlockPos p_55469_, Player p_55470_) { @@ -65,18 +48,16 @@ } ItemStack itemstack = p_55475_.m_21120_(p_55476_); - return itemstack.m_41720_() instanceof BlockItem && (new BlockPlaceContext(p_55475_, p_55476_, itemstack, p_55477_)).m_7059_() ? InteractionResult.PASS : InteractionResult.SUCCESS; - } +@@ -52,7 +_,17 @@ -+ private static void interact(BlockState p_55493_, Level p_55494_, BlockPos p_55495_, Entity entity) { // CraftBukkit - add Entity -+ CatServerCaptures.getCatServerCaptures().captureEntity(entity); -+ m_55492_(p_55493_, p_55494_, p_55495_); -+ } -+ private static void m_55492_(BlockState p_55493_, Level p_55494_, BlockPos p_55495_) { m_55454_(p_55494_, p_55495_); ++ p_55494_.m_7731_(p_55495_, p_55493_.m_61124_(f_55450_, Boolean.valueOf(true)), 3); ++ } ++ ++ private static void interact(BlockState p_55493_, Level p_55494_, BlockPos p_55495_, Entity entity) { // CraftBukkit - add Entity ++ m_55454_(p_55494_, p_55495_); if (!p_55493_.m_61143_(f_55450_)) { -+ var entity = CatServerCaptures.getCatServerCaptures().getCaptureEntity(); + // CraftBukkit start + if (CraftEventFactory.callEntityChangeBlockEvent(entity, p_55495_, p_55493_.m_61124_(f_55450_, true)).isCancelled()) { + return; diff --git a/patches/minecraft/net/minecraft/world/level/block/TrapDoorBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/TrapDoorBlock.java.patch index e00b8d170..cc7bb5890 100644 --- a/patches/minecraft/net/minecraft/world/level/block/TrapDoorBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/TrapDoorBlock.java.patch @@ -8,10 +8,11 @@ public class TrapDoorBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock { public static final BooleanProperty f_57514_ = BlockStateProperties.f_61446_; -@@ -106,6 +_,17 @@ +@@ -106,7 +_,38 @@ if (!p_57548_.f_46443_) { boolean flag = p_57548_.m_46753_(p_57549_); if (flag != p_57547_.m_61143_(f_57516_)) { +- if (p_57547_.m_61143_(f_57514_) != flag) { + // CraftBukkit start + org.bukkit.World bworld = p_57548_.getWorld(); + org.bukkit.block.Block bblock = bworld.getBlockAt(p_57549_.m_123341_(), p_57549_.m_123342_(), p_57549_.m_123343_()); @@ -23,9 +24,30 @@ + flag = eventRedstone.getNewCurrent() > 0; + } + // CraftBukkit end - if (p_57547_.m_61143_(f_57514_) != flag) { ++ // CatServer - From Paper 1.19.2 - https://github.com/PaperMC/paper/commit/4f9575eed827007f31ce17da471820fe8bc14573 ++ boolean open = (Boolean) p_57547_.m_61143_(TrapDoorBlock.f_57514_) != flag; // Paper - break redstone on trapdoors early ++ // Paper start - break redstone on trapdoors early ++ // note: this must run before any state for this block/its neighborus are written to the world ++ // we allow the redstone event to fire so that plugins can block ++ if (flag && open) { // if we are now powered and it caused the trap door to open ++ // in this case, first check for the redstone on top first ++ BlockPos abovePos = p_57549_.m_7494_(); ++ BlockState above = p_57548_.m_8055_(abovePos); ++ if (above.m_60734_() instanceof RedStoneWireBlock) { ++ p_57548_.m_7731_(abovePos, Blocks.f_50016_.m_49966_(), Block.f_152394_ | Block.f_152393_); ++ Block.m_49840_(p_57548_, abovePos, new net.minecraft.world.item.ItemStack(net.minecraft.world.item.Items.f_42451_)); ++ // now check that this didn't change our state ++ if (p_57548_.m_8055_(p_57549_) != p_57547_) { ++ // our state was changed, so we cannot propagate this update ++ return; ++ } ++ } ++ } ++ // Paper end - break redstone on trapdoors early ++ if (open) { // Paper - break redstone on trapdoors early p_57547_ = p_57547_.m_61124_(f_57514_, Boolean.valueOf(flag)); this.m_57527_((Player)null, p_57548_, p_57549_, flag); + } @@ -152,4 +_,17 @@ return super.m_7417_(p_57554_, p_57555_, p_57556_, p_57557_, p_57558_, p_57559_); diff --git a/patches/minecraft/net/minecraft/world/level/block/entity/HopperBlockEntity.java.patch b/patches/minecraft/net/minecraft/world/level/block/entity/HopperBlockEntity.java.patch index 7dbe35716..922e4134d 100644 --- a/patches/minecraft/net/minecraft/world/level/block/entity/HopperBlockEntity.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/entity/HopperBlockEntity.java.patch @@ -1,12 +1,10 @@ --- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java -@@ -5,21 +_,24 @@ +@@ -5,21 +_,22 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import javax.annotation.Nullable; + -+import catserver.server.CatServer; -+import catserver.server.CatServerCaptures; +import catserver.server.inventory.CatCustomInventory; +import catserver.server.inventory.CatInventoryUtils; import net.minecraft.core.BlockPos; @@ -172,40 +170,30 @@ }); } else { for(ItemEntity itementity : m_155589_(p_155553_, p_155554_)) { -@@ -193,24 +_,86 @@ - } +@@ -194,15 +_,56 @@ } -+ // CatServer start -+ private static boolean tryTakeInItemFromSlot(Hopper p_59355_, Container p_59356_, int p_59357_, Direction p_59358_, Level level) { -+ CatServerCaptures.getCatServerCaptures().captureLevel(level); -+ return m_59354_(p_59355_, p_59356_, p_59357_, p_59358_); + private static boolean m_59354_(Hopper p_59355_, Container p_59356_, int p_59357_, Direction p_59358_) { ++ // CatServer start ++ Level level; ++ if (p_59355_ instanceof HopperBlockEntity) { ++ level = ((HopperBlockEntity) p_59355_).f_58857_; ++ } else if (p_59355_ instanceof MinecartHopper) { ++ level = ((MinecartHopper) p_59355_).f_19853_; ++ } else { ++ level = net.minecraft.server.MinecraftServer.getServer().m_129783_(); ++ } ++ return tryTakeInItemFromSlot(p_59355_, p_59356_, p_59357_, p_59358_, level); ++ // CatServer end + } + - private static boolean m_59354_(Hopper p_59355_, Container p_59356_, int p_59357_, Direction p_59358_) { ++ private static boolean tryTakeInItemFromSlot(Hopper p_59355_, Container p_59356_, int p_59357_, Direction p_59358_, Level level) { ItemStack itemstack = p_59356_.m_8020_(p_59357_); if (!itemstack.m_41619_() && m_59380_(p_59356_, itemstack, p_59357_, p_59358_)) { ItemStack itemstack1 = itemstack.m_41777_(); - ItemStack itemstack2 = m_59326_(p_59356_, p_59355_, p_59356_.m_7407_(p_59357_, 1), (Direction)null); + // CraftBukkit start - Call event on collection of items from inventories into the hopper -+ -+ // CatServer start - add a null check -+ Level world = CatServerCaptures.getCatServerCaptures().getCaptureLevel(); -+ int hopperAmount = 0; -+ int hopperTransfer = 0; -+ if (world != null) { -+ hopperAmount = world.spigotConfig.hopperAmount; -+ hopperTransfer = world.spigotConfig.hopperTransfer; -+ } else { -+ hopperAmount = 1; -+ hopperTransfer = 8; -+ CatServer.LOGGER.warn("[CatServer]: It is detected that the Level is null, and the hopperAmount is set to 1 by default"); -+ CatServer.LOGGER.warn("[CatServer]: If you see this message, Spigot is not working properly, please report it to the developer!"); -+ CatServer.LOGGER.warn("[CatServer]: Class location: {}", HopperBlockEntity.class.getName()); -+ } -+ // CatServer end -+ -+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(p_59356_.m_7407_(p_59357_, hopperAmount)); ++ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(p_59356_.m_7407_(p_59357_, level.spigotConfig.hopperAmount)); + org.bukkit.inventory.Inventory sourceInventory; + // Have to special case large chests as they work oddly + if (p_59356_ instanceof CompoundContainer) { @@ -222,9 +210,9 @@ + if (event.isCancelled()) { + p_59356_.m_6836_(p_59357_, itemstack1); + if (p_59355_ instanceof HopperBlockEntity) { -+ ((HopperBlockEntity) p_59355_).m_59395_(hopperTransfer); // Spigot ++ ((HopperBlockEntity) p_59355_).m_59395_(level.spigotConfig.hopperTransfer); // Spigot + } else if (p_59355_ instanceof MinecartHopper) { -+ ((MinecartHopper) p_59355_).m_38610_(hopperTransfer / 2); // Spigot ++ ((MinecartHopper) p_59355_).m_38610_(level.spigotConfig.hopperTransfer / 2); // Spigot + } + return false; + } @@ -240,9 +228,7 @@ p_59356_.m_6836_(p_59357_, itemstack1); } - return false; - } -+ // CatServer end +@@ -211,6 +_,17 @@ public static boolean m_59331_(Container p_59332_, ItemEntity p_59333_) { boolean flag = false; @@ -281,6 +267,14 @@ } } +@@ -320,6 +_,7 @@ + private static Container m_59347_(Level p_59348_, double p_59349_, double p_59350_, double p_59351_) { + Container container = null; + BlockPos blockpos = new BlockPos(p_59349_, p_59350_, p_59351_); ++ if ( !p_59348_.m_46805_( blockpos ) ) return null; // Spigot + BlockState blockstate = p_59348_.m_8055_(blockpos); + Block block = blockstate.m_60734_(); + if (block instanceof WorldlyContainerHolder) { @@ -399,5 +_,14 @@ protected AbstractContainerMenu m_6555_(int p_59312_, Inventory p_59313_) { diff --git a/patches/minecraft/net/minecraft/world/level/chunk/ChunkAccess.java.patch b/patches/minecraft/net/minecraft/world/level/chunk/ChunkAccess.java.patch index d9204b2df..b228a552f 100644 --- a/patches/minecraft/net/minecraft/world/level/chunk/ChunkAccess.java.patch +++ b/patches/minecraft/net/minecraft/world/level/chunk/ChunkAccess.java.patch @@ -29,11 +29,10 @@ } private static void m_187634_(LevelHeightAccessor p_187635_, Registry p_187636_, LevelChunkSection[] p_187637_) { -@@ -247,12 +_,29 @@ - } +@@ -248,11 +_,29 @@ public void m_8092_(boolean p_62094_) { -- this.f_187603_ = p_62094_; + this.f_187603_ = p_62094_; + if (!p_62094_) this.persistentDataContainer.dirty(false); // CraftBukkit - SPIGOT-6814: chunk was saved, pdc is no longer dirty } diff --git a/patches/minecraft/net/minecraft/world/level/chunk/LevelChunk.java.patch b/patches/minecraft/net/minecraft/world/level/chunk/LevelChunk.java.patch index 51368d330..5cb86fa12 100644 --- a/patches/minecraft/net/minecraft/world/level/chunk/LevelChunk.java.patch +++ b/patches/minecraft/net/minecraft/world/level/chunk/LevelChunk.java.patch @@ -53,13 +53,20 @@ } public TickContainerAccess m_183531_() { -@@ -206,6 +_,12 @@ +@@ -206,6 +_,19 @@ } @Nullable + public BlockState setBlockState(BlockPos p_62865_, BlockState p_62866_, boolean p_62867_, boolean doPlace) { ++ // CatServer start + catserver.server.CatServerCaptures.getCatServerCaptures().captureDoPlace(doPlace); -+ return m_6978_(p_62865_, p_62866_, p_62867_); ++ try { ++ return m_6978_(p_62865_, p_62866_, p_62867_); ++ } finally { ++ // CatServer - Make sure reset ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureDoPlace(); ++ } ++ // CatServer end + } + + @Nullable diff --git a/patches/minecraft/net/minecraft/world/level/portal/PortalForcer.java.patch b/patches/minecraft/net/minecraft/world/level/portal/PortalForcer.java.patch index 0e64e1a27..eadf0b8dd 100644 --- a/patches/minecraft/net/minecraft/world/level/portal/PortalForcer.java.patch +++ b/patches/minecraft/net/minecraft/world/level/portal/PortalForcer.java.patch @@ -1,15 +1,14 @@ --- a/net/minecraft/world/level/portal/PortalForcer.java +++ b/net/minecraft/world/level/portal/PortalForcer.java -@@ -2,6 +_,8 @@ +@@ -2,6 +_,7 @@ import java.util.Comparator; import java.util.Optional; + -+import catserver.server.CatServerCaptures; import net.minecraft.BlockUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -@@ -19,163 +_,187 @@ +@@ -19,163 +_,193 @@ import net.minecraft.world.level.border.WorldBorder; import net.minecraft.world.level.levelgen.Heightmap; @@ -224,15 +223,20 @@ + } + + public Optional createPortal(BlockPos p_77667_, Direction.Axis p_77668_, net.minecraft.world.entity.Entity entity, int createRadius) { -+ CatServerCaptures.getCatServerCaptures().captureEntity(entity); -+ CatServerCaptures.getCatServerCaptures().capturePortalRadius(createRadius); -+ return m_77666_(p_77667_, p_77668_); ++ // CatServer start ++ catserver.server.CatServerCaptures.getCatServerCaptures().captureEntity(entity); ++ catserver.server.CatServerCaptures.getCatServerCaptures().capturePortalRadius(createRadius); ++ try { ++ return m_77666_(p_77667_, p_77668_); ++ } finally { ++ // CatServer - Make sure reset ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureEntity(); ++ catserver.server.CatServerCaptures.getCatServerCaptures().getCapturePortalRadius(); ++ } ++ // CatServer end + } + + public Optional m_77666_(BlockPos p_77667_, Direction.Axis p_77668_) { -+ var entity = CatServerCaptures.getCatServerCaptures().getCaptureEntity() == null ? null : CatServerCaptures.getCatServerCaptures().getCaptureEntity(); -+ var createRadius = CatServerCaptures.getCatServerCaptures().getCapturePortalRadius(); -+ if (createRadius == 0) createRadius = 16; + Direction direction = Direction.m_122390_(Direction.AxisDirection.POSITIVE, p_77668_); + double d0 = -1.0D; + BlockPos blockpos = null; @@ -242,7 +246,7 @@ + int i = Math.min(this.f_77648_.m_151558_(), this.f_77648_.m_141937_() + this.f_77648_.m_143344_()) - 1; + BlockPos.MutableBlockPos blockpos$mutableblockpos = p_77667_.m_122032_(); + -+ for (BlockPos.MutableBlockPos blockpos$mutableblockpos1 : BlockPos.m_121935_(p_77667_, createRadius, Direction.EAST, Direction.SOUTH)) { // CraftBukkit ++ for (BlockPos.MutableBlockPos blockpos$mutableblockpos1 : BlockPos.m_121935_(p_77667_, catserver.server.CatServerCaptures.getCatServerCaptures().getCapturePortalRadius(), Direction.EAST, Direction.SOUTH)) { // CraftBukkit // CatServer + int j = Math.min(i, this.f_77648_.m_6924_(Heightmap.Types.MOTION_BLOCKING, blockpos$mutableblockpos1.m_123341_(), blockpos$mutableblockpos1.m_123343_())); + int k = 1; + if (worldborder.m_61937_(blockpos$mutableblockpos1) && worldborder.m_61937_(blockpos$mutableblockpos1.m_122175_(direction, 1))) { @@ -325,6 +329,7 @@ + blockList.m_7731_(blockpos$mutableblockpos, blockstate, 18); // CraftBukkit + } + } ++ var entity = catserver.server.CatServerCaptures.getCatServerCaptures().getCaptureEntity(); // CatServer + // CraftBukkit start + org.bukkit.World bworld = this.f_77648_.getWorld(); + org.bukkit.event.world.PortalCreateEvent event = new org.bukkit.event.world.PortalCreateEvent((java.util.List) (java.util.List) blockList.getList(), bworld, (entity == null) ? null : entity.getBukkitEntity(), org.bukkit.event.world.PortalCreateEvent.CreateReason.NETHER_PAIR); diff --git a/server_files/args.txt b/server_files/args.txt index 6dd9824f3..84df94b0e 100644 --- a/server_files/args.txt +++ b/server_files/args.txt @@ -1,6 +1,7 @@ -p @MODULE_PATH@ --add-modules @MODULES@ --add-opens java.base/java.util.jar=cpw.mods.securejarhandler +--add-opens java.base/java.lang.invoke=cpw.mods.securejarhandler --add-exports java.base/sun.security.util=cpw.mods.securejarhandler --add-exports jdk.naming.dns/com.sun.jndi.dns=java.naming -Djava.net.preferIPv6Addresses=system diff --git a/spigot-patches/CraftBukkit-Patches/0051-Prevent-hoppers-from-loading-chunks.patch b/spigot-patches/CraftBukkit-Patches/0051-Prevent-hoppers-from-loading-chunks.patch deleted file mode 100644 index cc5faa286..000000000 --- a/spigot-patches/CraftBukkit-Patches/0051-Prevent-hoppers-from-loading-chunks.patch +++ /dev/null @@ -1,21 +0,0 @@ -From ceac742ade72e7b0191c2299d69bd3657dd57053 Mon Sep 17 00:00:00 2001 -From: Thinkofdeath -Date: Wed, 5 Mar 2014 20:27:27 +0000 -Subject: [PATCH] Prevent hoppers from loading chunks - - -diff --git a/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java -index 92f93542c..d8db5d531 100644 ---- a/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java -+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java -@@ -465,6 +465,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper { - private static IInventory getContainerAt(World world, double d0, double d1, double d2) { - Object object = null; - BlockPosition blockposition = new BlockPosition(d0, d1, d2); -+ if ( !world.hasChunkAt( blockposition ) ) return null; // Spigot - IBlockData iblockdata = world.getBlockState(blockposition); - Block block = iblockdata.getBlock(); - --- -2.25.1 - diff --git a/src/main/java/catserver/server/BukkitInjector.java b/src/main/java/catserver/server/BukkitInjector.java index 163339457..98245783e 100644 --- a/src/main/java/catserver/server/BukkitInjector.java +++ b/src/main/java/catserver/server/BukkitInjector.java @@ -5,7 +5,11 @@ import catserver.server.entity.CraftCustomEntity; import catserver.server.utils.EnumHelper; import com.google.common.base.Preconditions; -import com.google.common.collect.*; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; import io.izzel.arclight.api.Unsafe; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; @@ -14,16 +18,20 @@ import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.decoration.Motive; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.Potions; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.dimension.LevelStem; +import net.minecraftforge.fml.util.ObfuscationReflectionHelper; import net.minecraftforge.registries.ForgeRegistries; +import org.bukkit.Art; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.Statistic; import org.bukkit.World; +import org.bukkit.attribute.Attribute; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_18_R2.CraftStatistic; import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; @@ -40,12 +48,22 @@ import org.jetbrains.annotations.Contract; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; public class BukkitInjector { public static BiMap, World.Environment> environments = HashBiMap.create(ImmutableMap., World.Environment>builder().put(LevelStem.OVERWORLD, World.Environment.NORMAL).put(LevelStem.NETHER, World.Environment.NETHER).put(LevelStem.END, World.Environment.THE_END).build()); + public static Map professionMap = new HashMap<>(); + public static Map attributeToNameMap = new HashMap<>(); + public static Map nameToAttributeMap = new HashMap<>(); + public static Map artMap = new HashMap<>(); + public static void registerAll() { registerMaterials(); registerEnchantments(); @@ -55,6 +73,8 @@ public static void registerAll() { registerVillagerProfessions(); registerStatistics(); registerSpawnCategory(); + registerArts(); + registerAttribute(); try { for (var field : org.bukkit.Registry.class.getFields()) { if (Modifier.isStatic(field.getModifiers()) && field.get(null) instanceof org.bukkit.Registry.SimpleRegistry registry) { @@ -65,6 +85,50 @@ public static void registerAll() { } } + private static void registerAttribute() { + int length = Attribute.values().length; + List attributes = Lists.newArrayList(); + for (var attribute : ForgeRegistries.ATTRIBUTES) { + ResourceLocation location = attribute.getRegistryName(); + String name = standardize(location); + if (Objects.equals(location.getNamespace(), NamespacedKey.MINECRAFT)) { + continue; + } + Attribute bukkitAttribute = EnumHelper.makeEnum(org.bukkit.attribute.Attribute.class, name, length++, ImmutableList.of(NamespacedKey.class), ImmutableList.of(CraftNamespacedKey.fromMinecraft(location))); + attributes.add(bukkitAttribute); + attributeToNameMap.put(bukkitAttribute, location); + nameToAttributeMap.put(location, bukkitAttribute); + CatServer.LOGGER.debug("Save-Attribute: {}", name); + } + EnumHelper.addEnums(Attribute.class, attributes); + CatServer.LOGGER.info("Registered {} Attribute into Bukkit", attributes.size()); + } + + private static void registerArts() { + int length = Art.values().length; + List arts = Lists.newArrayList(); + HashMap BY_NAME = ObfuscationReflectionHelper.getPrivateValue(Art.class, null, "BY_NAME"); + HashMap BY_ID = ObfuscationReflectionHelper.getPrivateValue(Art.class, null, "BY_ID"); + for (Motive motive : ForgeRegistries.PAINTING_TYPES) { + var width = motive.getWidth(); + var height = motive.getHeight(); + ResourceLocation location = motive.getRegistryName(); + if (Objects.equals(location.getNamespace(), NamespacedKey.MINECRAFT)) { + continue; + } + var motiveName = standardize(location); + int id = length - 1; + Art art = EnumHelper.makeEnum(Art.class, motiveName, length++, ImmutableList.of(Integer.TYPE, Integer.TYPE, Integer.TYPE), ImmutableList.of(id, width, height)); + arts.add(art); + artMap.put(motive, art); + BY_NAME.put(motiveName, art); + BY_ID.put(id, art); + CatServer.LOGGER.debug("Save-Art: {}", motiveName); + } + EnumHelper.addEnums(Art.class, arts); + CatServer.LOGGER.info("Registered {} Art into Bukkit", arts.size()); + } + private static void registerSpawnCategory() { int i = SpawnCategory.values().length; List categories = Lists.newArrayList(); @@ -164,6 +228,7 @@ private static void registerVillagerProfessions() { } var newPfName = standardize(location); var bukkitProfessions = EnumHelper.makeEnum(Villager.Profession.class, newPfName, i++, ImmutableList.of(), ImmutableList.of()); + professionMap.put(bukkitProfessions, location); professions.add(bukkitProfessions); CatServer.LOGGER.debug("Save-VillagerProfessions: {}", bukkitProfessions.name()); } diff --git a/src/main/java/catserver/server/CatServerCaptures.java b/src/main/java/catserver/server/CatServerCaptures.java index b2c7e441f..ec6800ce4 100644 --- a/src/main/java/catserver/server/CatServerCaptures.java +++ b/src/main/java/catserver/server/CatServerCaptures.java @@ -1,230 +1,132 @@ package catserver.server; -import com.google.common.util.concurrent.AtomicDouble; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - public class CatServerCaptures { - private static final CatServerCaptures catServerCaptures = new CatServerCaptures(); - private AtomicReference entity = new AtomicReference<>(); - private AtomicReference itemEntity = new AtomicReference<>(); - private AtomicReference spawnReason = new AtomicReference<>(); - private AtomicBoolean doPlace = new AtomicBoolean(true); - private AtomicInteger spawnerLimit = new AtomicInteger(); - private AtomicInteger createPortalRadius = new AtomicInteger(); - private AtomicReference blockPos = new AtomicReference<>(); - private AtomicReference itemstack = new AtomicReference<>(); - private AtomicReference changeDimCause = new AtomicReference<>(); - private AtomicInteger searchPortalRadius = new AtomicInteger(); - private AtomicBoolean canCreatePortal = new AtomicBoolean(); - private AtomicBoolean isForceSleep = new AtomicBoolean(false); - private AtomicBoolean isCallEvent = new AtomicBoolean(true); - private AtomicBoolean isSilent = new AtomicBoolean(false); - private AtomicReference direction = new AtomicReference<>(); - private AtomicReference blockState = new AtomicReference<>(); - private AtomicReference serverPlayer = new AtomicReference<>(); - private AtomicReference level = new AtomicReference<>(); - private AtomicDouble blockRange = new AtomicDouble(); - private AtomicBoolean dropper = new AtomicBoolean(false); - private AtomicReference regainReason = new AtomicReference<>(EntityRegainHealthEvent.RegainReason.CUSTOM); - private AtomicReference potionEffectCause = new AtomicReference<>(EntityPotionEffectEvent.Cause.UNKNOWN); - private AtomicReference teleportCause = new AtomicReference<>(PlayerTeleportEvent.TeleportCause.UNKNOWN); - private AtomicBoolean arrowFlag = new AtomicBoolean(false); - - public void captureTeleportCause(PlayerTeleportEvent.TeleportCause cause) { - this.teleportCause.set(cause); - } - - public void captureArrowFlag(boolean flag) { - this.arrowFlag.set(flag); - } - - public void capturePotionEffectCause(EntityPotionEffectEvent.Cause cause) { - this.potionEffectCause.set(cause); - } - - public void captureRegainReason(EntityRegainHealthEvent.RegainReason regainReason) { - this.regainReason.set(regainReason); - } + private static final ThreadLocal catServerCaptures = new ThreadLocal<>(); + private Entity entity = null; + private ItemEntity itemEntity = null; + private CreatureSpawnEvent.SpawnReason spawnReason = null; + private boolean doPlace = true; + private int createPortalRadius = 16; + private BlockPos blockPos = null; + private ItemStack itemstack = null; + private Direction direction = null; + private PlayerTeleportEvent.TeleportCause changeDimCause = PlayerTeleportEvent.TeleportCause.UNKNOWN; + private PlayerTeleportEvent.TeleportCause teleportCause = PlayerTeleportEvent.TeleportCause.UNKNOWN; - public void captureDropper(boolean dropper) { - this.dropper.set(dropper); - } - - public void captureBlockRange(double d) { - this.blockRange.set(d); + public static CatServerCaptures getCatServerCaptures() { + CatServerCaptures currentThreadCaptures = catServerCaptures.get(); + if (currentThreadCaptures == null) { + currentThreadCaptures = new CatServerCaptures(); + catServerCaptures.set(currentThreadCaptures); + } + return currentThreadCaptures; } public void captureEntity(Entity entity) { - this.entity.set(entity); - } - - public void captureServerPlayer(ServerPlayer player) { - this.serverPlayer.set(player); + this.entity = entity; } public Entity getCaptureEntity() { - return this.entity.getAndSet(null); - } - - public void captureSpawnReason(CreatureSpawnEvent.SpawnReason spawnReason) { - this.spawnReason.set(spawnReason); - } - - public void captureSpawnerLimit(int i) { - this.spawnerLimit.set(i); + var result = this.entity; + this.entity = null; + return result; } - public void capturePortalRadius(int i) { - this.createPortalRadius.set(i); - } - - public void captureBlockPos(BlockPos pos) { - this.blockPos.set(pos); - } - public void captureItemStack(ItemStack itemstack) { - this.itemstack.set(itemstack); - } - public void captureDirection(Direction direction) { - this.direction.set(direction); - } - - public void captureChangeDimCause(PlayerTeleportEvent.TeleportCause cause) { - this.changeDimCause.set(cause); - } - - public void capturePortalSearchRadius(int i) { - this.searchPortalRadius.set(i); - } - - public void captureCanCreatePortal(boolean value) { - this.canCreatePortal.set(value); - } - public void captureIsForceSleep(boolean value) { - this.isForceSleep.set(value); - } - public void captureIsCallEvent(boolean value) { - this.isCallEvent.set(value); - } - public void captureIsSlient(boolean isSlient) { - this.isSilent.set(isSlient); - } - public void captureBlockState(BlockState blockState) { - this.blockState.set(blockState); - } public void captureItemEntity(ItemEntity itemEntity) { - this.itemEntity.set(itemEntity); - } - public void captureDoPlace(boolean doPlace) { - this.doPlace.set(doPlace); - } - public void captureLevel(Level level) { - this.level.set(level); + this.itemEntity = itemEntity; } - public EntityRegainHealthEvent.RegainReason getCaptureRegainReason() { - return this.regainReason.getAndSet(EntityRegainHealthEvent.RegainReason.CUSTOM); + public ItemEntity getCaptureItemEntity() { + var result = this.itemEntity; + this.itemEntity = null; + return result; } - public Level getCaptureLevel() { - return this.level.getAndSet(null); + public void captureSpawnReason(CreatureSpawnEvent.SpawnReason spawnReason) { + this.spawnReason = spawnReason; } public CreatureSpawnEvent.SpawnReason getCaptureSpawnReason() { - return this.spawnReason.getAndSet(null); + var result = this.spawnReason; + this.spawnReason = null; + return result; } - public boolean getCaptureDoPlace() { - return this.doPlace.getAndSet(true); + public void captureDoPlace(boolean doPlace) { + this.doPlace = doPlace; } - public int getCaptureLimit() { - return this.spawnerLimit.getAndSet(0); + public boolean getCaptureDoPlace() { + var result = this.doPlace; + this.doPlace = true; + return result; } - public BlockState getCaptureBlockState() { - return this.blockState.getAndSet(null); + public void capturePortalRadius(int i) { + this.createPortalRadius = i; } public int getCapturePortalRadius() { - return this.createPortalRadius.getAndSet(0); - } - - public BlockPos getCaptureBlockPos() { - return this.blockPos.getAndSet(null); - } - - public ItemStack getCaptureItemStack() { - return this.itemstack.getAndSet(null); - } - - public Direction getCaptureDirection() { - return this.direction.getAndSet(null); + var result = this.createPortalRadius; + this.createPortalRadius = 16; + return result; } - public PlayerTeleportEvent.TeleportCause getCaptureChangeDimCause() { - return this.changeDimCause.getAndSet(null); + public void captureTeleportCause(PlayerTeleportEvent.TeleportCause cause) { + this.teleportCause = cause; } - public int getCapturePortalSearchRadius() { - return this.searchPortalRadius.getAndSet(0); + public PlayerTeleportEvent.TeleportCause getCaptureTeleportCause() { + var result = this.teleportCause; + this.teleportCause = PlayerTeleportEvent.TeleportCause.UNKNOWN; + return result; } - public boolean getCaptureCanCreatePortal() { - return this.canCreatePortal.getAndSet(false); + public void captureBlockPos(BlockPos pos) { + this.blockPos = pos; } - public boolean getCaptureIsForceSleep() { - return this.isForceSleep.getAndSet(false); + public BlockPos getCaptureBlockPos() { + var result = this.blockPos; + this.blockPos = null; + return result; } - public boolean getCaptureIsCallEvent() { - return this.isCallEvent.getAndSet(true); - } - public boolean getCaptureIsSlient() { - return this.isSilent.getAndSet(false); - } - public ItemEntity getCaptureItemEntity() { - return this.itemEntity.getAndSet(null); - } - public ServerPlayer getCaptureServerPlayer() { - return this.serverPlayer.getAndSet(null); - } - public double getCaptureBlockRange() { - return this.blockRange.getAndSet(0.0D); + public void captureItemStack(ItemStack itemstack) { + this.itemstack = itemstack; } - public boolean getCaptureDropper() { - return this.dropper.getAndSet(false); + public ItemStack getCaptureItemStack() { + var result = this.itemstack; + this.itemstack = null; + return result; } - public EntityPotionEffectEvent.Cause getCapturePotionEffectCause() { - return this.potionEffectCause.getAndSet(EntityPotionEffectEvent.Cause.UNKNOWN); + public void captureDirection(Direction direction) { + this.direction = direction; } - public boolean getCaptureArrowFlag() { - return this.arrowFlag.getAndSet(false); + public Direction getCaptureDirection() { + var result = this.direction; + this.direction = null; + return result; } - public PlayerTeleportEvent.TeleportCause getCaptureTeleportCause() { - return this.teleportCause.getAndSet(PlayerTeleportEvent.TeleportCause.UNKNOWN); + public void captureChangeDimCause(PlayerTeleportEvent.TeleportCause cause) { + this.changeDimCause = cause; } - public static CatServerCaptures getCatServerCaptures() { - return catServerCaptures; + public PlayerTeleportEvent.TeleportCause getCaptureChangeDimCause() { + var result = this.changeDimCause; + this.changeDimCause = PlayerTeleportEvent.TeleportCause.UNKNOWN; + return result; } } diff --git a/src/main/java/catserver/server/utils/CatServerCallbackExecutor.java b/src/main/java/catserver/server/utils/CatServerCallbackExecutor.java index 85a51bc91..3c0db5895 100644 --- a/src/main/java/catserver/server/utils/CatServerCallbackExecutor.java +++ b/src/main/java/catserver/server/utils/CatServerCallbackExecutor.java @@ -1,23 +1,20 @@ package catserver.server.utils; +import java.util.LinkedList; import java.util.concurrent.Executor; public class CatServerCallbackExecutor implements Executor, Runnable { - private Runnable queued; + private final LinkedList queued = new LinkedList<>(); @Override public void execute(Runnable runnable) { - if (queued != null) { - throw new IllegalStateException("Already queued"); - } - queued = runnable; + queued.add(runnable); } @Override public void run() { - Runnable task = queued; - queued = null; - if (task != null) { + Runnable task; + while ((task = queued.pollFirst()) != null) { task.run(); } } diff --git a/src/main/java/org/bukkit/attribute/Attribute.java b/src/main/java/org/bukkit/attribute/Attribute.java index 13eac9ad2..c8c283272 100644 --- a/src/main/java/org/bukkit/attribute/Attribute.java +++ b/src/main/java/org/bukkit/attribute/Attribute.java @@ -68,6 +68,12 @@ private Attribute(String key) { this.key = NamespacedKey.minecraft(key); } + // CatServer start + private Attribute(NamespacedKey key) { + this.key = key; + } + // CatServer end + @NotNull @Override public NamespacedKey getKey() { diff --git a/src/main/java/org/bukkit/craftbukkit/v1_18_R2/CraftArt.java b/src/main/java/org/bukkit/craftbukkit/v1_18_R2/CraftArt.java index 56fb67c2f..9a19c31d1 100644 --- a/src/main/java/org/bukkit/craftbukkit/v1_18_R2/CraftArt.java +++ b/src/main/java/org/bukkit/craftbukkit/v1_18_R2/CraftArt.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.v1_18_R2; +import catserver.server.BukkitInjector; import com.google.common.base.Preconditions; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; @@ -7,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.decoration.Motive; import org.bukkit.Art; +import org.bukkit.NamespacedKey; public class CraftArt { private static final BiMap artwork; @@ -14,7 +16,13 @@ public class CraftArt { static { ImmutableBiMap.Builder artworkBuilder = ImmutableBiMap.builder(); for (ResourceLocation key : Registry.MOTIVE.keySet()) { - artworkBuilder.put(Registry.MOTIVE.get(key), Art.getByName(key.getPath())); + // CatServer start + if (key.getNamespace().equals(NamespacedKey.MINECRAFT)) { + artworkBuilder.put(Registry.MOTIVE.get(key), Art.getByName(key.getPath())); + } else { + BukkitInjector.artMap.forEach(artworkBuilder::put); + } + // CatServer end } artwork = artworkBuilder.build(); diff --git a/src/main/java/org/bukkit/craftbukkit/v1_18_R2/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/v1_18_R2/CraftWorld.java index 5581f18c4..8e89dcd20 100644 --- a/src/main/java/org/bukkit/craftbukkit/v1_18_R2/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/v1_18_R2/CraftWorld.java @@ -461,7 +461,7 @@ public org.bukkit.entity.Item dropItem(Location loc, ItemStack item, Consumer T getObject(Class clazz, Map map, Object field, boolean null private static final Set HANDLED_TAGS = Sets.newHashSet(); private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); + // CatServer start + private static final Set CUSTOM_TAGS = Sets.newHashSet(); + public static Set getCustomTags() { + synchronized (CUSTOM_TAGS) { + if (CUSTOM_TAGS.isEmpty()) { + CUSTOM_TAGS.addAll(Arrays.asList(CraftMetaMap.MAP_SCALING.NBT, CraftMetaMap.MAP_ID.NBT, CraftMetaPotion.POTION_EFFECTS.NBT, CraftMetaPotion.DEFAULT_POTION.NBT, CraftMetaPotion.POTION_COLOR.NBT, CraftMetaSkull.SKULL_OWNER.NBT, CraftMetaSkull.SKULL_PROFILE.NBT, CraftMetaSpawnEgg.ENTITY_TAG.NBT, CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT, CraftMetaBook.BOOK_TITLE.NBT, CraftMetaBook.BOOK_AUTHOR.NBT, CraftMetaBook.BOOK_PAGES.NBT, CraftMetaBook.RESOLVED.NBT, CraftMetaBook.GENERATION.NBT, CraftMetaFirework.FIREWORKS.NBT, CraftMetaEnchantedBook.STORED_ENCHANTMENTS.NBT, CraftMetaCharge.EXPLOSION.NBT, CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT, CraftMetaKnowledgeBook.BOOK_RECIPES.NBT, CraftMetaTropicalFishBucket.VARIANT.NBT, CraftMetaCrossbow.CHARGED.NBT, CraftMetaCrossbow.CHARGED_PROJECTILES.NBT, CraftMetaSuspiciousStew.EFFECTS.NBT, CraftMetaCompass.LODESTONE_DIMENSION.NBT, CraftMetaCompass.LODESTONE_POS.NBT, CraftMetaCompass.LODESTONE_TRACKED.NBT)); + } + return CUSTOM_TAGS; + } + } + // CatServer end private CompoundTag internalTag; final Map unhandledTags = new HashMap(); // Visible for testing only @@ -377,6 +388,13 @@ static T getObject(Class clazz, Map map, Object field, boolean null if (!getHandledTags().contains(key)) { unhandledTags.put(key, tag.get(key).copy()); } + // CatServer start - handle mod custom nbt + else { + if (getClass() == CraftMetaItem.class && getCustomTags().contains(key)) { + unhandledTags.put(key, tag.get(key)); + } + } + // CatServer end } } @@ -520,6 +538,13 @@ static Multimap buildModifiers(CompoundTag tag, It if (!getHandledTags().contains(key)) { unhandledTags.put(key, internalTag.get(key)); } + // CatServer start - handle mod custom nbt + else { + if (getClass() == CraftMetaItem.class && getCustomTags().contains(key)) { + unhandledTags.put(key, internalTag.get(key)); + } + } + // CatServer end } } catch (IOException ex) { Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 65c91a76a..d422d627d 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -562,6 +562,10 @@ public void clearPlugins() { public void callEvent(@NotNull Event event) { // CatServer start if (event.isAsynchronous() || !server.isPrimaryThread()) { + // CatServer - Thread safety check + if (!event.isAsynchronous() && Thread.currentThread() instanceof java.util.concurrent.ForkJoinWorkerThread) { + catserver.server.CatServer.LOGGER.debug("Call event at worker thread!", new RuntimeException()); + } if (Thread.holdsLock(this)) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from inside synchronized code."); }