Deleted old
This commit is contained in:
parent
49f3990eee
commit
e306fdce7d
32
old/Jenkinsfile
vendored
32
old/Jenkinsfile
vendored
|
|
@ -1,32 +0,0 @@
|
||||||
#!/usr/bin/env groovy
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
tools {
|
|
||||||
jdk "jdk-17.0.1"
|
|
||||||
}
|
|
||||||
stages {
|
|
||||||
stage('Clean') {
|
|
||||||
steps {
|
|
||||||
withCredentials([file(credentialsId: 'mod_build_secrets', variable: 'ORG_GRADLE_PROJECT_secretFile')]) {
|
|
||||||
echo 'Cleaning Project'
|
|
||||||
sh 'chmod +x gradlew'
|
|
||||||
sh './gradlew clean'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Build and Deploy') {
|
|
||||||
steps {
|
|
||||||
withCredentials([file(credentialsId: 'mod_build_secrets', variable: 'ORG_GRADLE_PROJECT_secretFile')]) {
|
|
||||||
echo 'Building and Deploying to Maven'
|
|
||||||
sh './gradlew build publish'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
archive 'build/libs/**.jar'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
165
old/LICENSE
165
old/LICENSE
|
|
@ -1,165 +0,0 @@
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
|
|
||||||
This version of the GNU Lesser General Public License incorporates
|
|
||||||
the terms and conditions of version 3 of the GNU General Public
|
|
||||||
License, supplemented by the additional permissions listed below.
|
|
||||||
|
|
||||||
0. Additional Definitions.
|
|
||||||
|
|
||||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
||||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
||||||
General Public License.
|
|
||||||
|
|
||||||
"The Library" refers to a covered work governed by this License,
|
|
||||||
other than an Application or a Combined Work as defined below.
|
|
||||||
|
|
||||||
An "Application" is any work that makes use of an interface provided
|
|
||||||
by the Library, but which is not otherwise based on the Library.
|
|
||||||
Defining a subclass of a class defined by the Library is deemed a mode
|
|
||||||
of using an interface provided by the Library.
|
|
||||||
|
|
||||||
A "Combined Work" is a work produced by combining or linking an
|
|
||||||
Application with the Library. The particular version of the Library
|
|
||||||
with which the Combined Work was made is also called the "Linked
|
|
||||||
Version".
|
|
||||||
|
|
||||||
The "Minimal Corresponding Source" for a Combined Work means the
|
|
||||||
Corresponding Source for the Combined Work, excluding any source code
|
|
||||||
for portions of the Combined Work that, considered in isolation, are
|
|
||||||
based on the Application, and not on the Linked Version.
|
|
||||||
|
|
||||||
The "Corresponding Application Code" for a Combined Work means the
|
|
||||||
object code and/or source code for the Application, including any data
|
|
||||||
and utility programs needed for reproducing the Combined Work from the
|
|
||||||
Application, but excluding the System Libraries of the Combined Work.
|
|
||||||
|
|
||||||
1. Exception to Section 3 of the GNU GPL.
|
|
||||||
|
|
||||||
You may convey a covered work under sections 3 and 4 of this License
|
|
||||||
without being bound by section 3 of the GNU GPL.
|
|
||||||
|
|
||||||
2. Conveying Modified Versions.
|
|
||||||
|
|
||||||
If you modify a copy of the Library, and, in your modifications, a
|
|
||||||
facility refers to a function or data to be supplied by an Application
|
|
||||||
that uses the facility (other than as an argument passed when the
|
|
||||||
facility is invoked), then you may convey a copy of the modified
|
|
||||||
version:
|
|
||||||
|
|
||||||
a) under this License, provided that you make a good faith effort to
|
|
||||||
ensure that, in the event an Application does not supply the
|
|
||||||
function or data, the facility still operates, and performs
|
|
||||||
whatever part of its purpose remains meaningful, or
|
|
||||||
|
|
||||||
b) under the GNU GPL, with none of the additional permissions of
|
|
||||||
this License applicable to that copy.
|
|
||||||
|
|
||||||
3. Object Code Incorporating Material from Library Header Files.
|
|
||||||
|
|
||||||
The object code form of an Application may incorporate material from
|
|
||||||
a header file that is part of the Library. You may convey such object
|
|
||||||
code under terms of your choice, provided that, if the incorporated
|
|
||||||
material is not limited to numerical parameters, data structure
|
|
||||||
layouts and accessors, or small macros, inline functions and templates
|
|
||||||
(ten or fewer lines in length), you do both of the following:
|
|
||||||
|
|
||||||
a) Give prominent notice with each copy of the object code that the
|
|
||||||
Library is used in it and that the Library and its use are
|
|
||||||
covered by this License.
|
|
||||||
|
|
||||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
||||||
document.
|
|
||||||
|
|
||||||
4. Combined Works.
|
|
||||||
|
|
||||||
You may convey a Combined Work under terms of your choice that,
|
|
||||||
taken together, effectively do not restrict modification of the
|
|
||||||
portions of the Library contained in the Combined Work and reverse
|
|
||||||
engineering for debugging such modifications, if you also do each of
|
|
||||||
the following:
|
|
||||||
|
|
||||||
a) Give prominent notice with each copy of the Combined Work that
|
|
||||||
the Library is used in it and that the Library and its use are
|
|
||||||
covered by this License.
|
|
||||||
|
|
||||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
||||||
document.
|
|
||||||
|
|
||||||
c) For a Combined Work that displays copyright notices during
|
|
||||||
execution, include the copyright notice for the Library among
|
|
||||||
these notices, as well as a reference directing the user to the
|
|
||||||
copies of the GNU GPL and this license document.
|
|
||||||
|
|
||||||
d) Do one of the following:
|
|
||||||
|
|
||||||
0) Convey the Minimal Corresponding Source under the terms of this
|
|
||||||
License, and the Corresponding Application Code in a form
|
|
||||||
suitable for, and under terms that permit, the user to
|
|
||||||
recombine or relink the Application with a modified version of
|
|
||||||
the Linked Version to produce a modified Combined Work, in the
|
|
||||||
manner specified by section 6 of the GNU GPL for conveying
|
|
||||||
Corresponding Source.
|
|
||||||
|
|
||||||
1) Use a suitable shared library mechanism for linking with the
|
|
||||||
Library. A suitable mechanism is one that (a) uses at run time
|
|
||||||
a copy of the Library already present on the user's computer
|
|
||||||
system, and (b) will operate properly with a modified version
|
|
||||||
of the Library that is interface-compatible with the Linked
|
|
||||||
Version.
|
|
||||||
|
|
||||||
e) Provide Installation Information, but only if you would otherwise
|
|
||||||
be required to provide such information under section 6 of the
|
|
||||||
GNU GPL, and only to the extent that such information is
|
|
||||||
necessary to install and execute a modified version of the
|
|
||||||
Combined Work produced by recombining or relinking the
|
|
||||||
Application with a modified version of the Linked Version. (If
|
|
||||||
you use option 4d0, the Installation Information must accompany
|
|
||||||
the Minimal Corresponding Source and Corresponding Application
|
|
||||||
Code. If you use option 4d1, you must provide the Installation
|
|
||||||
Information in the manner specified by section 6 of the GNU GPL
|
|
||||||
for conveying Corresponding Source.)
|
|
||||||
|
|
||||||
5. Combined Libraries.
|
|
||||||
|
|
||||||
You may place library facilities that are a work based on the
|
|
||||||
Library side by side in a single library together with other library
|
|
||||||
facilities that are not Applications and are not covered by this
|
|
||||||
License, and convey such a combined library under terms of your
|
|
||||||
choice, if you do both of the following:
|
|
||||||
|
|
||||||
a) Accompany the combined library with a copy of the same work based
|
|
||||||
on the Library, uncombined with any other library facilities,
|
|
||||||
conveyed under the terms of this License.
|
|
||||||
|
|
||||||
b) Give prominent notice with the combined library that part of it
|
|
||||||
is a work based on the Library, and explaining where to find the
|
|
||||||
accompanying uncombined form of the same work.
|
|
||||||
|
|
||||||
6. Revised Versions of the GNU Lesser General Public License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the GNU Lesser General Public License from time to time. Such new
|
|
||||||
versions will be similar in spirit to the present version, but may
|
|
||||||
differ in detail to address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Library as you received it specifies that a certain numbered version
|
|
||||||
of the GNU Lesser General Public License "or any later version"
|
|
||||||
applies to it, you have the option of following the terms and
|
|
||||||
conditions either of that published version or of any later version
|
|
||||||
published by the Free Software Foundation. If the Library as you
|
|
||||||
received it does not specify a version number of the GNU Lesser
|
|
||||||
General Public License, you may choose any version of the GNU Lesser
|
|
||||||
General Public License ever published by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Library as you received it specifies that a proxy can decide
|
|
||||||
whether future versions of the GNU Lesser General Public License shall
|
|
||||||
apply, that proxy's public statement of acceptance of any version is
|
|
||||||
permanent authorization for you to choose that version for the
|
|
||||||
Library.
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
|
|
||||||
# Carry On [](https://minecraft.curseforge.com/projects/carry-on) [](https://minecraft.curseforge.com/projects/carry-on)
|
|
||||||
|
|
||||||
To use CarryOn in your projects, include this in your build.gradle:
|
|
||||||
```
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
url "https://maven.blamejared.com/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
deobfCompile "tschipp.carryon:carryon-MCVERSION:MODVERSION"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
Make sure to replace `MCVERSION` and `MODVERSION` with the appropriate versions.
|
|
||||||
239
old/build.gradle
239
old/build.gradle
|
|
@ -1,239 +0,0 @@
|
||||||
buildscript {
|
|
||||||
dependencies {
|
|
||||||
classpath 'org.parchmentmc:librarian:1.+'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id 'eclipse'
|
|
||||||
id 'maven-publish'
|
|
||||||
id 'net.minecraftforge.gradle' version '5.1.+'
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'org.parchmentmc.librarian.forgegradle'
|
|
||||||
|
|
||||||
|
|
||||||
apply from: 'https://raw.githubusercontent.com/MinecraftModDevelopment/Gradle-Collection/22e7d543a18cd30675277fbfa3669e3d9e206010/generic/secrets.gradle'
|
|
||||||
apply from: 'https://raw.githubusercontent.com/SizableShrimp/Forge-Class-Remapper/main/classremapper.gradle'
|
|
||||||
|
|
||||||
//import net.minecraftforge.gradle.common.task.SignJar
|
|
||||||
import groovy.json.JsonSlurper
|
|
||||||
import groovy.json.JsonOutput
|
|
||||||
|
|
||||||
if (project.hasProperty('secretFile')) {
|
|
||||||
loadSecrets(new File((String) findProperty('secretFile')))
|
|
||||||
}
|
|
||||||
|
|
||||||
version = "${version}"
|
|
||||||
group = "tschipp.carryon"
|
|
||||||
archivesBaseName = "carryon-${minecraft_version}"
|
|
||||||
|
|
||||||
|
|
||||||
if (System.getenv('BUILD_NUMBER') != null) {
|
|
||||||
version += "." + System.getenv('BUILD_NUMBER')
|
|
||||||
}
|
|
||||||
|
|
||||||
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
|
||||||
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
|
|
||||||
|
|
||||||
minecraft {
|
|
||||||
mappings channel: 'parchment', version: "${mappings_version}"
|
|
||||||
|
|
||||||
runs {
|
|
||||||
client {
|
|
||||||
workingDirectory project.file('run')
|
|
||||||
|
|
||||||
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
|
|
||||||
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
|
||||||
|
|
||||||
property 'mixin.env.remapRefMap', 'true'
|
|
||||||
property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg"
|
|
||||||
|
|
||||||
mods {
|
|
||||||
carryon {
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
workingDirectory project.file('run')
|
|
||||||
|
|
||||||
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
|
|
||||||
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
|
||||||
|
|
||||||
property 'mixin.env.remapRefMap', 'true'
|
|
||||||
property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg"
|
|
||||||
|
|
||||||
mods {
|
|
||||||
carryon {
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data {
|
|
||||||
workingDirectory project.file('run')
|
|
||||||
|
|
||||||
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
|
|
||||||
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
|
||||||
|
|
||||||
args '--mod', 'carryon', '--all', '--output', file('src/generated/resources/')
|
|
||||||
|
|
||||||
mods {
|
|
||||||
carryon {
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
|
|
||||||
maven {
|
|
||||||
url "https://maven.blamejared.com/"
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
|
||||||
url "https://maven.mcmoddev.com/"
|
|
||||||
}
|
|
||||||
|
|
||||||
flatDir {
|
|
||||||
dirs 'libs'
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
|
||||||
url "https://www.cursemaven.com"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
|
||||||
|
|
||||||
//implementation fg.deobf("net.darkhax.gamestages:GameStages-1.16.4:6.0.1")
|
|
||||||
//implementation fg.deobf("net.darkhax.bookshelf:Bookshelf-1.16.4:9.3.18")
|
|
||||||
//implementation fg.deobf("curse.maven:obfuscate-289380:3169370")
|
|
||||||
|
|
||||||
//fileTree("libs").matching {
|
|
||||||
// include "*.jar"
|
|
||||||
//}.each {
|
|
||||||
// String filename = it.getName();
|
|
||||||
// filename = filename.substring(0, filename.length() - 4);
|
|
||||||
// int lastDash = filename.lastIndexOf("-");
|
|
||||||
// filename = filename.substring(0, lastDash) + ":" + filename.substring(lastDash+1, filename.length());
|
|
||||||
// implementation fg.deobf("blank:${filename}")
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Example for how to get properties into the manifest for reading by the runtime..
|
|
||||||
jar {
|
|
||||||
manifest {
|
|
||||||
attributes([
|
|
||||||
"Specification-Title": "carryon",
|
|
||||||
"Specification-Vendor": "Carry On",
|
|
||||||
"Specification-Version": "1", // We are version 1 of ourselves
|
|
||||||
"Implementation-Title": project.name,
|
|
||||||
"Implementation-Version": "${version}",
|
|
||||||
"Implementation-Vendor" :"Carry On",
|
|
||||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jar.finalizedBy('reobfJar')
|
|
||||||
|
|
||||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
|
||||||
description = 'Creates a JAR containing the source code.'
|
|
||||||
from sourceSets.main.allSource
|
|
||||||
classifier = 'sources'
|
|
||||||
}
|
|
||||||
|
|
||||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
|
||||||
description = 'Creates a JAR containing the JavaDocs.'
|
|
||||||
from javadoc.destinationDir
|
|
||||||
classifier = 'javadoc'
|
|
||||||
}
|
|
||||||
|
|
||||||
task deobfJar(type: Jar) {
|
|
||||||
description = 'Creates a JAR containing the non-obfuscated compiled code.'
|
|
||||||
from sourceSets.main.output
|
|
||||||
classifier = "deobf"
|
|
||||||
}
|
|
||||||
|
|
||||||
artifacts {
|
|
||||||
archives sourcesJar
|
|
||||||
archives javadocJar
|
|
||||||
archives deobfJar
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
|
|
||||||
publications {
|
|
||||||
|
|
||||||
mavenJava(MavenPublication) {
|
|
||||||
|
|
||||||
groupId project.group
|
|
||||||
artifactId project.archivesBaseName
|
|
||||||
version project.version
|
|
||||||
from components.java
|
|
||||||
|
|
||||||
// Allows the maven pom file to be modified.
|
|
||||||
pom.withXml {
|
|
||||||
|
|
||||||
// Go through all the dependencies.
|
|
||||||
asNode().dependencies.dependency.each { dep ->
|
|
||||||
|
|
||||||
println 'Surpressing artifact ' + dep.artifactId.last().value().last() + ' from maven dependencies.'
|
|
||||||
assert dep.parent().remove(dep)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
artifact sourcesJar {
|
|
||||||
|
|
||||||
classifier 'sources'
|
|
||||||
}
|
|
||||||
artifact javadocJar {
|
|
||||||
|
|
||||||
classifier 'javadoc'
|
|
||||||
}
|
|
||||||
artifact deobfJar {
|
|
||||||
|
|
||||||
classifier 'deobf'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
|
|
||||||
maven {
|
|
||||||
|
|
||||||
url "file://" + System.getenv("local_maven")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//task signJar(type: SignJar, dependsOn: jar) {
|
|
||||||
// Skips if the keyStore property is missing.
|
|
||||||
// onlyIf {
|
|
||||||
// project.hasProperty('modkeyStore')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// findProperty allows us to reference the property without it existing.
|
|
||||||
// Using project.propName would cause the script to fail validation if
|
|
||||||
// the property did not exist.
|
|
||||||
// keyStore = project.findProperty('modkeyStore')
|
|
||||||
// alias = project.findProperty('modkeyStoreAlias')
|
|
||||||
// storePass = project.findProperty('modkeyStorePass')
|
|
||||||
// keyPass = project.findProperty('modkeyStoreKeyPass')
|
|
||||||
// inputFile = jar.archivePath
|
|
||||||
// outputFile = jar.archivePath
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Runs this task automatically when build is ran.
|
|
||||||
//build.dependsOn signJar
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
|
|
||||||
# This is required to provide enough memory for the Minecraft decompilation process.
|
|
||||||
org.gradle.jvmargs=-Xmx3G
|
|
||||||
version=1.18.1
|
|
||||||
minecraft_version=1.19
|
|
||||||
mappings_version=1.19.2-2022.09.18
|
|
||||||
forge_version=41.0.100
|
|
||||||
org.gradle.daemon=false
|
|
||||||
# chorg.gradle.java.home=C:/Program Files/AdoptOpenJDK/jdk-17.0.1/
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
pluginManagement {
|
|
||||||
repositories {
|
|
||||||
gradlePluginPortal()
|
|
||||||
maven { url = 'https://maven.minecraftforge.net/' }
|
|
||||||
maven { url = 'https://maven.parchmentmc.org' }
|
|
||||||
jcenter()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
package tschipp.carryon;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|
||||||
import net.minecraftforge.forgespi.language.IModInfo;
|
|
||||||
import net.minecraftforge.network.NetworkDirection;
|
|
||||||
import net.minecraftforge.network.NetworkRegistry;
|
|
||||||
import net.minecraftforge.network.simple.SimpleChannel;
|
|
||||||
import tschipp.carryon.common.config.Configs;
|
|
||||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
|
||||||
import tschipp.carryon.network.client.CarrySlotPacket;
|
|
||||||
import tschipp.carryon.network.client.ScriptReloadPacket;
|
|
||||||
import tschipp.carryon.network.server.SyncKeybindPacket;
|
|
||||||
import tschipp.carryon.proxy.ClientProxy;
|
|
||||||
import tschipp.carryon.proxy.IProxy;
|
|
||||||
import tschipp.carryon.proxy.ServerProxy;
|
|
||||||
|
|
||||||
@Mod(CarryOn.MODID)
|
|
||||||
@EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
|
||||||
public class CarryOn
|
|
||||||
{
|
|
||||||
|
|
||||||
public static IProxy proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> ServerProxy::new);
|
|
||||||
|
|
||||||
public static final String MODID = "carryon";
|
|
||||||
public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn");
|
|
||||||
public static final String DEPENDENCIES = "required-after:forge@[13.20.1.2386,);after:gamestages;";
|
|
||||||
public static final String CERTIFICATE_FINGERPRINT = "55e88f24d04398481ae6f1ce76f65fd776f14227";
|
|
||||||
public static File CONFIGURATION_FILE;
|
|
||||||
|
|
||||||
public static boolean FINGERPRINT_VIOLATED = false;
|
|
||||||
|
|
||||||
public static SimpleChannel network;
|
|
||||||
public static IModInfo info;
|
|
||||||
|
|
||||||
public CarryOn()
|
|
||||||
{
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
|
||||||
|
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Configs.CLIENT_CONFIG);
|
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Configs.SERVER_CONFIG);
|
|
||||||
|
|
||||||
info = ModLoadingContext.get().getActiveContainer().getModInfo();
|
|
||||||
RegistrationHandler.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setup(final FMLCommonSetupEvent event)
|
|
||||||
{
|
|
||||||
String version = info.getVersion().toString();
|
|
||||||
// PreInitevent.
|
|
||||||
CarryOn.network = NetworkRegistry.newSimpleChannel(new ResourceLocation(CarryOn.MODID, "carryonpackets"), () -> version, version::equals, version::equals);
|
|
||||||
|
|
||||||
// CLIENT PACKETS
|
|
||||||
CarryOn.network.registerMessage(0, CarrySlotPacket.class, CarrySlotPacket::toBytes, CarrySlotPacket::new, CarrySlotPacket::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
|
||||||
CarryOn.network.registerMessage(1, ScriptReloadPacket.class, ScriptReloadPacket::toBytes, ScriptReloadPacket::new, ScriptReloadPacket::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
|
||||||
|
|
||||||
// SERVER PACKETS
|
|
||||||
CarryOn.network.registerMessage(2, SyncKeybindPacket.class, SyncKeybindPacket::toBytes, SyncKeybindPacket::new, SyncKeybindPacket::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER));
|
|
||||||
|
|
||||||
RegistrationHandler.regCommonEvents();
|
|
||||||
|
|
||||||
// Init
|
|
||||||
RegistrationHandler.regOverrideList();
|
|
||||||
|
|
||||||
proxy.setup(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
package tschipp.carryon.client.event;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.math.Vector3f;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.EntityType;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.client.event.RenderHandEvent;
|
|
||||||
import net.minecraftforge.event.level.LevelEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.ModList;
|
|
||||||
import tschipp.carryon.client.helper.CarryRenderHelper;
|
|
||||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonEntity;
|
|
||||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
|
||||||
import tschipp.carryon.common.scripting.ScriptChecker;
|
|
||||||
|
|
||||||
public class RenderEntityEvents
|
|
||||||
{
|
|
||||||
|
|
||||||
public static final Map<String, Entity> nbtEntityMap = new HashMap<>();
|
|
||||||
|
|
||||||
public static Entity getEntity(ItemStack carried, Level level)
|
|
||||||
{
|
|
||||||
String nbt = ItemCarryonEntity.getPersistentData(carried).toString();
|
|
||||||
if (nbtEntityMap.containsKey(nbt))
|
|
||||||
{
|
|
||||||
return nbtEntityMap.get(nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = ItemCarryonEntity.getEntity(carried, level);
|
|
||||||
nbtEntityMap.put(nbt, entity);
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onLevelUnload(LevelEvent.Unload event)
|
|
||||||
{
|
|
||||||
nbtEntityMap.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Renders the Entity in First Person
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void renderHand(RenderHandEvent event)
|
|
||||||
{
|
|
||||||
Level level = Minecraft.getInstance().level;
|
|
||||||
Player player = Minecraft.getInstance().player;
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
int perspective = CarryRenderHelper.getPerspective();
|
|
||||||
float partialticks = event.getPartialTick();
|
|
||||||
PoseStack matrix = event.getPoseStack();
|
|
||||||
int light = event.getPackedLight();
|
|
||||||
MultiBufferSource buffer = event.getMultiBufferSource();
|
|
||||||
EntityRenderDispatcher manager = Minecraft.getInstance().getEntityRenderDispatcher();
|
|
||||||
|
|
||||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack))
|
|
||||||
{
|
|
||||||
if (ModList.get().isLoaded("realrender") || ModList.get().isLoaded("rfpr"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Entity entity = getEntity(stack, level);
|
|
||||||
|
|
||||||
if (entity != null)
|
|
||||||
{
|
|
||||||
Vec3 playerpos = CarryRenderHelper.getExactPos(player, partialticks);
|
|
||||||
|
|
||||||
entity.setPos(playerpos.x, playerpos.y, playerpos.z);
|
|
||||||
entity.xRotO = 0.0f;
|
|
||||||
entity.yRotO = 0.0f;
|
|
||||||
entity.setYHeadRot(0.0f);
|
|
||||||
|
|
||||||
float height = entity.getBbHeight();
|
|
||||||
float width = entity.getBbWidth();
|
|
||||||
|
|
||||||
matrix.pushPose();
|
|
||||||
matrix.scale(0.8f, 0.8f, 0.8f);
|
|
||||||
matrix.mulPose(Vector3f.YP.rotationDegrees(180));
|
|
||||||
matrix.translate(0.0, -height - .1, width + 0.1);
|
|
||||||
|
|
||||||
// RenderSystem.enableAlphaTest();
|
|
||||||
|
|
||||||
if (perspective == 0)
|
|
||||||
{
|
|
||||||
// Lighting.en
|
|
||||||
manager.setRenderShadow(false);
|
|
||||||
|
|
||||||
CarryOnOverride carryOverride = ScriptChecker.getOverride(player);
|
|
||||||
if (carryOverride != null)
|
|
||||||
{
|
|
||||||
CarryRenderHelper.performOverrideTransformation(matrix, carryOverride);
|
|
||||||
|
|
||||||
String entityname = carryOverride.getRenderNameEntity();
|
|
||||||
if (entityname != null)
|
|
||||||
{
|
|
||||||
Entity newEntity = null;
|
|
||||||
|
|
||||||
Optional<EntityType<?>> type = EntityType.byString(entityname);
|
|
||||||
if (type.isPresent())
|
|
||||||
newEntity = type.get().create(level);
|
|
||||||
|
|
||||||
if (newEntity != null)
|
|
||||||
{
|
|
||||||
CompoundTag nbttag = carryOverride.getRenderNBT();
|
|
||||||
if (nbttag != null)
|
|
||||||
newEntity.deserializeNBT(nbttag);
|
|
||||||
entity = newEntity;
|
|
||||||
entity.setPos(playerpos.x, playerpos.y, playerpos.z);
|
|
||||||
entity.xRotO = 0.0f;
|
|
||||||
entity.yRotO = 0.0f;
|
|
||||||
entity.setYHeadRot(0.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof LivingEntity)
|
|
||||||
((LivingEntity) entity).hurtTime = 0;
|
|
||||||
|
|
||||||
manager.render(entity, 0, 0, 0, 0f, 0, matrix, buffer, light);
|
|
||||||
manager.setRenderShadow(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenderSystem.disableAlphaTest();
|
|
||||||
matrix.popPose();
|
|
||||||
|
|
||||||
// Lighting.turnOff();
|
|
||||||
// TODO
|
|
||||||
// RenderSystem.disableRescaleNormal();
|
|
||||||
|
|
||||||
if (perspective == 0)
|
|
||||||
{
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,796 +0,0 @@
|
||||||
package tschipp.carryon.client.event;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.Tesselator;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
||||||
import com.mojang.math.Quaternion;
|
|
||||||
import com.mojang.math.Vector3f;
|
|
||||||
|
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.client.KeyMapping;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.Options;
|
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
|
||||||
import net.minecraft.client.model.PlayerModel;
|
|
||||||
import net.minecraft.client.model.geom.ModelPart;
|
|
||||||
import net.minecraft.client.player.AbstractClientPlayer;
|
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
|
||||||
import net.minecraft.client.renderer.MultiBufferSource.BufferSource;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
|
|
||||||
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.chat.ClickEvent;
|
|
||||||
import net.minecraft.network.chat.ClickEvent.Action;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.EntityType;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.Pose;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.Blocks;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.client.event.RenderHandEvent;
|
|
||||||
import net.minecraftforge.client.event.RenderLevelLastEvent;
|
|
||||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
|
||||||
import net.minecraftforge.client.event.ScreenEvent;
|
|
||||||
import net.minecraftforge.event.TickEvent.PlayerTickEvent;
|
|
||||||
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
|
||||||
import net.minecraftforge.fml.ModList;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.client.helper.CarryRenderHelper;
|
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
|
||||||
import tschipp.carryon.common.config.Configs.Settings;
|
|
||||||
import tschipp.carryon.common.handler.ModelOverridesHandler;
|
|
||||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
|
||||||
import tschipp.carryon.common.helper.KeyboardCallbackWrapper.KeyPressedEvent;
|
|
||||||
import tschipp.carryon.common.helper.ScriptParseHelper;
|
|
||||||
import tschipp.carryon.common.helper.ScrollCallbackWrapper.MouseScrolledEvent;
|
|
||||||
import tschipp.carryon.common.helper.StringParser;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonBlock;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonEntity;
|
|
||||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
|
||||||
import tschipp.carryon.common.scripting.ScriptChecker;
|
|
||||||
import tschipp.carryon.network.server.SyncKeybindPacket;
|
|
||||||
|
|
||||||
public class RenderEvents
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Prevents the Player from scrolling
|
|
||||||
*/
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onScroll(MouseScrolledEvent event)
|
|
||||||
{
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
Player player = Minecraft.getInstance().player;
|
|
||||||
|
|
||||||
if (player != null)
|
|
||||||
{
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
|
|
||||||
if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile.get() || stack.getItem() == RegistrationHandler.itemEntity.get()))
|
|
||||||
{
|
|
||||||
if (ItemCarryonBlock.hasTileData(stack) || ItemCarryonEntity.hasEntityData(stack))
|
|
||||||
{
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public void onPlayerTick(PlayerTickEvent event) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
|
|
||||||
{
|
|
||||||
Player player = event.player;
|
|
||||||
|
|
||||||
if (player != null && event.side == LogicalSide.CLIENT)
|
|
||||||
{
|
|
||||||
boolean keyPressed = CarryOnKeybinds.carryKey.isDown();
|
|
||||||
boolean playerKeyPressed = CarryOnKeybinds.isKeyPressed(player);
|
|
||||||
|
|
||||||
if (keyPressed && !playerKeyPressed)
|
|
||||||
{
|
|
||||||
CarryOnKeybinds.setKeyPressed(player, true);
|
|
||||||
CarryOn.network.sendToServer(new SyncKeybindPacket(true));
|
|
||||||
}
|
|
||||||
else if (!keyPressed && playerKeyPressed)
|
|
||||||
{
|
|
||||||
CarryOnKeybinds.setKeyPressed(player, false);
|
|
||||||
CarryOn.network.sendToServer(new SyncKeybindPacket(false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public void onJoinLevel(EntityJoinLevelEvent event)
|
|
||||||
{
|
|
||||||
if (event.getEntity() instanceof Player)
|
|
||||||
{
|
|
||||||
Player player = (Player) event.getEntity();
|
|
||||||
if (player.level.isClientSide)
|
|
||||||
{
|
|
||||||
CarryOnKeybinds.setKeyPressed(player, false);
|
|
||||||
CarryOn.network.sendToServer(new SyncKeybindPacket(false));
|
|
||||||
|
|
||||||
if (CarryOn.FINGERPRINT_VIOLATED)
|
|
||||||
{
|
|
||||||
Component cf = Component.literal(ChatFormatting.AQUA + "Curseforge" + ChatFormatting.RED);
|
|
||||||
cf.getStyle().withClickEvent(new ClickEvent(Action.OPEN_URL, "https://minecraft.curseforge.com/projects/carry-on"));
|
|
||||||
|
|
||||||
player.displayClientMessage(Component.literal(ChatFormatting.RED + "[CarryOn] WARNING! Invalid fingerprint detected! The Carry On mod file may have been tampered with! If you didn't download the file from ").append(cf).append(ChatFormatting.RED + " or through any kind of mod launcher, immediately delete the file and re-download it from ").append(cf), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Prevents the Player from opening Guis
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onGuiInit(ScreenEvent.Init.Pre event)
|
|
||||||
{
|
|
||||||
if (event.getScreen() != null)
|
|
||||||
{
|
|
||||||
boolean inventory = event.getScreen() instanceof AbstractContainerScreen;
|
|
||||||
Player player = Minecraft.getInstance().player;
|
|
||||||
|
|
||||||
if (player != null && inventory)
|
|
||||||
{
|
|
||||||
ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND);
|
|
||||||
|
|
||||||
if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile.get() && ItemCarryonBlock.hasTileData(stack) || stack.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack)))
|
|
||||||
{
|
|
||||||
Minecraft.getInstance().player.closeContainer();
|
|
||||||
Minecraft.getInstance().screen = null;
|
|
||||||
Minecraft.getInstance().mouseHandler.grabMouse();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Prevents the Player from switching Slots
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void inputEvent(KeyPressedEvent event) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
|
|
||||||
{
|
|
||||||
Options settings = Minecraft.getInstance().options;
|
|
||||||
int key = event.key;
|
|
||||||
int scancode = event.scancode;
|
|
||||||
Player player = Minecraft.getInstance().player;
|
|
||||||
|
|
||||||
if (player != null)
|
|
||||||
{
|
|
||||||
ItemStack stack = Minecraft.getInstance().player.getMainHandItem();
|
|
||||||
|
|
||||||
if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile.get() && ItemCarryonBlock.hasTileData(stack) || stack.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack)))
|
|
||||||
{
|
|
||||||
if (settings.keyDrop.matches(key, scancode))
|
|
||||||
{
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
if (settings.keySwapOffhand.matches(key, scancode))
|
|
||||||
{
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
if (settings.keyPickItem.matches(key, scancode))
|
|
||||||
{
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
for (KeyMapping keyBind : settings.keyHotbarSlots)
|
|
||||||
{
|
|
||||||
if (keyBind.matches(key, scancode))
|
|
||||||
{
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int current = player.getInventory().selected;
|
|
||||||
|
|
||||||
if (player.getPersistentData().contains("carrySlot") ? player.getPersistentData().getInt("carrySlot") != current : false)
|
|
||||||
{
|
|
||||||
player.getInventory().selected = player.getPersistentData().getInt("carrySlot");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Renders the Block in First Person
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "resource", "deprecation" })
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void renderHand(RenderHandEvent event)
|
|
||||||
{
|
|
||||||
Level level = Minecraft.getInstance().level;
|
|
||||||
Player player = Minecraft.getInstance().player;
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
int perspective = CarryRenderHelper.getPerspective();
|
|
||||||
boolean f1 = Minecraft.getInstance().options.hideGui;
|
|
||||||
MultiBufferSource buffer = event.getMultiBufferSource();
|
|
||||||
PoseStack matrix = event.getPoseStack();
|
|
||||||
int light = event.getPackedLight();
|
|
||||||
|
|
||||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile.get() && ItemCarryonBlock.hasTileData(stack) && perspective == 0 && !f1)
|
|
||||||
{
|
|
||||||
if (ModList.get().isLoaded("realrender") || ModList.get().isLoaded("rfpr"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Block block = ItemCarryonBlock.getBlock(stack);
|
|
||||||
CompoundTag tag = ItemCarryonBlock.getTileData(stack);
|
|
||||||
BlockState state = ItemCarryonBlock.getBlockState(stack);
|
|
||||||
ItemStack tileStack = ItemCarryonBlock.getItemStack(stack);
|
|
||||||
|
|
||||||
matrix.pushPose();
|
|
||||||
matrix.scale(2.5f, 2.5f, 2.5f);
|
|
||||||
matrix.translate(0, -0.5, -1);
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.disableCull();
|
|
||||||
|
|
||||||
if (Settings.facePlayer.get() ? !isChest(block) : isChest(block))
|
|
||||||
{
|
|
||||||
matrix.mulPose(Vector3f.YP.rotationDegrees(180));
|
|
||||||
matrix.mulPose(Vector3f.XN.rotationDegrees(8));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
matrix.mulPose(Vector3f.XP.rotationDegrees(8));
|
|
||||||
}
|
|
||||||
|
|
||||||
BakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, level, player) : tileStack.isEmpty() ? Minecraft.getInstance().getBlockRenderer().getBlockModel(state) : Minecraft.getInstance().getItemRenderer().getModel(tileStack, level, player, 0);
|
|
||||||
|
|
||||||
CarryOnOverride carryOverride = ScriptChecker.getOverride(player);
|
|
||||||
if (carryOverride != null)
|
|
||||||
{
|
|
||||||
CarryRenderHelper.performOverrideTransformation(matrix, carryOverride);
|
|
||||||
|
|
||||||
if (!carryOverride.getRenderNameBlock().isEmpty())
|
|
||||||
{
|
|
||||||
Block b = StringParser.getBlock(carryOverride.getRenderNameBlock());
|
|
||||||
if (b != null)
|
|
||||||
{
|
|
||||||
ItemStack s = new ItemStack(b, 1);
|
|
||||||
s.setTag(carryOverride.getRenderNBT());
|
|
||||||
model = Minecraft.getInstance().getItemRenderer().getModel(s, level, player, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
|
|
||||||
|
|
||||||
CarryRenderHelper.renderItem(state, tag, stack, tileStack, matrix, buffer, light, model);
|
|
||||||
|
|
||||||
if (perspective == 0)
|
|
||||||
{
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderSystem.enableCull();
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
matrix.popPose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @SubscribeEvent
|
|
||||||
// public void onJoinServer(LoggedInEvent event)
|
|
||||||
// {
|
|
||||||
// ListHandler.initConfigLists();
|
|
||||||
// }
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Render blocks and entities in third person
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "deprecation", "resource" })
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onRenderLevel(RenderLevelLastEvent event)
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
Level level = mc.level;
|
|
||||||
float partialticks = event.getPartialTick();
|
|
||||||
BufferSource buffer = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
|
|
||||||
PoseStack matrix = event.getPoseStack();
|
|
||||||
int light = 0;
|
|
||||||
int perspective = CarryRenderHelper.getPerspective();
|
|
||||||
EntityRenderDispatcher manager = mc.getEntityRenderDispatcher();
|
|
||||||
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.disableCull();
|
|
||||||
RenderSystem.disableDepthTest();
|
|
||||||
|
|
||||||
for (Player player : level.players())
|
|
||||||
{
|
|
||||||
if (perspective == 0 && player == mc.player)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
light = manager.getPackedLightCoords(player, partialticks);
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
|
|
||||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile.get() && ItemCarryonBlock.hasTileData(stack))
|
|
||||||
{
|
|
||||||
Block block = ItemCarryonBlock.getBlock(stack);
|
|
||||||
BlockState state = ItemCarryonBlock.getBlockState(stack);
|
|
||||||
CompoundTag tag = ItemCarryonBlock.getTileData(stack);
|
|
||||||
ItemStack tileItem = ItemCarryonBlock.getItemStack(stack);
|
|
||||||
|
|
||||||
applyBlockTransformations(player, partialticks, matrix, block);
|
|
||||||
|
|
||||||
BakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, level, player) : tileItem.isEmpty() ? mc.getBlockRenderer().getBlockModel(state) : mc.getItemRenderer().getModel(tileItem, level, player, 0);
|
|
||||||
|
|
||||||
CarryOnOverride carryOverride = ScriptChecker.getOverride(player);
|
|
||||||
if (carryOverride != null)
|
|
||||||
{
|
|
||||||
CarryRenderHelper.performOverrideTransformation(matrix, carryOverride);
|
|
||||||
|
|
||||||
if (!carryOverride.getRenderNameBlock().isEmpty())
|
|
||||||
{
|
|
||||||
Block b = StringParser.getBlock(carryOverride.getRenderNameBlock());
|
|
||||||
if (b != null)
|
|
||||||
{
|
|
||||||
ItemStack s = new ItemStack(b, 1);
|
|
||||||
s.setTag(carryOverride.getRenderNBT());
|
|
||||||
model = mc.getItemRenderer().getModel(s, level, player, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
|
|
||||||
RenderSystem.enableCull();
|
|
||||||
|
|
||||||
PoseStack.Pose p = matrix.last();
|
|
||||||
PoseStack copy = new PoseStack();
|
|
||||||
copy.mulPoseMatrix(p.pose());
|
|
||||||
matrix.popPose();
|
|
||||||
drawArms(player, partialticks, matrix, buffer, light);
|
|
||||||
|
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
|
|
||||||
CarryRenderHelper.renderItem(state, tag, stack, tileItem, copy, buffer, light, model);
|
|
||||||
buffer.endBatch();
|
|
||||||
|
|
||||||
matrix.popPose();
|
|
||||||
}
|
|
||||||
else if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack))
|
|
||||||
{
|
|
||||||
Entity entity = RenderEntityEvents.getEntity(stack, level);
|
|
||||||
|
|
||||||
if (entity != null)
|
|
||||||
{
|
|
||||||
applyEntityTransformations(player, partialticks, matrix, entity);
|
|
||||||
|
|
||||||
manager.setRenderShadow(false);
|
|
||||||
|
|
||||||
CarryOnOverride carryOverride = ScriptChecker.getOverride(player);
|
|
||||||
if (carryOverride != null)
|
|
||||||
{
|
|
||||||
CarryRenderHelper.performOverrideTransformation(matrix, carryOverride);
|
|
||||||
|
|
||||||
String entityname = carryOverride.getRenderNameEntity();
|
|
||||||
if (entityname != null)
|
|
||||||
{
|
|
||||||
Entity newEntity = null;
|
|
||||||
|
|
||||||
Optional<EntityType<?>> type = EntityType.byString(entityname);
|
|
||||||
if (type.isPresent())
|
|
||||||
newEntity = type.get().create(level);
|
|
||||||
|
|
||||||
if (newEntity != null)
|
|
||||||
{
|
|
||||||
CompoundTag nbttag = carryOverride.getRenderNBT();
|
|
||||||
if (nbttag != null)
|
|
||||||
newEntity.deserializeNBT(nbttag);
|
|
||||||
entity = newEntity;
|
|
||||||
entity.yo = 0.0f;
|
|
||||||
entity.yRotO = 0.0f;
|
|
||||||
entity.setYHeadRot(0.0f);
|
|
||||||
entity.xo = 0.0f;
|
|
||||||
entity.xRotO = 0.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof LivingEntity le)
|
|
||||||
le.hurtTime = 0;
|
|
||||||
|
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
|
|
||||||
manager.render(entity, 0, 0, 0, 0f, 0, matrix, buffer, light);
|
|
||||||
buffer.endBatch();
|
|
||||||
|
|
||||||
matrix.popPose();
|
|
||||||
|
|
||||||
drawArms(player, partialticks, matrix, buffer, light);
|
|
||||||
|
|
||||||
manager.setRenderShadow(true);
|
|
||||||
|
|
||||||
matrix.popPose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
RenderSystem.enableDepthTest();
|
|
||||||
RenderSystem.enableCull();
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
private void applyGeneralTransformations(Player player, float partialticks, PoseStack matrix)
|
|
||||||
{
|
|
||||||
int perspective = CarryRenderHelper.getPerspective();
|
|
||||||
Quaternion playerrot = CarryRenderHelper.getExactBodyRotation(player, partialticks);
|
|
||||||
Vec3 playerpos = CarryRenderHelper.getExactPos(player, partialticks);
|
|
||||||
Vec3 cameraPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
|
|
||||||
Vec3 offset = playerpos.subtract(cameraPos);
|
|
||||||
Pose pose = player.getPose();
|
|
||||||
|
|
||||||
matrix.pushPose();
|
|
||||||
matrix.translate(offset.x, offset.y, offset.z);
|
|
||||||
|
|
||||||
if (perspective == 2)
|
|
||||||
playerrot.mul(Vector3f.YP.rotationDegrees(180));
|
|
||||||
matrix.mulPose(playerrot);
|
|
||||||
|
|
||||||
matrix.pushPose();
|
|
||||||
matrix.scale(0.6f, 0.6f, 0.6f);
|
|
||||||
|
|
||||||
if (perspective == 2)
|
|
||||||
matrix.translate(0, 0, -1.35);
|
|
||||||
|
|
||||||
if (doSneakCheck(player))
|
|
||||||
{
|
|
||||||
matrix.translate(0, -0.4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pose == Pose.SWIMMING)
|
|
||||||
{
|
|
||||||
float f = player.getSwimAmount(partialticks);
|
|
||||||
float f3 = player.isInWater() ? -90.0F - player.xRotO : -90.0F;
|
|
||||||
float f4 = Mth.lerp(f, 0.0F, f3);
|
|
||||||
if (perspective == 2)
|
|
||||||
{
|
|
||||||
matrix.translate(0, 0, 1.35);
|
|
||||||
matrix.mulPose(Vector3f.XP.rotationDegrees(f4));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
matrix.mulPose(Vector3f.XN.rotationDegrees(f4));
|
|
||||||
|
|
||||||
matrix.translate(0, -1.5, -1.848);
|
|
||||||
if (perspective == 2)
|
|
||||||
matrix.translate(0, 0, 2.38);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pose == Pose.FALL_FLYING)
|
|
||||||
{
|
|
||||||
float f1 = player.getFallFlyingTicks() + partialticks;
|
|
||||||
float f2 = Mth.clamp(f1 * f1 / 100.0F, 0.0F, 1.0F);
|
|
||||||
if (!player.isAutoSpinAttack())
|
|
||||||
{
|
|
||||||
if (perspective == 2)
|
|
||||||
matrix.translate(0, 0, 1.35);
|
|
||||||
|
|
||||||
if (perspective == 2)
|
|
||||||
matrix.mulPose(Vector3f.XP.rotationDegrees(f2 * (-90.0F - player.xRotO)));
|
|
||||||
else
|
|
||||||
matrix.mulPose(Vector3f.XN.rotationDegrees(f2 * (-90.0F - player.xRotO)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 Vector3d = player.getViewVector(partialticks);
|
|
||||||
Vec3 Vector3d1 = player.getDeltaMovement();
|
|
||||||
double d0 = Vector3d1.horizontalDistanceSqr();
|
|
||||||
double d1 = Vector3d1.horizontalDistanceSqr();
|
|
||||||
if (d0 > 0.0D && d1 > 0.0D)
|
|
||||||
{
|
|
||||||
double d2 = (Vector3d1.x * Vector3d.x + Vector3d1.z * Vector3d.z) / (Math.sqrt(d0) * Math.sqrt(d1));
|
|
||||||
double d3 = Vector3d1.x * Vector3d.z - Vector3d1.z * Vector3d.x;
|
|
||||||
|
|
||||||
matrix.mulPose(Vector3f.YP.rotation((float) (Math.signum(d3) * Math.acos(d2))));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (perspective != 2)
|
|
||||||
matrix.translate(0, 0, -1.35);
|
|
||||||
matrix.translate(0, -0.2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
matrix.translate(0, 1.6, 0.65);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyBlockTransformations(Player player, float partialticks, PoseStack matrix, Block block)
|
|
||||||
{
|
|
||||||
int perspective = CarryRenderHelper.getPerspective();
|
|
||||||
|
|
||||||
applyGeneralTransformations(player, partialticks, matrix);
|
|
||||||
|
|
||||||
if (Settings.facePlayer.get() ? !isChest(block) : isChest(block))
|
|
||||||
{
|
|
||||||
if ((ModList.get().isLoaded("realrender") || ModList.get().isLoaded("rfpr")) && perspective == 0)
|
|
||||||
matrix.translate(0, 0, -0.4);
|
|
||||||
matrix.mulPose(Vector3f.YP.rotationDegrees(180));
|
|
||||||
}
|
|
||||||
else if ((ModList.get().isLoaded("realrender") || ModList.get().isLoaded("rfpr")) && perspective == 0)
|
|
||||||
matrix.translate(0, 0, 0.4);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyEntityTransformations(Player player, float partialticks, PoseStack matrix, Entity entity)
|
|
||||||
{
|
|
||||||
int perspective = CarryRenderHelper.getPerspective();
|
|
||||||
Pose pose = player.getPose();
|
|
||||||
|
|
||||||
applyGeneralTransformations(player, partialticks, matrix);
|
|
||||||
|
|
||||||
if (perspective == 2)
|
|
||||||
matrix.translate(0, -1.6, 0.65);
|
|
||||||
else
|
|
||||||
matrix.translate(0, -1.6, -0.65);
|
|
||||||
matrix.scale(1.666f, 1.666f, 1.666f);
|
|
||||||
|
|
||||||
float height = entity.getBbHeight();
|
|
||||||
float width = entity.getBbWidth();
|
|
||||||
float multiplier = height * width;
|
|
||||||
entity.yo = 0.0f;
|
|
||||||
entity.yRotO = 0.0f;
|
|
||||||
entity.setYHeadRot(0.0f);
|
|
||||||
entity.xo = 0.0f;
|
|
||||||
entity.xRotO = 0.0f;
|
|
||||||
|
|
||||||
if (perspective == 2)
|
|
||||||
matrix.mulPose(Vector3f.YP.rotationDegrees(180));
|
|
||||||
|
|
||||||
matrix.scale((10 - multiplier) * 0.08f, (10 - multiplier) * 0.08f, (10 - multiplier) * 0.08f);
|
|
||||||
matrix.translate(0.0, height / 2 + -(height / 2) + 1, width - 0.1 < 0.7 ? width - 0.1 + (0.7 - (width - 0.1)) : width - 0.1);
|
|
||||||
|
|
||||||
if (pose == Pose.SWIMMING || pose == Pose.FALL_FLYING)
|
|
||||||
{
|
|
||||||
matrix.mulPose(Vector3f.XN.rotationDegrees(90));
|
|
||||||
matrix.translate(0, -0.2 * height, 0);
|
|
||||||
|
|
||||||
if (pose == Pose.FALL_FLYING)
|
|
||||||
matrix.translate(0, 0, 0.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Renders correct arm rotation
|
|
||||||
*/
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public void drawArms(Player player, float partialticks, PoseStack matrix, MultiBufferSource buffer, int light)
|
|
||||||
{
|
|
||||||
int perspective = CarryRenderHelper.getPerspective();
|
|
||||||
Pose pose = player.getPose();
|
|
||||||
|
|
||||||
if (!Settings.renderArms.get() || pose == Pose.SWIMMING || pose == Pose.FALL_FLYING)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (handleMobends() && !ModList.get().isLoaded("obfuscate"))
|
|
||||||
{
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile.get() && ItemCarryonBlock.hasTileData(stack) || stack.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack))
|
|
||||||
{
|
|
||||||
PlayerModel<AbstractClientPlayer> model = getPlayerModel((AbstractClientPlayer) player);
|
|
||||||
|
|
||||||
AbstractClientPlayer aplayer = (AbstractClientPlayer) player;
|
|
||||||
ResourceLocation skinLoc = aplayer.getSkinTextureLocation();
|
|
||||||
|
|
||||||
matrix.pushPose();
|
|
||||||
if (perspective == 2)
|
|
||||||
matrix.mulPose(Vector3f.YP.rotationDegrees(180));
|
|
||||||
|
|
||||||
RenderSystem.setShaderTexture(0, skinLoc);
|
|
||||||
|
|
||||||
CarryOnOverride overrider = ScriptChecker.getOverride(player);
|
|
||||||
VertexConsumer builder = buffer.getBuffer(RenderType.entityCutout(skinLoc));
|
|
||||||
|
|
||||||
if (overrider != null)
|
|
||||||
{
|
|
||||||
float[] rotLeft = null;
|
|
||||||
float[] rotRight = null;
|
|
||||||
if (!overrider.getRenderRotationLeftArm().isEmpty())
|
|
||||||
rotLeft = ScriptParseHelper.getXYZArray(overrider.getRenderRotationLeftArm());
|
|
||||||
if (!overrider.getRenderRotationRightArm().isEmpty())
|
|
||||||
rotRight = ScriptParseHelper.getXYZArray(overrider.getRenderRotationRightArm());
|
|
||||||
|
|
||||||
boolean renderRight = overrider.isRenderRightArm();
|
|
||||||
boolean renderLeft = overrider.isRenderLeftArm();
|
|
||||||
|
|
||||||
if (renderLeft && rotLeft != null)
|
|
||||||
{
|
|
||||||
renderArmPost(model.leftArm, rotLeft[0], rotLeft[2], false, doSneakCheck(player), light, matrix, builder);
|
|
||||||
renderArmPost(model.leftSleeve, rotLeft[0], rotLeft[2], false, doSneakCheck(player), light, matrix, builder);
|
|
||||||
}
|
|
||||||
else if (renderLeft)
|
|
||||||
{
|
|
||||||
renderArmPost(model.leftArm, 2.0F + (doSneakCheck(player) ? 0f : 0.2f) - (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.3f : 0), stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.15f : 0, false, doSneakCheck(player), light, matrix, builder);
|
|
||||||
renderArmPost(model.leftSleeve, 2.0F + (doSneakCheck(player) ? 0f : 0.2f) - (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.3f : 0), stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.15f : 0, false, doSneakCheck(player), light, matrix, builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (renderRight && rotRight != null)
|
|
||||||
{
|
|
||||||
renderArmPost(model.rightArm, rotRight[0], rotRight[2], true, doSneakCheck(player), light, matrix, builder);
|
|
||||||
renderArmPost(model.rightSleeve, rotRight[0], rotRight[2], true, doSneakCheck(player), light, matrix, builder);
|
|
||||||
}
|
|
||||||
else if (renderRight)
|
|
||||||
{
|
|
||||||
renderArmPost(model.rightArm, 2.0F + (doSneakCheck(player) ? 0f : 0.2f) - (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.3f : 0), stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.15f : 0, true, doSneakCheck(player), light, matrix, builder);
|
|
||||||
renderArmPost(model.rightSleeve, 2.0F + (doSneakCheck(player) ? 0f : 0.2f) - (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.3f : 0), stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.15f : 0, true, doSneakCheck(player), light, matrix, builder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renderArmPost(model.rightArm, 2.0F + (doSneakCheck(player) ? 0f : 0.2f) - (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.3f : 0), stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.15f : 0, true, doSneakCheck(player), light, matrix, builder);
|
|
||||||
renderArmPost(model.leftArm, 2.0F + (doSneakCheck(player) ? 0f : 0.2f) - (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.3f : 0), stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.15f : 0, false, doSneakCheck(player), light, matrix, builder);
|
|
||||||
renderArmPost(model.leftSleeve, 2.0F + (doSneakCheck(player) ? 0f : 0.2f) - (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.3f : 0), stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.15f : 0, false, doSneakCheck(player), light, matrix, builder);
|
|
||||||
renderArmPost(model.rightSleeve, 2.0F + (doSneakCheck(player) ? 0f : 0.2f) - (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.3f : 0), stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.15f : 0, true, doSneakCheck(player), light, matrix, builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer instanceof BufferSource)
|
|
||||||
((BufferSource) buffer).endBatch();
|
|
||||||
|
|
||||||
matrix.popPose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hides the vanilla arm for rendering the rotation
|
|
||||||
*/
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
|
||||||
public void onEvent(RenderPlayerEvent.Pre event)
|
|
||||||
{
|
|
||||||
if (!Settings.renderArms.get())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (handleMobends() && !ModList.get().isLoaded("obfuscate"))
|
|
||||||
{
|
|
||||||
Player player = event.getEntity();
|
|
||||||
Pose pose = player.getPose();
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (pose != Pose.SWIMMING && pose != Pose.FALL_FLYING && !stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile.get() && ItemCarryonBlock.hasTileData(stack) || stack.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack)))
|
|
||||||
{
|
|
||||||
PlayerModel<AbstractClientPlayer> model = event.getRenderer().getModel();
|
|
||||||
|
|
||||||
CarryOnOverride overrider = ScriptChecker.getOverride(player);
|
|
||||||
if (overrider != null)
|
|
||||||
{
|
|
||||||
boolean renderRight = overrider.isRenderRightArm();
|
|
||||||
boolean renderLeft = overrider.isRenderLeftArm();
|
|
||||||
|
|
||||||
if (renderRight)
|
|
||||||
{
|
|
||||||
renderArmPre(model.rightArm);
|
|
||||||
renderArmPre(model.rightSleeve);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (renderLeft)
|
|
||||||
{
|
|
||||||
renderArmPre(model.leftArm);
|
|
||||||
renderArmPre(model.leftSleeve);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renderArmPre(model.rightArm);
|
|
||||||
renderArmPre(model.leftArm);
|
|
||||||
renderArmPre(model.leftSleeve);
|
|
||||||
renderArmPre(model.rightSleeve);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
private void renderArmPost(ModelPart arm, float x, float z, boolean right, boolean sneaking, int light, PoseStack matrix, VertexConsumer builder)
|
|
||||||
{
|
|
||||||
matrix.pushPose();
|
|
||||||
arm.visible = true;
|
|
||||||
if (right)
|
|
||||||
matrix.translate(0.015, 0, 0);
|
|
||||||
else
|
|
||||||
matrix.translate(-0.015, 0, 0);
|
|
||||||
|
|
||||||
if (!sneaking)
|
|
||||||
arm.y = 20;
|
|
||||||
else
|
|
||||||
arm.y = 15;
|
|
||||||
|
|
||||||
arm.xRot = x;
|
|
||||||
arm.yRot = 0;
|
|
||||||
arm.zRot = -z;
|
|
||||||
arm.render(matrix, builder, light, 655360);
|
|
||||||
arm.y = 2;
|
|
||||||
matrix.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
private void renderArmPre(ModelPart arm)
|
|
||||||
{
|
|
||||||
arm.visible = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean handleMobends()
|
|
||||||
{
|
|
||||||
// TODO MOBENDS
|
|
||||||
// if (ModList.get().isLoaded("mobends"))
|
|
||||||
// {
|
|
||||||
// Configuration config = new Configuration(new
|
|
||||||
// File(CarryOn.CONFIGURATION_FILE.getPath().substring(0,
|
|
||||||
// CarryOn.CONFIGURATION_FILE.getPath().length() - 16), "mobends.cfg"));
|
|
||||||
//
|
|
||||||
// boolean renderPlayer = config.get("animated", "player",
|
|
||||||
// true).getBoolean();
|
|
||||||
// return !renderPlayer;
|
|
||||||
// }
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean doSneakCheck(Player player)
|
|
||||||
{
|
|
||||||
if (player.getAbilities().flying)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return player.isShiftKeyDown() || player.isCrouching();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isChest(Block block)
|
|
||||||
{
|
|
||||||
return block == Blocks.CHEST || block == Blocks.ENDER_CHEST || block == Blocks.TRAPPED_CHEST;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
private static PlayerRenderer getRenderPlayer(AbstractClientPlayer player)
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
EntityRenderDispatcher manager = mc.getEntityRenderDispatcher();
|
|
||||||
return (PlayerRenderer) manager.getSkinMap().get(player.getModelName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
private static PlayerModel<AbstractClientPlayer> getPlayerModel(AbstractClientPlayer player)
|
|
||||||
{
|
|
||||||
return getRenderPlayer(player).getModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @SubscribeEvent
|
|
||||||
// @OnlyIn(Dist.CLIENT)
|
|
||||||
// public void hideItems(RenderSpecificHandEvent event)
|
|
||||||
// {
|
|
||||||
// ItemStack stack = event.getItemStack();
|
|
||||||
//
|
|
||||||
// if (stack != null && (stack.getItem() == RegistrationHandler.itemTile.get() ||
|
|
||||||
// stack.getItem() == RegistrationHandler.itemEntity.get()))
|
|
||||||
// {
|
|
||||||
// event.setCanceled(true);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
package tschipp.carryon.client.helper;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.math.Quaternion;
|
|
||||||
import com.mojang.math.Vector3f;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
|
||||||
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
|
|
||||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import tschipp.carryon.common.handler.ModelOverridesHandler;
|
|
||||||
import tschipp.carryon.common.helper.ScriptParseHelper;
|
|
||||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
|
||||||
|
|
||||||
public class CarryRenderHelper
|
|
||||||
{
|
|
||||||
public static Vec3 getExactPos(Entity entity, float partialticks)
|
|
||||||
{
|
|
||||||
return new Vec3(entity.xOld + (entity.getX() - entity.xOld) * partialticks, entity.yOld + (entity.getY() - entity.yOld) * partialticks, entity.zOld + (entity.getZ() - entity.zOld) * partialticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getExactBodyRotationDegrees(LivingEntity entity, float partialticks)
|
|
||||||
{
|
|
||||||
if (entity.getVehicle() != null && entity.getVehicle() instanceof LivingEntity)
|
|
||||||
return -(entity.yHeadRotO + (entity.yHeadRot - entity.yHeadRotO) * partialticks);
|
|
||||||
else
|
|
||||||
return -(entity.yBodyRotO + (entity.yBodyRot - entity.yBodyRotO) * partialticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Quaternion getExactBodyRotation(LivingEntity entity, float partialticks)
|
|
||||||
{
|
|
||||||
return Vector3f.YP.rotationDegrees(getExactBodyRotationDegrees(entity, partialticks));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void performOverrideTransformation(PoseStack matrix, CarryOnOverride override)
|
|
||||||
{
|
|
||||||
int perspective = getPerspective();
|
|
||||||
|
|
||||||
float[] translation = ScriptParseHelper.getXYZArray(override.getRenderTranslation());
|
|
||||||
float[] rotation = ScriptParseHelper.getXYZArray(override.getRenderRotation());
|
|
||||||
float[] scaled = ScriptParseHelper.getScaled(override.getRenderScaled());
|
|
||||||
|
|
||||||
Quaternion rot = Vector3f.XP.rotationDegrees(rotation[0]);
|
|
||||||
rot.mul(Vector3f.YP.rotationDegrees(rotation[1]));
|
|
||||||
rot.mul(Vector3f.ZP.rotationDegrees(rotation[2]));
|
|
||||||
matrix.mulPose(rot);
|
|
||||||
|
|
||||||
matrix.translate(translation[0], translation[1], perspective == 1 && override.isBlock() ? -translation[2] : translation[2]);
|
|
||||||
|
|
||||||
matrix.scale(scaled[0], scaled[1], scaled[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderItem(BlockState state, CompoundTag tag, ItemStack stack, ItemStack tileStack, PoseStack matrix, MultiBufferSource buffer, int light, BakedModel model)
|
|
||||||
{
|
|
||||||
ItemRenderer renderer = Minecraft.getInstance().getItemRenderer();
|
|
||||||
if (ModelOverridesHandler.hasCustomOverrideModel(state, tag))
|
|
||||||
{
|
|
||||||
Object override = ModelOverridesHandler.getOverrideObject(state, tag);
|
|
||||||
|
|
||||||
if (override instanceof ItemStack)
|
|
||||||
{
|
|
||||||
renderer.render((ItemStack) override, TransformType.NONE, false, matrix, buffer, light, OverlayTexture.NO_OVERLAY, model);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.render(tileStack.isEmpty() ? stack : tileStack, TransformType.NONE, false, matrix, buffer, light, OverlayTexture.NO_OVERLAY, model);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
public static int getPerspective()
|
|
||||||
{
|
|
||||||
boolean isThirdPerson = !Minecraft.getInstance().options.getCameraType().isFirstPerson(); // isThirdPerson
|
|
||||||
boolean isThirdPersonReverse = Minecraft.getInstance().options.getCameraType().isMirrored();
|
|
||||||
|
|
||||||
if (!isThirdPerson && !isThirdPersonReverse)
|
|
||||||
return 0;
|
|
||||||
if (isThirdPerson && !isThirdPersonReverse)
|
|
||||||
return 1;
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
package tschipp.carryon.client.keybinds;
|
|
||||||
|
|
||||||
import net.minecraft.client.KeyMapping;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
|
|
||||||
@EventBusSubscriber(modid = CarryOn.MODID, bus = Bus.MOD, value = Dist.CLIENT)
|
|
||||||
public class CarryOnKeybinds
|
|
||||||
{
|
|
||||||
|
|
||||||
public static final String KEYBIND_KEY = "carryOnKeyPressed";
|
|
||||||
public static KeyMapping carryKey;
|
|
||||||
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void registerKeybinds(RegisterKeyMappingsEvent event)
|
|
||||||
{
|
|
||||||
carryKey = new KeyMapping("key.carry.desc", 340, "key.carry.category");
|
|
||||||
|
|
||||||
event.register(carryKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isKeyPressed(Player player)
|
|
||||||
{
|
|
||||||
CompoundTag tag = player.getPersistentData();
|
|
||||||
if (tag != null && tag.contains(KEYBIND_KEY))
|
|
||||||
{
|
|
||||||
return tag.getBoolean(KEYBIND_KEY);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setKeyPressed(Player player, boolean pressed)
|
|
||||||
{
|
|
||||||
CompoundTag tag = player.getPersistentData();
|
|
||||||
tag.putBoolean(KEYBIND_KEY, pressed);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package tschipp.carryon.common.capabilities;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
|
|
||||||
public interface IPosition
|
|
||||||
{
|
|
||||||
|
|
||||||
public BlockPos getPos();
|
|
||||||
|
|
||||||
public void setPos(BlockPos pos);
|
|
||||||
|
|
||||||
public boolean isBlockActivated();
|
|
||||||
|
|
||||||
public void setBlockActivated(boolean b);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
package tschipp.carryon.common.capabilities;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
|
||||||
import net.minecraftforge.common.capabilities.CapabilityToken;
|
|
||||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
|
|
||||||
public class PositionProvider implements ICapabilitySerializable<CompoundTag>
|
|
||||||
{
|
|
||||||
|
|
||||||
public static final Capability<IPosition> POSITION_CAPABILITY = CapabilityManager.get(new CapabilityToken<>(){});
|
|
||||||
|
|
||||||
private IPosition instance = new TEPosition();// POSITION_CAPABILITY.getDefaultInstance();
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side)
|
|
||||||
{
|
|
||||||
if (cap == POSITION_CAPABILITY)
|
|
||||||
return (LazyOptional<T>) LazyOptional.of(TEPosition::new);
|
|
||||||
|
|
||||||
return LazyOptional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundTag serializeNBT()
|
|
||||||
{
|
|
||||||
CompoundTag tag = new CompoundTag();
|
|
||||||
|
|
||||||
tag.putBoolean("blockActivated", this.instance.isBlockActivated());
|
|
||||||
tag.putInt("x", this.instance.getPos().getX());
|
|
||||||
tag.putInt("y", this.instance.getPos().getY());
|
|
||||||
tag.putInt("z", this.instance.getPos().getZ());
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deserializeNBT(CompoundTag nbt)
|
|
||||||
{
|
|
||||||
CompoundTag tag = nbt;
|
|
||||||
|
|
||||||
int x = tag.getInt("x");
|
|
||||||
int y = tag.getInt("y");
|
|
||||||
int z = tag.getInt("z");
|
|
||||||
|
|
||||||
BlockPos pos = new BlockPos(x, y, z);
|
|
||||||
|
|
||||||
this.instance.setPos(pos);
|
|
||||||
this.instance.setBlockActivated(tag.getBoolean("blockActivated"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
package tschipp.carryon.common.capabilities;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
|
|
||||||
public class TEPosition implements IPosition
|
|
||||||
{
|
|
||||||
|
|
||||||
private BlockPos pos = new BlockPos(0, 0, 0);
|
|
||||||
private boolean blockActivated = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockPos getPos()
|
|
||||||
{
|
|
||||||
return this.pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPos(BlockPos pos)
|
|
||||||
{
|
|
||||||
this.pos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBlockActivated()
|
|
||||||
{
|
|
||||||
return this.blockActivated;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBlockActivated(boolean b)
|
|
||||||
{
|
|
||||||
this.blockActivated = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
package tschipp.carryon.common.capabilities.event;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.client.event.ScreenEvent;
|
|
||||||
import net.minecraftforge.event.TickEvent.PlayerTickEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
|
||||||
import tschipp.carryon.common.capabilities.IPosition;
|
|
||||||
import tschipp.carryon.common.capabilities.PositionProvider;
|
|
||||||
import tschipp.carryon.common.capabilities.TEPosition;
|
|
||||||
|
|
||||||
public class PositionClientEvents
|
|
||||||
{
|
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onGui(ScreenEvent.BackgroundRendered event)
|
|
||||||
{
|
|
||||||
if (event.getScreen() != null)
|
|
||||||
{
|
|
||||||
Player player = Minecraft.getInstance().player;
|
|
||||||
boolean inventory = event.getScreen() instanceof AbstractContainerScreen;
|
|
||||||
|
|
||||||
if (player != null && inventory && player.getCapability(PositionProvider.POSITION_CAPABILITY).isPresent())
|
|
||||||
{
|
|
||||||
IPosition cap = player.getCapability(PositionProvider.POSITION_CAPABILITY).orElse(new TEPosition());
|
|
||||||
if (cap.isBlockActivated())
|
|
||||||
{
|
|
||||||
Level level = player.level;
|
|
||||||
BlockPos pos = cap.getPos();
|
|
||||||
if (level != null)
|
|
||||||
{
|
|
||||||
BlockEntity te = level.getBlockEntity(pos);
|
|
||||||
if (te == null)
|
|
||||||
{
|
|
||||||
// player.openContainer = null;
|
|
||||||
Minecraft.getInstance().screen = null;
|
|
||||||
// Minecraft.getInstance().fo;
|
|
||||||
cap.setBlockActivated(false);
|
|
||||||
cap.setPos(new BlockPos(0, 0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onGuiClose(PlayerContainerEvent.Close event)
|
|
||||||
{
|
|
||||||
Player player = event.getEntity();
|
|
||||||
if (player.getCapability(PositionProvider.POSITION_CAPABILITY).isPresent())
|
|
||||||
{
|
|
||||||
IPosition cap = player.getCapability(PositionProvider.POSITION_CAPABILITY).orElse(new TEPosition());
|
|
||||||
cap.setBlockActivated(false);
|
|
||||||
cap.setPos(new BlockPos(0, 0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onPlayerTick(PlayerTickEvent event)
|
|
||||||
{
|
|
||||||
if (event.side == LogicalSide.CLIENT)
|
|
||||||
{
|
|
||||||
Player player = event.player;
|
|
||||||
if (player.getCapability(PositionProvider.POSITION_CAPABILITY).isPresent())
|
|
||||||
{
|
|
||||||
IPosition cap = player.getCapability(PositionProvider.POSITION_CAPABILITY).orElse(new TEPosition());
|
|
||||||
if (cap.isBlockActivated() && Minecraft.getInstance().screen == null)
|
|
||||||
{
|
|
||||||
cap.setBlockActivated(false);
|
|
||||||
cap.setPos(new BlockPos(0, 0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
package tschipp.carryon.common.capabilities.event;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
|
||||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.common.capabilities.IPosition;
|
|
||||||
import tschipp.carryon.common.capabilities.PositionProvider;
|
|
||||||
import tschipp.carryon.common.capabilities.TEPosition;
|
|
||||||
|
|
||||||
public class PositionCommonEvents
|
|
||||||
{
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onAttachCaps(AttachCapabilitiesEvent<Entity> event)
|
|
||||||
{
|
|
||||||
if (event.getObject() instanceof Player)
|
|
||||||
{
|
|
||||||
event.addCapability(new ResourceLocation(CarryOn.MODID, "position"), new PositionProvider());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onBlockRight(PlayerInteractEvent.RightClickBlock event)
|
|
||||||
{
|
|
||||||
BlockPos pos = event.getPos();
|
|
||||||
Level level = event.getLevel();
|
|
||||||
Player player = event.getEntity();
|
|
||||||
|
|
||||||
if (event.isCanceled() || player == null || player instanceof FakePlayer)
|
|
||||||
return;
|
|
||||||
|
|
||||||
BlockEntity te = level.getBlockEntity(pos);
|
|
||||||
if (te != null && player.getCapability(PositionProvider.POSITION_CAPABILITY).isPresent())
|
|
||||||
{
|
|
||||||
IPosition cap = player.getCapability(PositionProvider.POSITION_CAPABILITY).orElse(new TEPosition());
|
|
||||||
cap.setBlockActivated(true);
|
|
||||||
cap.setPos(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,122 +0,0 @@
|
||||||
package tschipp.carryon.common.command;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
import net.minecraft.commands.Commands;
|
|
||||||
import net.minecraft.commands.arguments.EntityArgument;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.common.handler.CustomPickupOverrideHandler;
|
|
||||||
import tschipp.carryon.common.handler.ModelOverridesHandler;
|
|
||||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonBlock;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonEntity;
|
|
||||||
import tschipp.carryon.network.client.CarrySlotPacket;
|
|
||||||
|
|
||||||
public class CommandCarryOn
|
|
||||||
{
|
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
|
||||||
{
|
|
||||||
LiteralArgumentBuilder<CommandSourceStack> builder = Commands.literal("carryon")
|
|
||||||
|
|
||||||
.then(Commands.literal("debug").executes(cmd -> handleDebug(cmd.getSource())))
|
|
||||||
|
|
||||||
.then(Commands.literal("clear").executes(cmd -> handleClear(cmd.getSource(), Collections.singleton(cmd.getSource().getPlayerOrException()))))
|
|
||||||
|
|
||||||
.then(Commands.literal("clear").then(Commands.argument("target", EntityArgument.players()).requires(src -> src.hasPermission(2)).executes(cmd -> handleClear(cmd.getSource(), EntityArgument.getPlayers(cmd, "target")))))
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
dispatcher.register(builder);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int handleDebug(CommandSourceStack source)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (source.getEntityOrException() != null)
|
|
||||||
{
|
|
||||||
ServerPlayer player = source.getPlayerOrException();
|
|
||||||
|
|
||||||
ItemStack main = player.getMainHandItem();
|
|
||||||
if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemTile.get())
|
|
||||||
{
|
|
||||||
source.sendSuccess(Component.literal("Block: " + ItemCarryonBlock.getBlock(main)), true);
|
|
||||||
source.sendSuccess(Component.literal("BlockState: " + ItemCarryonBlock.getBlockState(main)), true);
|
|
||||||
source.sendSuccess(Component.literal("ItemStack: " + ItemCarryonBlock.getItemStack(main)), true);
|
|
||||||
|
|
||||||
if (ModelOverridesHandler.hasCustomOverrideModel(ItemCarryonBlock.getBlockState(main), ItemCarryonBlock.getTileData(main)))
|
|
||||||
source.sendSuccess(Component.literal("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemCarryonBlock.getBlockState(main), ItemCarryonBlock.getTileData(main))), true);
|
|
||||||
|
|
||||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemCarryonBlock.getBlockState(main)))
|
|
||||||
source.sendSuccess(Component.literal("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemCarryonBlock.getBlockState(main))), true);
|
|
||||||
|
|
||||||
CarryOn.LOGGER.info("Block: " + ItemCarryonBlock.getBlock(main));
|
|
||||||
CarryOn.LOGGER.info("BlockState: " + ItemCarryonBlock.getBlockState(main));
|
|
||||||
CarryOn.LOGGER.info("ItemStack: " + ItemCarryonBlock.getItemStack(main));
|
|
||||||
|
|
||||||
if (ModelOverridesHandler.hasCustomOverrideModel(ItemCarryonBlock.getBlockState(main), ItemCarryonBlock.getTileData(main)))
|
|
||||||
CarryOn.LOGGER.info("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemCarryonBlock.getBlockState(main), ItemCarryonBlock.getTileData(main)));
|
|
||||||
|
|
||||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemCarryonBlock.getBlockState(main)))
|
|
||||||
CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemCarryonBlock.getBlockState(main)));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity.get())
|
|
||||||
{
|
|
||||||
source.sendSuccess(Component.literal("Entity: " + ItemCarryonEntity.getEntity(main, player.level)), true);
|
|
||||||
source.sendSuccess(Component.literal("Entity Name: " + ItemCarryonEntity.getEntityName(main)), true);
|
|
||||||
|
|
||||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemCarryonEntity.getEntity(main, player.level)))
|
|
||||||
source.sendSuccess(Component.literal("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemCarryonEntity.getEntity(main, player.level))), true);
|
|
||||||
|
|
||||||
CarryOn.LOGGER.info("Entity: " + ItemCarryonEntity.getEntity(main, player.level));
|
|
||||||
CarryOn.LOGGER.info("Entity Name: " + ItemCarryonEntity.getEntityName(main));
|
|
||||||
|
|
||||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemCarryonEntity.getEntity(main, player.level)))
|
|
||||||
CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemCarryonEntity.getEntity(main, player.level)));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (CommandSyntaxException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int handleClear(CommandSourceStack source, Collection<ServerPlayer> players)
|
|
||||||
{
|
|
||||||
for (ServerPlayer player : players)
|
|
||||||
{
|
|
||||||
int cleared = 0;
|
|
||||||
cleared += player.getInventory().clearOrCountMatchingItems(stack -> !stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile.get(), 64, player.inventoryMenu.getCraftSlots()); // TODO
|
|
||||||
cleared += player.getInventory().clearOrCountMatchingItems(stack -> !stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity.get(), 64, player.inventoryMenu.getCraftSlots());
|
|
||||||
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> player), new CarrySlotPacket(9, player.getId()));
|
|
||||||
|
|
||||||
if (cleared != 1)
|
|
||||||
source.sendSuccess(Component.literal("Cleared " + cleared + " Items!"), true);
|
|
||||||
else
|
|
||||||
source.sendSuccess(Component.literal("Cleared " + cleared + " Item!"), true);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package tschipp.carryon.common.config;
|
|
||||||
|
|
||||||
public class CarryOnConfig
|
|
||||||
{
|
|
||||||
|
|
||||||
public static Configs.Settings settings = new Configs.Settings();
|
|
||||||
|
|
||||||
public static Configs.Blacklist blacklist = new Configs.Blacklist();
|
|
||||||
|
|
||||||
public static Configs.WhiteList whitelist = new Configs.WhiteList();
|
|
||||||
|
|
||||||
public static Configs.ModelOverrides modelOverrides = new Configs.ModelOverrides();
|
|
||||||
|
|
||||||
public static Configs.CustomPickupConditions customPickupConditions = new Configs.CustomPickupConditions();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,329 +0,0 @@
|
||||||
package tschipp.carryon.common.config;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
|
||||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec.DoubleValue;
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec.IntValue;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
|
||||||
import net.minecraftforge.fml.event.config.ModConfigEvent;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.common.handler.ListHandler;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(modid = CarryOn.MODID, bus = Bus.MOD)
|
|
||||||
public class Configs {
|
|
||||||
|
|
||||||
private static final ForgeConfigSpec.Builder SERVER_BUILDER = new ForgeConfigSpec.Builder();
|
|
||||||
private static final ForgeConfigSpec.Builder CLIENT_BUILDER = new ForgeConfigSpec.Builder();
|
|
||||||
|
|
||||||
public static final ForgeConfigSpec SERVER_CONFIG;
|
|
||||||
public static final ForgeConfigSpec CLIENT_CONFIG;
|
|
||||||
|
|
||||||
public static boolean SERVER_LOADED = false;
|
|
||||||
|
|
||||||
static {
|
|
||||||
|
|
||||||
Settings.init(SERVER_BUILDER, CLIENT_BUILDER);
|
|
||||||
Blacklist.init(SERVER_BUILDER, CLIENT_BUILDER);
|
|
||||||
WhiteList.init(SERVER_BUILDER, CLIENT_BUILDER);
|
|
||||||
ModelOverrides.init(SERVER_BUILDER, CLIENT_BUILDER);
|
|
||||||
CustomPickupConditions.init(SERVER_BUILDER, CLIENT_BUILDER);
|
|
||||||
|
|
||||||
SERVER_CONFIG = SERVER_BUILDER.build();
|
|
||||||
CLIENT_CONFIG = CLIENT_BUILDER.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onLoad(final ModConfigEvent event) {
|
|
||||||
if (event.getConfig().getModId().equals(CarryOn.MODID) && event.getConfig().getSpec() == SERVER_CONFIG) {
|
|
||||||
SERVER_LOADED = true;
|
|
||||||
|
|
||||||
CommentedConfig cfg = event.getConfig().getConfigData();
|
|
||||||
|
|
||||||
if (cfg instanceof CommentedFileConfig cfig) {
|
|
||||||
cfig.load();
|
|
||||||
ListHandler.initConfigLists();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @SubscribeEvent
|
|
||||||
// public static void onConfigChanged(ModConfigEvent.Reloading event) {
|
|
||||||
// if (event.getConfig().getModId().equals(CarryOn.MODID) && event.getConfig().getSpec() == SERVER_CONFIG) {
|
|
||||||
//
|
|
||||||
// CommentedConfig cfg = event.getConfig().getConfigData();
|
|
||||||
//
|
|
||||||
// if (cfg instanceof CommentedFileConfig)
|
|
||||||
// {
|
|
||||||
// ((CommentedFileConfig) cfg).load();
|
|
||||||
// ListHandler.initConfigLists();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static class Settings {
|
|
||||||
public static BooleanValue facePlayer;
|
|
||||||
|
|
||||||
public static BooleanValue heavyTiles;
|
|
||||||
|
|
||||||
public static BooleanValue pickupAllBlocks;
|
|
||||||
|
|
||||||
public static BooleanValue slownessInCreative;
|
|
||||||
|
|
||||||
public static DoubleValue maxDistance;
|
|
||||||
|
|
||||||
public static DoubleValue maxEntityWidth;
|
|
||||||
|
|
||||||
public static DoubleValue maxEntityHeight;
|
|
||||||
|
|
||||||
public static BooleanValue pickupHostileMobs;
|
|
||||||
|
|
||||||
public static BooleanValue heavyEntities;
|
|
||||||
|
|
||||||
public static DoubleValue blockSlownessMultiplier;
|
|
||||||
|
|
||||||
public static DoubleValue entitySlownessMultiplier;
|
|
||||||
|
|
||||||
public static BooleanValue renderArms;
|
|
||||||
|
|
||||||
public static BooleanValue allowBabies;
|
|
||||||
|
|
||||||
public static BooleanValue useWhitelistBlocks;
|
|
||||||
|
|
||||||
public static BooleanValue useWhitelistEntities;
|
|
||||||
|
|
||||||
public static BooleanValue useWhitelistStacking;
|
|
||||||
|
|
||||||
public static BooleanValue hitWhileCarrying;
|
|
||||||
|
|
||||||
public static BooleanValue dropCarriedWhenHit;
|
|
||||||
|
|
||||||
public static BooleanValue useScripts;
|
|
||||||
|
|
||||||
public static BooleanValue stackableEntities;
|
|
||||||
|
|
||||||
public static IntValue maxEntityStackLimit;
|
|
||||||
|
|
||||||
public static BooleanValue entitySizeMattersStacking;
|
|
||||||
|
|
||||||
public static void init(ForgeConfigSpec.Builder s, ForgeConfigSpec.Builder c) {
|
|
||||||
c.comment("Settings");
|
|
||||||
s.comment("Settings");
|
|
||||||
|
|
||||||
s.push("settings");
|
|
||||||
c.push("settings");
|
|
||||||
|
|
||||||
maxDistance = s.comment("Maximum distance from where Blocks and Entities can be picked up")
|
|
||||||
.defineInRange("maxDistance", 2.5, 0, Double.MAX_VALUE);
|
|
||||||
|
|
||||||
maxEntityWidth = s.comment("Max width of entities that can be picked up in survival mode")
|
|
||||||
.defineInRange("maxEntityWidth", 1.5, 0, 10);
|
|
||||||
|
|
||||||
maxEntityHeight = s.comment("Max height of entities that can be picked up in survival mode")
|
|
||||||
.defineInRange("maxEntityHeight", 2.0, 0, 10);
|
|
||||||
|
|
||||||
blockSlownessMultiplier = s.comment("Slowness multiplier for blocks")
|
|
||||||
.defineInRange("blockSlownessMultiplier", 1, 0, Double.MAX_VALUE);
|
|
||||||
|
|
||||||
entitySlownessMultiplier = s.comment("Slowness multiplier for entities")
|
|
||||||
.defineInRange("entitySlownessMultiplier", 1, 0, Double.MAX_VALUE);
|
|
||||||
|
|
||||||
maxEntityStackLimit = s.comment("Maximum stack limit for entities").defineInRange("maxEntityStackLimit", 10,
|
|
||||||
1, Integer.MAX_VALUE);
|
|
||||||
|
|
||||||
facePlayer = c.comment("If the front of the Tile Entities should face the player or should face outward")
|
|
||||||
.define("facePlayer", false);
|
|
||||||
|
|
||||||
heavyTiles = s.comment("More complex Tile Entities slow down the player more").define("heavyTiles", true);
|
|
||||||
|
|
||||||
pickupAllBlocks = s.comment("Allow all blocks to be picked up, not just Tile Entites")
|
|
||||||
.define("pickupAllBlocks", false);
|
|
||||||
|
|
||||||
slownessInCreative = s.comment("Whether Blocks and Entities slow the creative player down when carried")
|
|
||||||
.define("slownessInCreative", true);
|
|
||||||
|
|
||||||
pickupHostileMobs = s.comment("Whether hostile mobs should be able to picked up in survival mode")
|
|
||||||
.define("pickupHostileMobs", false);
|
|
||||||
|
|
||||||
heavyEntities = s.comment("Larger Entities slow down the player more").define("heavyEntities", true);
|
|
||||||
|
|
||||||
renderArms = c.comment("Arms should render on sides when carrying").define("renderArms", true);
|
|
||||||
|
|
||||||
allowBabies = s
|
|
||||||
.comment("Allow babies to be carried even when adult mob is blacklisted (or not whitelisted)")
|
|
||||||
.define("allowBabies", false);
|
|
||||||
|
|
||||||
useWhitelistBlocks = s.comment("Use Whitelist instead of Blacklist for Blocks").define("useWhitelistBlocks",
|
|
||||||
false);
|
|
||||||
|
|
||||||
useWhitelistEntities = s.comment("Use Whitelist instead of Blacklist for Entities")
|
|
||||||
.define("useWhitelistEntities", false);
|
|
||||||
|
|
||||||
useWhitelistStacking = s.comment("Use Whitelist instead of Blacklist for Stacking")
|
|
||||||
.define("useWhitelistStacking", false);
|
|
||||||
|
|
||||||
hitWhileCarrying = s.comment("Whether the player can hit blocks and entities while carrying or not")
|
|
||||||
.define("hitWhileCarrying", false);
|
|
||||||
|
|
||||||
dropCarriedWhenHit = s.comment("Whether the player drops the carried object when hit or not")
|
|
||||||
.define("dropCarriedWhenHit", false);
|
|
||||||
|
|
||||||
useScripts = s.comment(
|
|
||||||
"Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will increase your performance")
|
|
||||||
.worldRestart().define("useScripts", false);
|
|
||||||
|
|
||||||
stackableEntities = s.comment("Allows entities to be stacked using Carry On").define("stackableEntities",
|
|
||||||
true);
|
|
||||||
|
|
||||||
entitySizeMattersStacking = s.comment("Whether entities' size matters when stacking or not")
|
|
||||||
.define("stackableEntities", true);
|
|
||||||
|
|
||||||
s.pop();
|
|
||||||
c.pop();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class WhiteList {
|
|
||||||
public static ConfigValue<List<? extends String>> allowedEntities;
|
|
||||||
|
|
||||||
public static ConfigValue<List<? extends String>> allowedBlocks;
|
|
||||||
|
|
||||||
public static ConfigValue<List<? extends String>> allowedStacking;
|
|
||||||
|
|
||||||
public static void init(ForgeConfigSpec.Builder s, ForgeConfigSpec.Builder c) {
|
|
||||||
s.comment(
|
|
||||||
"Whitelist. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Black---and-Whitelist-Config");
|
|
||||||
|
|
||||||
allowedEntities = s.comment("Entities that CAN be picked up (useWhitelistEntities must be true)")
|
|
||||||
.defineList("whitelist.allowedEntities", Arrays.asList(),
|
|
||||||
obj -> obj instanceof String ? true : false);
|
|
||||||
|
|
||||||
allowedBlocks = s.comment("Blocks that CAN be picked up (useWhitelistBlocks must be true)").defineList(
|
|
||||||
"whitelist.allowedBlocks", Arrays.asList(), obj -> obj instanceof String ? true : false);
|
|
||||||
|
|
||||||
allowedStacking = s.comment(
|
|
||||||
"Entities that CAN have other entities stacked on top of them (useWhitelistStacking must be true)")
|
|
||||||
.defineList("whitelist.allowedStacking", Arrays.asList(),
|
|
||||||
obj -> obj instanceof String ? true : false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Blacklist {
|
|
||||||
public static ConfigValue<List<? extends String>> forbiddenTiles;
|
|
||||||
|
|
||||||
public static ConfigValue<List<? extends String>> forbiddenEntities;
|
|
||||||
|
|
||||||
public static ConfigValue<List<? extends String>> forbiddenStacking;
|
|
||||||
|
|
||||||
public static void init(ForgeConfigSpec.Builder s, ForgeConfigSpec.Builder c) {
|
|
||||||
s.comment(
|
|
||||||
"Blacklist. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Black---and-Whitelist-Config");
|
|
||||||
|
|
||||||
forbiddenTiles = s.comment("Blocks that cannot be picked up").defineList("blacklist.forbiddenTiles",
|
|
||||||
Arrays.asList("#forge:immovable", "#forge:relocation_not_supported", "minecraft:end_portal",
|
|
||||||
"minecraft:end_gateway", "minecraft:tall_grass", "minecraft:large_fern", "minecraft:peony",
|
|
||||||
"minecraft:rose_bush", "minecraft:lilac", "minecraft:sunflower", "minecraft:*_bed",
|
|
||||||
"minecraft:oak_door", "minecraft:iron_door", "minecraft:spruce_door",
|
|
||||||
"minecraft:birch_door", "minecraft:jungle_door", "minecraft:acacia_door",
|
|
||||||
"minecraft:dark_oak_door", "minecraft:waterlily", "minecraft:cake",
|
|
||||||
"minecraft:nether_portal", "minecraft:tall_seagrass", "animania:block_trough",
|
|
||||||
"animania:block_invisiblock", "colossalchests:*", "ic2:*", "bigreactors:*", "forestry:*",
|
|
||||||
"tconstruct:*", "rustic:*", "botania:*", "astralsorcery:*", "quark:colored_bed_*",
|
|
||||||
"immersiveengineering:*", "embers:block_furnace", "embers:ember_bore",
|
|
||||||
"embers:ember_activator", "embers:mixer", "embers:heat_coil", "embers:large_tank",
|
|
||||||
"embers:crystal_cell", "embers:alchemy_pedestal", "embers:boiler", "embers:combustor",
|
|
||||||
"embers:catalzyer", "embers:field_chart", "embers:inferno_forge",
|
|
||||||
"storagedrawers:framingtable", "skyresources:*", "lootbags:*", "exsartagine:*",
|
|
||||||
"aquamunda:tank", "opencomputers:*", "malisisdoors:*", "industrialforegoing:*",
|
|
||||||
"minecolonies:*", "thaumcraft:pillar*", "thaumcraft:infernal_furnace",
|
|
||||||
"thaumcraft:placeholder*", "thaumcraft:infusion_matrix", "thaumcraft:golem_builder",
|
|
||||||
"thaumcraft:thaumatorium*", "magneticraft:oil_heater", "magneticraft:solar_panel",
|
|
||||||
"magneticraft:steam_engine", "magneticraft:shelving_unit", "magneticraft:grinder",
|
|
||||||
"magneticraft:sieve", "magneticraft:solar_tower", "magneticraft:solar_mirror",
|
|
||||||
"magneticraft:container", "magneticraft:pumpjack", "magneticraft:solar_panel",
|
|
||||||
"magneticraft:refinery", "magneticraft:oil_heater", "magneticraft:hydraulic_press",
|
|
||||||
"magneticraft:multiblock_gap", "refinedstorage:*", "mcmultipart:*", "enderstorage:*",
|
|
||||||
"betterstorage:*", "practicallogistics2:*", "wearablebackpacks:*", "rftools:screen",
|
|
||||||
"rftools:creative_screen", "create:*", "magic_doorknob:*", "iceandfire:*", "ftbquests:*",
|
|
||||||
"waystones:*"),
|
|
||||||
obj -> obj instanceof String);
|
|
||||||
|
|
||||||
forbiddenEntities = s.comment("Entities that cannot be picked up").defineList("blacklist.forbiddenEntities",
|
|
||||||
Arrays.asList("minecraft:end_crystal", "minecraft:ender_dragon", "minecraft:ghast",
|
|
||||||
"minecraft:shulker", "minecraft:leash_knot", "minecraft:armor_stand",
|
|
||||||
"minecraft:item_frame", "minecraft:painting", "minecraft:shulker_bullet",
|
|
||||||
"animania:hamster", "animania:ferret*", "animania:hedgehog*", "animania:cart",
|
|
||||||
"animania:wagon", "mynko:*", "pixelmon:*", "mocreatures:*", "quark:totem", "vehicle:*"),
|
|
||||||
obj -> obj instanceof String ? true : false);
|
|
||||||
|
|
||||||
forbiddenStacking = s.comment("Entities that cannot have other entities stacked on top of them").defineList(
|
|
||||||
"blacklist.forbiddenStacking", Arrays.asList("minecraft:horse"),
|
|
||||||
obj -> obj instanceof String ? true : false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ModelOverrides {
|
|
||||||
public static ConfigValue<List<? extends String>> modelOverrides;
|
|
||||||
|
|
||||||
public static void init(ForgeConfigSpec.Builder s, ForgeConfigSpec.Builder c) {
|
|
||||||
c.comment(
|
|
||||||
"Model Overrides. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Model-Override-Config");
|
|
||||||
|
|
||||||
modelOverrides = c.comment("Model Overrides based on NBT or on Meta. Advanced Users Only!").defineList(
|
|
||||||
"modeloverrides.overrides",
|
|
||||||
Arrays.asList("minecraft:hopper->(block)minecraft:hopper",
|
|
||||||
"minecraft:comparator->(block)minecraft:comparator",
|
|
||||||
"minecraft:repeater->(block)minecraft:repeater",
|
|
||||||
"minecraft:cauldron->(block)minecraft:cauldron",
|
|
||||||
"minecraft:brewing_stand->(item)minecraft:brewing_stand",
|
|
||||||
"minecraft:flower_pot->(block)minecraft:flower_pot",
|
|
||||||
"minecraft:sugar_cane->(block)minecraft:sugar_cane",
|
|
||||||
"minecraft:redstone_wire->(item)minecraft:redstone",
|
|
||||||
"animania:block_nest->(block)animania:block_nest",
|
|
||||||
"animania:cheese_mold;0->(block)animania:cheese_mold;0",
|
|
||||||
"animania:cheese_mold;1->(block)animania:cheese_mold;1",
|
|
||||||
"animania:cheese_mold;2->(block)animania:cheese_mold;2",
|
|
||||||
"animania:cheese_mold;3->(block)animania:cheese_mold;3",
|
|
||||||
"animania:cheese_mold;4->(block)animania:cheese_mold;4",
|
|
||||||
"animania:cheese_mold;5->(block)animania:cheese_mold;5",
|
|
||||||
"animania:cheese_mold;6->(block)animania:cheese_mold;6",
|
|
||||||
"animania:cheese_mold;7->(block)animania:cheese_mold;7",
|
|
||||||
"animania:cheese_mold;8->(block)animania:cheese_mold;8",
|
|
||||||
"animania:cheese_mold;9->(block)animania:cheese_mold;9",
|
|
||||||
"animania:cheese_mold;10->(block)animania:cheese_mold;10"),
|
|
||||||
obj -> obj instanceof String ? true : false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CustomPickupConditions {
|
|
||||||
|
|
||||||
public static ConfigValue<List<? extends String>> customPickupConditionsBlocks;
|
|
||||||
|
|
||||||
public static ConfigValue<List<? extends String>> customPickupConditionsEntities;
|
|
||||||
|
|
||||||
public static void init(ForgeConfigSpec.Builder s, ForgeConfigSpec.Builder c) {
|
|
||||||
s.comment(
|
|
||||||
"Custom Pickup Conditions. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Custom-Pickup-Condition-Config");
|
|
||||||
|
|
||||||
customPickupConditionsBlocks = s.comment("Custom Pickup Conditions for Blocks").defineList(
|
|
||||||
"custom_pickup_conditions.customPickupConditionsBlocks", Arrays.asList(),
|
|
||||||
obj -> obj instanceof String ? true : false);
|
|
||||||
|
|
||||||
customPickupConditionsEntities = s.comment("Custom Pickup Conditions for Entities").defineList(
|
|
||||||
"custom_pickup_conditions.customPickupConditionsEntities", Arrays.asList(),
|
|
||||||
obj -> obj instanceof String ? true : false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
package tschipp.carryon.common.event;
|
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.InterModComms;
|
|
||||||
import net.minecraftforge.fml.InterModComms.IMCMessage;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.common.handler.ListHandler;
|
|
||||||
import tschipp.carryon.common.handler.ModelOverridesHandler;
|
|
||||||
|
|
||||||
public class IMCEvents
|
|
||||||
{
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.LOW)
|
|
||||||
public void serverLoad(FMLDedicatedServerSetupEvent event)
|
|
||||||
{
|
|
||||||
Stream<IMCMessage> messages = InterModComms.getMessages(CarryOn.MODID);
|
|
||||||
|
|
||||||
messages.forEach(msg -> {
|
|
||||||
|
|
||||||
String method = msg.method();
|
|
||||||
Object obj = msg.messageSupplier().get();
|
|
||||||
|
|
||||||
if (!(obj instanceof String str))
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (method)
|
|
||||||
{
|
|
||||||
case "blacklistBlock":
|
|
||||||
ListHandler.FORBIDDEN_TILES.add(str);
|
|
||||||
break;
|
|
||||||
case "blacklistEntity":
|
|
||||||
ListHandler.FORBIDDEN_ENTITIES.add(str);
|
|
||||||
break;
|
|
||||||
case "whitelistBlock":
|
|
||||||
ListHandler.ALLOWED_TILES.add(str);
|
|
||||||
break;
|
|
||||||
case "whitelistEntity":
|
|
||||||
ListHandler.ALLOWED_ENTITIES.add(str);
|
|
||||||
break;
|
|
||||||
case "blacklistStacking":
|
|
||||||
ListHandler.FORBIDDEN_STACKING.add(str);
|
|
||||||
break;
|
|
||||||
case "whitelistStacking":
|
|
||||||
ListHandler.ALLOWED_STACKING.add(str);
|
|
||||||
break;
|
|
||||||
case "addModelOverride":
|
|
||||||
ModelOverridesHandler.parseOverride(str, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,270 +0,0 @@
|
||||||
package tschipp.carryon.common.event;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.sounds.SoundEvents;
|
|
||||||
import net.minecraft.sounds.SoundSource;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.animal.Animal;
|
|
||||||
import net.minecraft.world.entity.animal.horse.Horse;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.material.Material;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.Event.Result;
|
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
|
||||||
import tschipp.carryon.common.config.Configs.Settings;
|
|
||||||
import tschipp.carryon.common.handler.ListHandler;
|
|
||||||
import tschipp.carryon.common.handler.PickupHandler;
|
|
||||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonEntity;
|
|
||||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
|
||||||
import tschipp.carryon.common.scripting.ScriptChecker;
|
|
||||||
|
|
||||||
public class ItemEntityEvents
|
|
||||||
{
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
||||||
public void onBlockClick(PlayerInteractEvent.RightClickBlock event)
|
|
||||||
{
|
|
||||||
Player player = event.getEntity();
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack))
|
|
||||||
{
|
|
||||||
player.getPersistentData().remove("carrySlot");
|
|
||||||
event.setUseBlock(Result.DENY);
|
|
||||||
|
|
||||||
if (!player.level.isClientSide)
|
|
||||||
{
|
|
||||||
CarryOnOverride override = ScriptChecker.getOverride(player);
|
|
||||||
if (override != null)
|
|
||||||
{
|
|
||||||
String command = override.getCommandPlace();
|
|
||||||
|
|
||||||
if (command != null)
|
|
||||||
player.getServer().getCommands().performCommand(player.getServer().createCommandSourceStack(), "/execute as " + player.getGameProfile().getName() + " run " + command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
||||||
public void onItemDropped(EntityJoinLevelEvent event)
|
|
||||||
{
|
|
||||||
Entity e = event.getEntity();
|
|
||||||
Level level = event.getLevel();
|
|
||||||
if (e instanceof net.minecraft.world.entity.item.ItemEntity eitem)
|
|
||||||
{
|
|
||||||
ItemStack stack = eitem.getItem();
|
|
||||||
Item item = stack.getItem();
|
|
||||||
if (item == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack))
|
|
||||||
{
|
|
||||||
BlockPos pos = eitem.blockPosition();
|
|
||||||
Entity entity = ItemCarryonEntity.getEntity(stack, level);
|
|
||||||
entity.setPos(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
|
|
||||||
level.addFreshEntity(entity);
|
|
||||||
|
|
||||||
ItemCarryonEntity.clearEntityData(stack);
|
|
||||||
eitem.setItem(ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
||||||
public void onEntityRightClick(PlayerInteractEvent.EntityInteract event)
|
|
||||||
{
|
|
||||||
Player player = event.getEntity();
|
|
||||||
|
|
||||||
if (player instanceof ServerPlayer)
|
|
||||||
{
|
|
||||||
ItemStack main = player.getMainHandItem();
|
|
||||||
ItemStack off = player.getOffhandItem();
|
|
||||||
Level level = event.getLevel();
|
|
||||||
Entity entity = event.getTarget();
|
|
||||||
BlockPos pos = entity.blockPosition();
|
|
||||||
|
|
||||||
if (main.isEmpty() && off.isEmpty() && CarryOnKeybinds.isKeyPressed(player))
|
|
||||||
{
|
|
||||||
ItemStack stack = new ItemStack(RegistrationHandler.itemEntity.get());
|
|
||||||
|
|
||||||
if (entity.invulnerableTime == 0)
|
|
||||||
{
|
|
||||||
if (entity instanceof Animal)
|
|
||||||
((Animal) entity).dropLeash(true, true);
|
|
||||||
|
|
||||||
if (PickupHandler.canPlayerPickUpEntity((ServerPlayer) player, entity) && ItemCarryonEntity.storeEntityData(entity, level, stack))
|
|
||||||
{
|
|
||||||
LazyOptional<IItemHandler> handler = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
|
||||||
|
|
||||||
handler.ifPresent(hand -> {
|
|
||||||
for (int i = 0; i < hand.getSlots(); i++)
|
|
||||||
{
|
|
||||||
hand.extractItem(i, 64, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
CarryOnOverride override = ScriptChecker.inspectEntity(entity);
|
|
||||||
int overrideHash = 0;
|
|
||||||
if (override != null)
|
|
||||||
overrideHash = override.hashCode();
|
|
||||||
|
|
||||||
ItemEvents.sendPacket(player, player.getInventory().selected, overrideHash);
|
|
||||||
|
|
||||||
if (entity instanceof LivingEntity)
|
|
||||||
((LivingEntity) entity).setHealth(0);
|
|
||||||
|
|
||||||
entity.ejectPassengers();
|
|
||||||
entity.setPos(entity.getX(), 0, entity.getZ());
|
|
||||||
entity.discard();
|
|
||||||
player.setItemInHand(InteractionHand.MAIN_HAND, stack);
|
|
||||||
event.setCanceled(true);
|
|
||||||
event.setCancellationResult(InteractionResult.FAIL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(main) && !CarryOnKeybinds.isKeyPressed(player) && Settings.stackableEntities.get())
|
|
||||||
{
|
|
||||||
Entity entityHeld = ItemCarryonEntity.getEntity(main, level);
|
|
||||||
|
|
||||||
if (entity.invulnerableTime == 0 && entityHeld instanceof LivingEntity)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!level.isClientSide && entityHeld.getUUID() != entity.getUUID() && entity.isAlive())
|
|
||||||
{
|
|
||||||
|
|
||||||
double sizeHeldEntity = entityHeld.getBbHeight() * entityHeld.getBbWidth();
|
|
||||||
double distance = pos.distSqr(player.blockPosition());
|
|
||||||
Entity lowestEntity = entity.getRootVehicle();
|
|
||||||
int numPassengers = getAllPassengers(lowestEntity);
|
|
||||||
if (numPassengers < Settings.maxEntityStackLimit.get() - 1)
|
|
||||||
{
|
|
||||||
Entity topEntity = getTopPassenger(lowestEntity);
|
|
||||||
|
|
||||||
if (Settings.useWhitelistStacking.get() ? ListHandler.isStackingAllowed(topEntity) : !ListHandler.isStackingForbidden(topEntity))
|
|
||||||
{
|
|
||||||
double sizeEntity = topEntity.getBbHeight() * topEntity.getBbWidth();
|
|
||||||
if (Settings.entitySizeMattersStacking.get() && sizeHeldEntity <= sizeEntity || !Settings.entitySizeMattersStacking.get())
|
|
||||||
{
|
|
||||||
if (topEntity instanceof Horse horse)
|
|
||||||
{
|
|
||||||
horse.setTamed(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (distance < 6)
|
|
||||||
{
|
|
||||||
double tempX = entity.getX();
|
|
||||||
double tempY = entity.getY();
|
|
||||||
double tempZ = entity.getZ();
|
|
||||||
entityHeld.setPos(tempX, tempY + 2.6, tempZ);
|
|
||||||
level.addFreshEntity(entityHeld);
|
|
||||||
entityHeld.startRiding(topEntity, false);
|
|
||||||
entityHeld.teleportTo(tempX, tempY, tempZ);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entityHeld.setPos(entity.getX(), entity.getY(), entity.getZ());
|
|
||||||
level.addFreshEntity(entityHeld);
|
|
||||||
entityHeld.startRiding(topEntity, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemCarryonEntity.clearEntityData(main);
|
|
||||||
player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
|
|
||||||
ItemEvents.sendPacket(player, 9, 0);
|
|
||||||
event.setCanceled(true);
|
|
||||||
event.setCancellationResult(InteractionResult.FAIL);
|
|
||||||
level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.HORSE_SADDLE, SoundSource.PLAYERS, 0.5F, 1.5F);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.NOTE_BLOCK_BASS, SoundSource.PLAYERS, 0.5F, 1.5F);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.NOTE_BLOCK_BASS, SoundSource.PLAYERS, 0.5F, 1.5F);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getAllPassengers(Entity entity)
|
|
||||||
{
|
|
||||||
int passengers = 0;
|
|
||||||
while (entity.isVehicle())
|
|
||||||
{
|
|
||||||
List<Entity> pass = entity.getPassengers();
|
|
||||||
if (!pass.isEmpty())
|
|
||||||
{
|
|
||||||
entity = pass.get(0);
|
|
||||||
passengers++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return passengers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Entity getTopPassenger(Entity entity)
|
|
||||||
{
|
|
||||||
Entity top = entity;
|
|
||||||
while (entity.isVehicle())
|
|
||||||
{
|
|
||||||
List<Entity> pass = entity.getPassengers();
|
|
||||||
if (!pass.isEmpty())
|
|
||||||
{
|
|
||||||
entity = pass.get(0);
|
|
||||||
top = entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return top;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onLivingUpdate(LivingTickEvent event)
|
|
||||||
{
|
|
||||||
LivingEntity entity = event.getEntity();
|
|
||||||
Level level = entity.level;
|
|
||||||
ItemStack main = entity.getMainHandItem();
|
|
||||||
if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(main))
|
|
||||||
{
|
|
||||||
BlockPos pos = entity.blockPosition();
|
|
||||||
BlockPos below = pos.relative(Direction.DOWN);
|
|
||||||
|
|
||||||
if (level.getBlockState(pos).getMaterial() == Material.WATER || level.getBlockState(below).getMaterial() == Material.WATER)
|
|
||||||
{
|
|
||||||
Entity contained = ItemCarryonEntity.getEntity(main, level);
|
|
||||||
if (contained != null)
|
|
||||||
{
|
|
||||||
float height = contained.getBbWidth();
|
|
||||||
float width = contained.getBbWidth();
|
|
||||||
|
|
||||||
entity.push(0, -0.01 * height * width, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,547 +0,0 @@
|
||||||
package tschipp.carryon.common.event;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.chat.ClickEvent;
|
|
||||||
import net.minecraft.network.chat.ClickEvent.Action;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.Container;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
||||||
import net.minecraft.world.item.context.DirectionalPlaceContext;
|
|
||||||
import net.minecraft.world.level.GameRules;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
|
||||||
import net.minecraftforge.event.TagsUpdatedEvent;
|
|
||||||
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
|
||||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent.StartTracking;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
||||||
import net.minecraftforge.event.level.BlockEvent.BreakEvent;
|
|
||||||
import net.minecraftforge.event.level.LevelEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.Event.Result;
|
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
|
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
|
||||||
import net.minecraftforge.network.PacketDistributor.TargetPoint;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
|
||||||
import tschipp.carryon.common.command.CommandCarryOn;
|
|
||||||
import tschipp.carryon.common.config.Configs;
|
|
||||||
import tschipp.carryon.common.config.Configs.Settings;
|
|
||||||
import tschipp.carryon.common.handler.CustomPickupOverrideHandler;
|
|
||||||
import tschipp.carryon.common.handler.ListHandler;
|
|
||||||
import tschipp.carryon.common.handler.PickupHandler;
|
|
||||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonBlock;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonEntity;
|
|
||||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
|
||||||
import tschipp.carryon.common.scripting.ScriptChecker;
|
|
||||||
import tschipp.carryon.common.scripting.ScriptReader;
|
|
||||||
import tschipp.carryon.network.client.CarrySlotPacket;
|
|
||||||
import tschipp.carryon.network.client.ScriptReloadPacket;
|
|
||||||
|
|
||||||
@EventBusSubscriber(modid = CarryOn.MODID)
|
|
||||||
public class ItemEvents
|
|
||||||
{
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
||||||
public void onBlockClick(PlayerInteractEvent.RightClickBlock event)
|
|
||||||
{
|
|
||||||
if (event.isCanceled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Player player = event.getEntity();
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile.get() && ItemCarryonBlock.hasTileData(stack))
|
|
||||||
{
|
|
||||||
player.getPersistentData().remove("carrySlot");
|
|
||||||
event.setUseBlock(Result.DENY);
|
|
||||||
|
|
||||||
if (!player.level.isClientSide)
|
|
||||||
{
|
|
||||||
CarryOnOverride override = ScriptChecker.getOverride(player);
|
|
||||||
if (override != null)
|
|
||||||
{
|
|
||||||
String command = override.getCommandPlace();
|
|
||||||
|
|
||||||
if (command != null && !command.isEmpty())
|
|
||||||
player.getServer().getCommands().performCommand(player.getServer().createCommandSourceStack(), "/execute as " + player.getGameProfile().getName() + " run " + command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
||||||
public void onItemDropped(EntityJoinLevelEvent event)
|
|
||||||
{
|
|
||||||
Entity e = event.getEntity();
|
|
||||||
Level level = event.getLevel();
|
|
||||||
if (e instanceof net.minecraft.world.entity.item.ItemEntity eitem)
|
|
||||||
{
|
|
||||||
ItemStack stack = eitem.getItem();
|
|
||||||
Item item = stack.getItem();
|
|
||||||
if (item == RegistrationHandler.itemTile.get() && ItemCarryonBlock.hasTileData(stack))
|
|
||||||
{
|
|
||||||
BlockPos pos = eitem.blockPosition();
|
|
||||||
BlockPos finalPos = pos;
|
|
||||||
BlockPlaceContext context = new DirectionalPlaceContext(level, pos, Direction.DOWN, stack, Direction.UP);
|
|
||||||
|
|
||||||
if (!level.getBlockState(pos).canBeReplaced(context) || !context.canPlace())
|
|
||||||
{
|
|
||||||
for (Direction facing : Direction.values())
|
|
||||||
{
|
|
||||||
BlockPos offsetPos = pos.relative(facing);
|
|
||||||
BlockPlaceContext newContext = new DirectionalPlaceContext(level, offsetPos, Direction.DOWN, stack, Direction.UP);
|
|
||||||
if (level.getBlockState(offsetPos).canBeReplaced(newContext) && newContext.canPlace())
|
|
||||||
{
|
|
||||||
finalPos = offsetPos;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
level.setBlockAndUpdate(finalPos, ItemCarryonBlock.getBlockState(stack));
|
|
||||||
BlockEntity tile = level.getBlockEntity(finalPos);
|
|
||||||
if (tile != null)
|
|
||||||
{
|
|
||||||
var nbt = ItemCarryonBlock.getTileData(stack);
|
|
||||||
ItemCarryonBlock.updateTileLocation(nbt, finalPos);
|
|
||||||
tile.load(nbt);
|
|
||||||
}
|
|
||||||
ItemCarryonBlock.clearTileData(stack);
|
|
||||||
eitem.setItem(ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockPos pos = new BlockPos(Math.floor(eitem.getPosX()),
|
|
||||||
// Math.floor(eitem.getPosY()), Math.floor(eitem.getPosZ()));
|
|
||||||
// if (positions.containsKey(pos))
|
|
||||||
// {
|
|
||||||
// event.setCanceled(true);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onPlayerLogin(PlayerLoggedInEvent event)
|
|
||||||
{
|
|
||||||
if (event.getEntity() instanceof Player)
|
|
||||||
{
|
|
||||||
Player player = event.getEntity();
|
|
||||||
Level level = player.getCommandSenderWorld();
|
|
||||||
|
|
||||||
ItemStack carried = player.getMainHandItem();
|
|
||||||
if (!carried.isEmpty() && carried.getItem() == RegistrationHandler.itemTile.get() || carried.getItem() == RegistrationHandler.itemEntity.get())
|
|
||||||
{
|
|
||||||
if (carried.getItem() == RegistrationHandler.itemTile.get())
|
|
||||||
{
|
|
||||||
CarryOnOverride override = ScriptChecker.inspectBlock(ItemCarryonBlock.getBlockState(carried), level, player.blockPosition(), ItemCarryonBlock.getTileData(carried));
|
|
||||||
if (override != null)
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new CarrySlotPacket(player.getInventory().selected, player.getId(), override.hashCode()));
|
|
||||||
else
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new CarrySlotPacket(player.getInventory().selected, player.getId()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CarryOnOverride override = ScriptChecker.inspectEntity(ItemCarryonEntity.getEntity(carried, level));
|
|
||||||
if (override != null)
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new CarrySlotPacket(player.getInventory().selected, player.getId(), override.hashCode()));
|
|
||||||
else
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new CarrySlotPacket(player.getInventory().selected, player.getId()));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (event.getEntity() instanceof ServerPlayer)
|
|
||||||
{
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) event.getEntity()), new ScriptReloadPacket(ScriptReader.OVERRIDES.values()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void serverLoad(RegisterCommandsEvent event)
|
|
||||||
{
|
|
||||||
CommandCarryOn.register(event.getDispatcher());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void serverLoad(FMLDedicatedServerSetupEvent event)
|
|
||||||
{
|
|
||||||
CustomPickupOverrideHandler.initPickupOverrides();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void reloadTags(TagsUpdatedEvent event)
|
|
||||||
{
|
|
||||||
ListHandler.initConfigLists();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void unloadWorld(LevelEvent.Unload event)
|
|
||||||
{
|
|
||||||
Configs.SERVER_LOADED = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onEntityStartTracking(StartTracking event)
|
|
||||||
{
|
|
||||||
Entity e = event.getTarget();
|
|
||||||
Player tracker = event.getEntity();
|
|
||||||
|
|
||||||
if (e instanceof Player player && tracker instanceof ServerPlayer)
|
|
||||||
{
|
|
||||||
Level level = player.getCommandSenderWorld();
|
|
||||||
|
|
||||||
ItemStack carried = player.getMainHandItem();
|
|
||||||
if (!carried.isEmpty() && carried.getItem() == RegistrationHandler.itemTile.get() || carried.getItem() == RegistrationHandler.itemEntity.get())
|
|
||||||
{
|
|
||||||
if (carried.getItem() == RegistrationHandler.itemTile.get())
|
|
||||||
{
|
|
||||||
CarryOnOverride override = ScriptChecker.inspectBlock(ItemCarryonBlock.getBlockState(carried), level, player.blockPosition(), ItemCarryonBlock.getTileData(carried));
|
|
||||||
if (override != null)
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) tracker), new CarrySlotPacket(player.getInventory().selected, player.getId(), override.hashCode()));
|
|
||||||
else
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) tracker), new CarrySlotPacket(player.getInventory().selected, player.getId()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CarryOnOverride override = ScriptChecker.inspectEntity(ItemCarryonEntity.getEntity(carried, level));
|
|
||||||
if (override != null)
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) tracker), new CarrySlotPacket(player.getInventory().selected, player.getId(), override.hashCode()));
|
|
||||||
else
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) tracker), new CarrySlotPacket(player.getInventory().selected, player.getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void harvestSpeed(BreakSpeed event)
|
|
||||||
{
|
|
||||||
Player player = event.getEntity();
|
|
||||||
if (player != null && !Settings.hitWhileCarrying.get())
|
|
||||||
{
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile.get() || stack.getItem() == RegistrationHandler.itemEntity.get()))
|
|
||||||
event.setNewSpeed(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void attackEntity(AttackEntityEvent event)
|
|
||||||
{
|
|
||||||
Player player = event.getEntity();
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (!stack.isEmpty() && !Settings.hitWhileCarrying.get() && (stack.getItem() == RegistrationHandler.itemTile.get() || stack.getItem() == RegistrationHandler.itemEntity.get()))
|
|
||||||
{
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void harvestSpeed(BreakEvent event)
|
|
||||||
{
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player != null && !Settings.hitWhileCarrying.get())
|
|
||||||
{
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile.get() || stack.getItem() == RegistrationHandler.itemEntity.get()))
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void playerAttack(LivingAttackEvent event)
|
|
||||||
{
|
|
||||||
LivingEntity eliving = event.getEntity();
|
|
||||||
if (eliving instanceof Player player && Settings.dropCarriedWhenHit.get())
|
|
||||||
{
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile.get() || stack.getItem() == RegistrationHandler.itemEntity.get()) && !player.level.isClientSide)
|
|
||||||
{
|
|
||||||
player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
|
|
||||||
ItemEntity item = new ItemEntity(player.level, player.getX(), player.getY(), player.getZ(), stack);
|
|
||||||
sendPacket(player, 9, 0);
|
|
||||||
player.level.addFreshEntity(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
||||||
public static void onBlockRightClick(PlayerInteractEvent.RightClickBlock event)
|
|
||||||
{
|
|
||||||
Player player = event.getEntity();
|
|
||||||
|
|
||||||
if (event.isCanceled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!player.level.isClientSide)
|
|
||||||
{
|
|
||||||
|
|
||||||
ItemStack main = player.getMainHandItem();
|
|
||||||
ItemStack off = player.getOffhandItem();
|
|
||||||
Level level = event.getLevel();
|
|
||||||
BlockPos pos = event.getPos();
|
|
||||||
BlockState state = level.getBlockState(pos);
|
|
||||||
|
|
||||||
if (main.isEmpty() && off.isEmpty() && CarryOnKeybinds.isKeyPressed(player))
|
|
||||||
{
|
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(RegistrationHandler.itemTile.get());
|
|
||||||
|
|
||||||
BlockEntity te = level.getBlockEntity(pos);
|
|
||||||
if (PickupHandler.canPlayerPickUpBlock((ServerPlayer) player, te, level, pos))
|
|
||||||
{
|
|
||||||
player.closeContainer();
|
|
||||||
level.levelEvent(1010, pos, 0);
|
|
||||||
|
|
||||||
if (ItemCarryonBlock.storeTileData(te, level, pos, state, stack))
|
|
||||||
{
|
|
||||||
|
|
||||||
BlockState statee = level.getBlockState(pos);
|
|
||||||
CompoundTag tag = new CompoundTag();
|
|
||||||
tag = level.getBlockEntity(pos) != null ? level.getBlockEntity(pos).saveWithId() : tag;
|
|
||||||
CarryOnOverride override = ScriptChecker.inspectBlock(state, level, pos, tag);
|
|
||||||
int overrideHash = 0;
|
|
||||||
if (override != null)
|
|
||||||
overrideHash = override.hashCode();
|
|
||||||
|
|
||||||
boolean success = false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sendPacket(player, player.getInventory().selected, overrideHash);
|
|
||||||
|
|
||||||
level.removeBlockEntity(pos);
|
|
||||||
level.removeBlock(pos, false);
|
|
||||||
player.setItemInHand(InteractionHand.MAIN_HAND, stack);
|
|
||||||
event.setUseBlock(Result.DENY);
|
|
||||||
event.setUseItem(Result.DENY);
|
|
||||||
event.setCanceled(true);
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sendPacket(player, player.getInventory().selected, overrideHash);
|
|
||||||
emptyTileEntity(te);
|
|
||||||
level.removeBlock(pos, false);
|
|
||||||
player.setItemInHand(InteractionHand.MAIN_HAND, stack);
|
|
||||||
event.setUseBlock(Result.DENY);
|
|
||||||
event.setUseItem(Result.DENY);
|
|
||||||
event.setCanceled(true);
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
sendPacket(player, 9, 0);
|
|
||||||
level.setBlockAndUpdate(pos, statee);
|
|
||||||
if (!tag.isEmpty())
|
|
||||||
{
|
|
||||||
BlockEntity.loadStatic(pos, statee, tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.displayClientMessage(Component.literal(ChatFormatting.RED + "Error detected. Cannot pick up block."), false);
|
|
||||||
Component s = Component.literal(ChatFormatting.GOLD + "here");
|
|
||||||
s.getStyle().withClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/Tschipp/CarryOn/issues"));
|
|
||||||
player.displayClientMessage(Component.literal(ChatFormatting.RED + "Please report this error ").append(s), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success && override != null)
|
|
||||||
{
|
|
||||||
String command = override.getCommandInit();
|
|
||||||
|
|
||||||
if (command != null)
|
|
||||||
player.getServer().getCommands().performCommand(player.getServer().createCommandSourceStack(), "/execute as " + player.getGameProfile().getName() + " run " + command);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void emptyTileEntity(BlockEntity te)
|
|
||||||
{
|
|
||||||
if (te != null)
|
|
||||||
{
|
|
||||||
for (Direction facing : Direction.values())
|
|
||||||
{
|
|
||||||
LazyOptional<IItemHandler> itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
|
|
||||||
|
|
||||||
itemHandler.ifPresent(handler -> {
|
|
||||||
|
|
||||||
for (int i = 0; i < handler.getSlots(); i++)
|
|
||||||
{
|
|
||||||
handler.extractItem(i, 64, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
LazyOptional<IItemHandler> itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
|
||||||
|
|
||||||
itemHandler.ifPresent(handler -> {
|
|
||||||
|
|
||||||
for (int i = 0; i < handler.getSlots(); i++)
|
|
||||||
{
|
|
||||||
handler.extractItem(i, 64, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
if (te instanceof Container inv)
|
|
||||||
{
|
|
||||||
inv.clearContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (te instanceof IItemHandler itemHandler1)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < itemHandler1.getSlots(); i++)
|
|
||||||
{
|
|
||||||
itemHandler1.extractItem(i, 64, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
te.setChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onRespawn(PlayerEvent.Clone event)
|
|
||||||
{
|
|
||||||
Player original = event.getOriginal();
|
|
||||||
Player player = event.getEntity();
|
|
||||||
boolean wasDead = event.isWasDeath();
|
|
||||||
GameRules rules = player.level.getGameRules();
|
|
||||||
boolean keepInv = rules.getBoolean(GameRules.RULE_KEEPINVENTORY);
|
|
||||||
boolean wasCarrying = player.getInventory().contains(new ItemStack(RegistrationHandler.itemTile.get())) || player.getInventory().contains(new ItemStack(RegistrationHandler.itemEntity.get()));
|
|
||||||
|
|
||||||
if ((wasDead ? keepInv : true) && wasCarrying)
|
|
||||||
{
|
|
||||||
int carrySlot = original.getInventory().selected;
|
|
||||||
|
|
||||||
ItemStack stack = player.getInventory().removeItemNoUpdate(carrySlot);
|
|
||||||
Level level = player.level;
|
|
||||||
|
|
||||||
ItemEntity item = new ItemEntity(level, 0, 0, 0, stack);
|
|
||||||
BlockPos pos = null;
|
|
||||||
Optional<BlockPos> bedpos = original.getSleepingPos();
|
|
||||||
if (bedpos.isPresent())
|
|
||||||
pos = bedpos.get();
|
|
||||||
if (pos == null)
|
|
||||||
pos = player.blockPosition();
|
|
||||||
item.setPos(pos.getX(), pos.getY(), pos.getZ());
|
|
||||||
level.addFreshEntity(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void dropNonHotbarItems(LivingTickEvent event)
|
|
||||||
{
|
|
||||||
LivingEntity entity = event.getEntity();
|
|
||||||
if (entity instanceof Player player && !entity.level.isClientSide)
|
|
||||||
{
|
|
||||||
boolean hasCarried = player.getInventory().contains(new ItemStack(RegistrationHandler.itemTile.get())) || player.getInventory().contains(new ItemStack(RegistrationHandler.itemEntity.get()));
|
|
||||||
ItemStack inHand = player.getMainHandItem();
|
|
||||||
|
|
||||||
if (hasCarried && inHand.getItem() != RegistrationHandler.itemTile.get() && inHand.getItem() != RegistrationHandler.itemEntity.get() && player.getDimensionChangingDelay() == 0)
|
|
||||||
{
|
|
||||||
int slotBlock = this.getSlot(player, RegistrationHandler.itemTile.get());
|
|
||||||
int slotEntity = this.getSlot(player, RegistrationHandler.itemEntity.get());
|
|
||||||
|
|
||||||
ItemEntity item = null;
|
|
||||||
if (slotBlock != -1)
|
|
||||||
{
|
|
||||||
ItemStack dropped = player.getInventory().removeItemNoUpdate(slotBlock);
|
|
||||||
item = new ItemEntity(player.level, player.getX(), player.getY(), player.getZ(), dropped);
|
|
||||||
}
|
|
||||||
if (slotEntity != -1)
|
|
||||||
{
|
|
||||||
ItemStack dropped = player.getInventory().removeItemNoUpdate(slotEntity);
|
|
||||||
item = new ItemEntity(player.level, player.getX(), player.getY(), player.getZ(), dropped);
|
|
||||||
}
|
|
||||||
if (item != null)
|
|
||||||
{
|
|
||||||
player.level.addFreshEntity(item);
|
|
||||||
sendPacket(player, 9, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CarryOnOverride override = ScriptChecker.getOverride(player);
|
|
||||||
|
|
||||||
if (override != null)
|
|
||||||
{
|
|
||||||
String command = override.getCommandLoop();
|
|
||||||
|
|
||||||
if (command != null)
|
|
||||||
player.getServer().getCommands().performCommand(player.getServer().createCommandSourceStack(), "/execute as " + player.getGameProfile().getName() + " run " + command);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSlot(Player player, Item item)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < player.getInventory().getContainerSize(); i++)
|
|
||||||
{
|
|
||||||
ItemStack stack = player.getInventory().getItem(i);
|
|
||||||
if (stack.getItem() == item)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendPacket(Player player, int currentItem, int hash)
|
|
||||||
{
|
|
||||||
if (player instanceof ServerPlayer)
|
|
||||||
{
|
|
||||||
CarryOn.network.send(PacketDistributor.NEAR.with(() -> new TargetPoint(player.getX(), player.getY(), player.getZ(), 128, player.level.dimension())), new CarrySlotPacket(currentItem, player.getId(), hash));
|
|
||||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new CarrySlotPacket(currentItem, player.getId(), hash));
|
|
||||||
|
|
||||||
if (currentItem >= 9)
|
|
||||||
{
|
|
||||||
player.getPersistentData().remove("carrySlot");
|
|
||||||
player.getPersistentData().remove("overrideKey");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player.getPersistentData().putInt("carrySlot", currentItem);
|
|
||||||
if (hash != 0)
|
|
||||||
ScriptChecker.setCarryOnOverride(player, hash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
package tschipp.carryon.common.handler;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraftforge.fml.ModList;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import tschipp.carryon.common.config.Configs.CustomPickupConditions;
|
|
||||||
import tschipp.carryon.common.helper.InvalidConfigException;
|
|
||||||
import tschipp.carryon.common.helper.StringParser;
|
|
||||||
|
|
||||||
public class CustomPickupOverrideHandler
|
|
||||||
{
|
|
||||||
|
|
||||||
public static HashMap<String, String> PICKUP_CONDITIONS = new HashMap<>();
|
|
||||||
public static HashMap<String, String> PICKUP_CONDITIONS_ENTITIES = new HashMap<>();
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static void initPickupOverrides()
|
|
||||||
{
|
|
||||||
if (ModList.get().isLoaded("gamestages"))
|
|
||||||
{
|
|
||||||
|
|
||||||
List<String> conditions = (List<String>) CustomPickupConditions.customPickupConditionsBlocks.get();
|
|
||||||
|
|
||||||
for (int i = 0; i < conditions.size(); i++)
|
|
||||||
{
|
|
||||||
String line = conditions.get(i);
|
|
||||||
|
|
||||||
if (!line.contains("(") || !line.contains(")"))
|
|
||||||
new InvalidConfigException("Invalid Condition at line " + i + ": " + line).printException();
|
|
||||||
|
|
||||||
String condition = line.substring(line.indexOf("("));
|
|
||||||
String blockname = line.replace(condition, "");
|
|
||||||
condition = condition.replace("(", "");
|
|
||||||
condition = condition.replace(")", "");
|
|
||||||
|
|
||||||
if (blockname.contains("*"))
|
|
||||||
{
|
|
||||||
String modid = blockname.replace("*", "");
|
|
||||||
for (int k = 0; k < ForgeRegistries.BLOCKS.getKeys().size(); k++)
|
|
||||||
{
|
|
||||||
if (ForgeRegistries.BLOCKS.getKeys().toArray()[k].toString().contains(modid))
|
|
||||||
{
|
|
||||||
PICKUP_CONDITIONS.put(ForgeRegistries.BLOCKS.getKeys().toArray()[k].toString(), condition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
PICKUP_CONDITIONS.put(blockname, condition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> entityConditions = (List<String>) CustomPickupConditions.customPickupConditionsEntities.get();
|
|
||||||
|
|
||||||
for (int i = 0; i < entityConditions.size(); i++)
|
|
||||||
{
|
|
||||||
String line = entityConditions.get(i);
|
|
||||||
|
|
||||||
if (!line.contains("(") || !line.contains(")"))
|
|
||||||
new InvalidConfigException("Invalid Condition at line " + i + ": " + line).printException();
|
|
||||||
|
|
||||||
String condition = line.substring(line.indexOf("("));
|
|
||||||
String entityname = line.replace(condition, "");
|
|
||||||
condition = condition.replace("(", "");
|
|
||||||
condition = condition.replace(")", "");
|
|
||||||
|
|
||||||
PICKUP_CONDITIONS_ENTITIES.put(entityname, condition);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasSpecialPickupConditions(BlockState state)
|
|
||||||
{
|
|
||||||
if (!ModList.get().isLoaded("gamestages"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for (String cond : PICKUP_CONDITIONS.keySet())
|
|
||||||
{
|
|
||||||
if(state == StringParser.getBlockState(cond));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPickupCondition(BlockState state)
|
|
||||||
{
|
|
||||||
for (String cond : PICKUP_CONDITIONS.keySet())
|
|
||||||
{
|
|
||||||
if(state == StringParser.getBlockState(cond));
|
|
||||||
return PICKUP_CONDITIONS.get(cond);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasSpecialPickupConditions(Entity entity)
|
|
||||||
{
|
|
||||||
if (!ModList.get().isLoaded("gamestages"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
String name = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()).toString();
|
|
||||||
return PICKUP_CONDITIONS_ENTITIES.containsKey(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPickupCondition(Entity entity)
|
|
||||||
{
|
|
||||||
String name = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()).toString();
|
|
||||||
return PICKUP_CONDITIONS_ENTITIES.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,367 +0,0 @@
|
||||||
package tschipp.carryon.common.handler;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.tags.TagKey;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.EntityType;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import tschipp.carryon.common.config.Configs;
|
|
||||||
import tschipp.carryon.common.config.Configs.Blacklist;
|
|
||||||
import tschipp.carryon.common.config.Configs.WhiteList;
|
|
||||||
|
|
||||||
public class ListHandler
|
|
||||||
{
|
|
||||||
public static List<String> FORBIDDEN_TILES = new ArrayList<>();
|
|
||||||
public static List<String> FORBIDDEN_ENTITIES = new ArrayList<>();
|
|
||||||
public static List<String> ALLOWED_ENTITIES = new ArrayList<>();
|
|
||||||
public static List<String> ALLOWED_TILES = new ArrayList<>();
|
|
||||||
public static List<String> FORBIDDEN_STACKING = new ArrayList<>();
|
|
||||||
public static List<String> ALLOWED_STACKING = new ArrayList<>();
|
|
||||||
|
|
||||||
public static List<TagKey<Block>> FORBIDDEN_TILES_TAGS = new ArrayList<>();
|
|
||||||
public static List<TagKey<EntityType<?>>> FORBIDDEN_ENTITIES_TAGS = new ArrayList<>();
|
|
||||||
public static List<TagKey<EntityType<?>>> ALLOWED_ENTITIES_TAGS = new ArrayList<>();
|
|
||||||
public static List<TagKey<Block>> ALLOWED_TILES_TAGS = new ArrayList<>();
|
|
||||||
public static List<TagKey<EntityType<?>>> FORBIDDEN_STACKING_TAGS = new ArrayList<>();
|
|
||||||
public static List<TagKey<EntityType<?>>> ALLOWED_STACKING_TAGS = new ArrayList<>();
|
|
||||||
|
|
||||||
public static boolean isForbidden(Block block)
|
|
||||||
{
|
|
||||||
String name = ForgeRegistries.BLOCKS.getKey(block).toString();
|
|
||||||
if (FORBIDDEN_TILES.contains(name))
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boolean contains = false;
|
|
||||||
for (String s : FORBIDDEN_TILES)
|
|
||||||
{
|
|
||||||
if (s.contains("*"))
|
|
||||||
{
|
|
||||||
String[] filter = s.replace("*", ",").split(",");
|
|
||||||
if (containsAll(name, filter))
|
|
||||||
contains = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TagKey<Block> tag : FORBIDDEN_TILES_TAGS)
|
|
||||||
{
|
|
||||||
if (block.defaultBlockState().is(tag))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return contains;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isForbidden(Entity entity)
|
|
||||||
{
|
|
||||||
String name = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()).toString();
|
|
||||||
boolean contains = FORBIDDEN_ENTITIES.contains(name);
|
|
||||||
|
|
||||||
for (TagKey<EntityType<?>> tag : FORBIDDEN_ENTITIES_TAGS)
|
|
||||||
{
|
|
||||||
if (entity.getType().is(tag))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return contains;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAllowed(Entity entity)
|
|
||||||
{
|
|
||||||
String name = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()).toString();
|
|
||||||
boolean contains = ALLOWED_ENTITIES.contains(name);
|
|
||||||
|
|
||||||
for (TagKey<EntityType<?>> tag : ALLOWED_ENTITIES_TAGS)
|
|
||||||
{
|
|
||||||
if (entity.getType().is(tag))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return contains;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isStackingForbidden(Entity entity)
|
|
||||||
{
|
|
||||||
String name = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()).toString();
|
|
||||||
boolean contains = FORBIDDEN_STACKING.contains(name);
|
|
||||||
|
|
||||||
for (TagKey<EntityType<?>> tag : FORBIDDEN_STACKING_TAGS)
|
|
||||||
{
|
|
||||||
if (entity.getType().is(tag))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return contains;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isStackingAllowed(Entity entity)
|
|
||||||
{
|
|
||||||
String name = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()).toString();
|
|
||||||
boolean contains = ALLOWED_STACKING.contains(name);
|
|
||||||
|
|
||||||
for (TagKey<EntityType<?>> tag : ALLOWED_STACKING_TAGS)
|
|
||||||
{
|
|
||||||
if (entity.getType().is(tag))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return contains;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAllowed(Block block)
|
|
||||||
{
|
|
||||||
String name = ForgeRegistries.BLOCKS.getKey(block).toString();
|
|
||||||
if (ALLOWED_TILES.contains(name))
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boolean contains = false;
|
|
||||||
for (String s : ALLOWED_TILES)
|
|
||||||
{
|
|
||||||
if (s.contains("*"))
|
|
||||||
{
|
|
||||||
String[] filter = s.replace("*", ",").split(",");
|
|
||||||
if (containsAll(name, filter))
|
|
||||||
contains = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TagKey<Block> tag : ALLOWED_TILES_TAGS)
|
|
||||||
{
|
|
||||||
if (block.defaultBlockState().is(tag))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return contains;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static void initConfigLists()
|
|
||||||
{
|
|
||||||
if(!Configs.SERVER_LOADED)
|
|
||||||
return;
|
|
||||||
|
|
||||||
FORBIDDEN_ENTITIES.clear();
|
|
||||||
FORBIDDEN_ENTITIES_TAGS.clear();
|
|
||||||
FORBIDDEN_STACKING.clear();
|
|
||||||
FORBIDDEN_STACKING_TAGS.clear();
|
|
||||||
FORBIDDEN_TILES.clear();
|
|
||||||
FORBIDDEN_TILES_TAGS.clear();
|
|
||||||
ALLOWED_ENTITIES.clear();
|
|
||||||
ALLOWED_ENTITIES_TAGS.clear();
|
|
||||||
ALLOWED_STACKING.clear();
|
|
||||||
ALLOWED_STACKING_TAGS.clear();
|
|
||||||
ALLOWED_TILES.clear();
|
|
||||||
ALLOWED_TILES_TAGS.clear();
|
|
||||||
|
|
||||||
List<String> forbidden = new ArrayList<>(Blacklist.forbiddenTiles.get());
|
|
||||||
forbidden.add("#carryon:block_blacklist");
|
|
||||||
FORBIDDEN_TILES = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < forbidden.size(); i++)
|
|
||||||
{
|
|
||||||
if (!forbidden.get(i).startsWith("#"))
|
|
||||||
FORBIDDEN_TILES.add(forbidden.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> forbiddenEntity = new ArrayList<>(Blacklist.forbiddenEntities.get());
|
|
||||||
forbiddenEntity.add("#carryon:entity_blacklist");
|
|
||||||
FORBIDDEN_ENTITIES = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < forbiddenEntity.size(); i++)
|
|
||||||
{
|
|
||||||
if (!forbiddenEntity.get(i).startsWith("#"))
|
|
||||||
{
|
|
||||||
if (forbiddenEntity.get(i).contains("*"))
|
|
||||||
{
|
|
||||||
String[] filter = forbiddenEntity.get(i).replace("*", ",").split(",");
|
|
||||||
|
|
||||||
ResourceLocation[] keys = ForgeRegistries.ENTITY_TYPES.getKeys().toArray(new ResourceLocation[0]);
|
|
||||||
for (ResourceLocation key : keys)
|
|
||||||
{
|
|
||||||
if (containsAll(key.toString(), filter))
|
|
||||||
{
|
|
||||||
FORBIDDEN_ENTITIES.add(key.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FORBIDDEN_ENTITIES.add(forbiddenEntity.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> allowedEntities = new ArrayList<>(WhiteList.allowedEntities.get());
|
|
||||||
allowedEntities.add("#carryon:entity_whitelist");
|
|
||||||
ALLOWED_ENTITIES = new ArrayList<>();
|
|
||||||
for (int i = 0; i < allowedEntities.size(); i++)
|
|
||||||
{
|
|
||||||
if (!allowedEntities.get(i).startsWith("#"))
|
|
||||||
{
|
|
||||||
if (allowedEntities.get(i).contains("*"))
|
|
||||||
{
|
|
||||||
String[] filter = allowedEntities.get(i).replace("*", ",").split(",");
|
|
||||||
|
|
||||||
ResourceLocation[] keys = ForgeRegistries.ENTITY_TYPES.getKeys().toArray(new ResourceLocation[0]);
|
|
||||||
for (ResourceLocation key : keys)
|
|
||||||
{
|
|
||||||
if (containsAll(key.toString(), filter))
|
|
||||||
{
|
|
||||||
ALLOWED_ENTITIES.add(key.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ALLOWED_ENTITIES.add(allowedEntities.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> allowedBlocks = new ArrayList<>(WhiteList.allowedBlocks.get());
|
|
||||||
allowedBlocks.add("#carryon:block_whitelist");
|
|
||||||
ALLOWED_TILES = new ArrayList<>();
|
|
||||||
for (int i = 0; i < allowedBlocks.size(); i++)
|
|
||||||
{
|
|
||||||
if (!allowedBlocks.get(i).startsWith("#"))
|
|
||||||
ALLOWED_TILES.add(allowedBlocks.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> forbiddenStacking = new ArrayList<>(Blacklist.forbiddenStacking.get());
|
|
||||||
forbiddenStacking.add("#carryon:stacking_blacklist");
|
|
||||||
FORBIDDEN_STACKING = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < forbiddenStacking.size(); i++)
|
|
||||||
{
|
|
||||||
if (!forbiddenStacking.get(i).startsWith("#"))
|
|
||||||
{
|
|
||||||
if (forbiddenStacking.get(i).contains("*"))
|
|
||||||
{
|
|
||||||
String[] filter = forbiddenStacking.get(i).replace("*", ",").split(",");
|
|
||||||
|
|
||||||
ResourceLocation[] keys = ForgeRegistries.ENTITY_TYPES.getKeys().toArray(new ResourceLocation[0]);
|
|
||||||
for (ResourceLocation key : keys)
|
|
||||||
{
|
|
||||||
if (containsAll(key.toString(), filter))
|
|
||||||
{
|
|
||||||
FORBIDDEN_STACKING.add(key.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FORBIDDEN_STACKING.add(forbiddenStacking.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> allowedStacking = new ArrayList<>(WhiteList.allowedStacking.get());
|
|
||||||
allowedStacking.add("#carryon:stacking_whitelist");
|
|
||||||
ALLOWED_STACKING = new ArrayList<>();
|
|
||||||
for (int i = 0; i < allowedStacking.size(); i++)
|
|
||||||
{
|
|
||||||
if (!allowedStacking.get(i).startsWith("#"))
|
|
||||||
{
|
|
||||||
if (allowedStacking.get(i).contains("*"))
|
|
||||||
{
|
|
||||||
String[] filter = allowedStacking.get(i).replace("*", ",").split(",");
|
|
||||||
|
|
||||||
ResourceLocation[] keys = ForgeRegistries.ENTITY_TYPES.getKeys().toArray(new ResourceLocation[0]);
|
|
||||||
for (ResourceLocation key : keys)
|
|
||||||
{
|
|
||||||
if (containsAll(key.toString(), filter))
|
|
||||||
{
|
|
||||||
ALLOWED_STACKING.add(key.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ALLOWED_STACKING.add(allowedStacking.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Map<ResourceLocation, TagKey<Block>> blocktags = Registry.BLOCK.getTagNames().collect(Collectors.toMap(t -> t.location(), t -> t));
|
|
||||||
Map<ResourceLocation, TagKey<EntityType<?>>> entitytags = Registry.ENTITY_TYPE.getTagNames().collect(Collectors.toMap(t -> t.location(), t -> t));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// System.out.println(blocktags.getAvailableTags());
|
|
||||||
|
|
||||||
for (String s : forbidden)
|
|
||||||
{
|
|
||||||
if (s.startsWith("#"))
|
|
||||||
{
|
|
||||||
String sub = s.substring(1);
|
|
||||||
TagKey<Block> tag = blocktags.get(new ResourceLocation(sub));
|
|
||||||
if (tag != null)
|
|
||||||
FORBIDDEN_TILES_TAGS.add(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String s : allowedBlocks)
|
|
||||||
{
|
|
||||||
if (s.startsWith("#"))
|
|
||||||
{
|
|
||||||
TagKey<Block> tag = blocktags.get(new ResourceLocation(s.substring(1)));
|
|
||||||
if (tag != null)
|
|
||||||
ALLOWED_TILES_TAGS.add(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String s : forbiddenEntity)
|
|
||||||
{
|
|
||||||
if (s.startsWith("#"))
|
|
||||||
{
|
|
||||||
TagKey<EntityType<?>> tag = entitytags.get(new ResourceLocation(s.substring(1)));
|
|
||||||
if (tag != null)
|
|
||||||
FORBIDDEN_ENTITIES_TAGS.add(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String s : allowedEntities)
|
|
||||||
{
|
|
||||||
if (s.startsWith("#"))
|
|
||||||
{
|
|
||||||
TagKey<EntityType<?>> tag = entitytags.get(new ResourceLocation(s.substring(1)));
|
|
||||||
if (tag != null)
|
|
||||||
ALLOWED_ENTITIES_TAGS.add(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String s : forbiddenStacking)
|
|
||||||
{
|
|
||||||
if (s.startsWith("#"))
|
|
||||||
{
|
|
||||||
TagKey<EntityType<?>> tag = entitytags.get(new ResourceLocation(s.substring(1)));
|
|
||||||
if (tag != null)
|
|
||||||
FORBIDDEN_STACKING_TAGS.add(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String s : allowedStacking)
|
|
||||||
{
|
|
||||||
if (s.startsWith("#"))
|
|
||||||
{
|
|
||||||
TagKey<EntityType<?>> tag = entitytags.get(new ResourceLocation(s.substring(1)));
|
|
||||||
if (tag != null)
|
|
||||||
ALLOWED_STACKING_TAGS.add(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean containsAll(String str, String... strings)
|
|
||||||
{
|
|
||||||
boolean containsAll = true;
|
|
||||||
|
|
||||||
for (String s : strings)
|
|
||||||
{
|
|
||||||
if (!str.contains(s))
|
|
||||||
containsAll = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return containsAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,270 +0,0 @@
|
||||||
package tschipp.carryon.common.handler;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.NbtUtils;
|
|
||||||
import net.minecraft.nbt.TagParser;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.fml.ModList;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import tschipp.carryon.common.config.Configs.ModelOverrides;
|
|
||||||
import tschipp.carryon.common.helper.InvalidConfigException;
|
|
||||||
import tschipp.carryon.common.helper.StringParser;
|
|
||||||
|
|
||||||
public class ModelOverridesHandler
|
|
||||||
{
|
|
||||||
public static HashMap<CompoundTag, Object> OVERRIDE_OBJECTS = new HashMap<>();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This class is really ugly, will probably be replaced by something else -
|
|
||||||
* Tschipp
|
|
||||||
*/
|
|
||||||
public static void parseOverride(String overrideString, int i)
|
|
||||||
{
|
|
||||||
boolean errored = false;
|
|
||||||
|
|
||||||
Object toOverrideObject;
|
|
||||||
Object overrideObject;
|
|
||||||
CompoundTag tag = new CompoundTag();
|
|
||||||
|
|
||||||
String currentline = overrideString;
|
|
||||||
if (StringUtils.isEmpty(currentline) || !StringUtils.contains(currentline, "->"))
|
|
||||||
new InvalidConfigException("Missing Override Model at line " + i + " : " + currentline).printException();
|
|
||||||
|
|
||||||
String[] sa = currentline.split("->");
|
|
||||||
String toOverride = "";
|
|
||||||
String override = "";
|
|
||||||
try
|
|
||||||
{
|
|
||||||
toOverride = sa[0];
|
|
||||||
override = sa[1];
|
|
||||||
}
|
|
||||||
catch (ArrayIndexOutOfBoundsException e)
|
|
||||||
{
|
|
||||||
errored = true;
|
|
||||||
new InvalidConfigException("Missing Override Model at line " + i + " : " + currentline).printException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toOverride.contains("{"))
|
|
||||||
{
|
|
||||||
if (!toOverride.contains("}"))
|
|
||||||
{
|
|
||||||
errored = true;
|
|
||||||
new InvalidConfigException("Missing } at line " + i + " : " + currentline).printException();
|
|
||||||
}
|
|
||||||
|
|
||||||
String nbt = toOverride.substring(toOverride.indexOf("{"));
|
|
||||||
toOverride = toOverride.replace(nbt, "");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
tag = TagParser.parseTag(nbt);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
errored = true;
|
|
||||||
new InvalidConfigException("Error while parsing NBT at line " + i + " : " + e.getMessage()).printException();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (toOverride.contains("}"))
|
|
||||||
{
|
|
||||||
errored = true;
|
|
||||||
new InvalidConfigException("Missing { at line " + i + " : " + currentline).printException();
|
|
||||||
}
|
|
||||||
|
|
||||||
String overridetype = "item";
|
|
||||||
if (override.contains("("))
|
|
||||||
{
|
|
||||||
if (!override.contains(")"))
|
|
||||||
{
|
|
||||||
errored = true;
|
|
||||||
new InvalidConfigException("Missing ) at line " + i + " : " + currentline).printException();
|
|
||||||
}
|
|
||||||
|
|
||||||
overridetype = override.substring(0, override.indexOf(")") + 1);
|
|
||||||
override = override.replace(overridetype, "");
|
|
||||||
overridetype = overridetype.replace("(", "");
|
|
||||||
overridetype = overridetype.replace(")", "");
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (override.contains(")"))
|
|
||||||
{
|
|
||||||
errored = true;
|
|
||||||
new InvalidConfigException("Missing ( at line " + i + " : " + currentline).printException();
|
|
||||||
}
|
|
||||||
|
|
||||||
String modidToOverride = "minecraft";
|
|
||||||
String modidOverride = "minecraft";
|
|
||||||
|
|
||||||
if (toOverride.contains(":"))
|
|
||||||
modidToOverride = toOverride.replace(toOverride.substring(toOverride.indexOf(":")), "");
|
|
||||||
|
|
||||||
if (override.contains(":"))
|
|
||||||
modidOverride = override.replace(override.substring(override.indexOf(":")), "");
|
|
||||||
|
|
||||||
if ((ModList.get().isLoaded(modidOverride) || modidOverride.equals("minecraft")) && (ModList.get().isLoaded(modidToOverride) || modidToOverride.equals("minecraft")) && !errored)
|
|
||||||
{
|
|
||||||
toOverrideObject = StringParser.getBlockState(toOverride);
|
|
||||||
|
|
||||||
if (toOverrideObject != null)
|
|
||||||
{
|
|
||||||
if (overridetype.equals("block"))
|
|
||||||
overrideObject = StringParser.getBlockState(override);
|
|
||||||
else
|
|
||||||
overrideObject = StringParser.getItemStack(override);
|
|
||||||
|
|
||||||
if (overrideObject != null)
|
|
||||||
{
|
|
||||||
CompoundTag keyComp = new CompoundTag();
|
|
||||||
keyComp.put("nbttag", tag);
|
|
||||||
if (toOverrideObject instanceof Block)
|
|
||||||
{
|
|
||||||
keyComp.putString("block", ForgeRegistries.BLOCKS.getKey(((Block) toOverrideObject)).toString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
keyComp.putInt("stateid", Block.getId((BlockState) toOverrideObject));
|
|
||||||
keyComp.putString("block", ForgeRegistries.BLOCKS.getKey(((BlockState) toOverrideObject).getBlock()).toString());
|
|
||||||
}
|
|
||||||
OVERRIDE_OBJECTS.put(keyComp, overrideObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initOverrides()
|
|
||||||
{
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<String> overrides = (List<String>) ModelOverrides.modelOverrides.get();
|
|
||||||
|
|
||||||
for (int i = 0; i < overrides.size(); i++)
|
|
||||||
{
|
|
||||||
parseOverride(overrides.get(i), i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasCustomOverrideModel(BlockState state, CompoundTag tag)
|
|
||||||
{
|
|
||||||
if (OVERRIDE_OBJECTS.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
int stateid = Block.getId(state);
|
|
||||||
CompoundTag[] keys = new CompoundTag[OVERRIDE_OBJECTS.size()];
|
|
||||||
OVERRIDE_OBJECTS.keySet().toArray(keys);
|
|
||||||
for (CompoundTag key : keys)
|
|
||||||
{
|
|
||||||
int id = key.getInt("stateid");
|
|
||||||
Block block = StringParser.getBlock(key.getString("block"));
|
|
||||||
if (id == 0 ? block == state.getBlock() : id == stateid)
|
|
||||||
{
|
|
||||||
CompoundTag toCheckForCompound = key.getCompound("nbttag");
|
|
||||||
Set<String> kSetToCheck = toCheckForCompound.getAllKeys();
|
|
||||||
Set<String> kSetTile = tag.getAllKeys();
|
|
||||||
|
|
||||||
boolean flag = true;
|
|
||||||
if (kSetTile.containsAll(kSetToCheck))
|
|
||||||
{
|
|
||||||
for (String skey : kSetToCheck)
|
|
||||||
{
|
|
||||||
if (!NbtUtils.compareNbt(tag.get(skey), toCheckForCompound.get(skey), true))
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
if (flag)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public static BakedModel getCustomOverrideModel(BlockState state, CompoundTag tag, Level level, Player player)
|
|
||||||
{
|
|
||||||
int stateid = Block.getId(state);
|
|
||||||
CompoundTag[] keys = new CompoundTag[OVERRIDE_OBJECTS.size()];
|
|
||||||
OVERRIDE_OBJECTS.keySet().toArray(keys);
|
|
||||||
for (CompoundTag key : keys)
|
|
||||||
{
|
|
||||||
int id = key.getInt("stateid");
|
|
||||||
Block block = StringParser.getBlock(key.getString("block"));
|
|
||||||
if (id == 0 ? block == state.getBlock() : id == stateid)
|
|
||||||
{
|
|
||||||
CompoundTag toCheckForCompound = key.getCompound("nbttag");
|
|
||||||
Set<String> kSetToCheck = toCheckForCompound.getAllKeys();
|
|
||||||
Set<String> kSetTile = tag.getAllKeys();
|
|
||||||
|
|
||||||
boolean flag = true;
|
|
||||||
if (kSetTile.containsAll(kSetToCheck))
|
|
||||||
{
|
|
||||||
for (String skey : kSetToCheck)
|
|
||||||
{
|
|
||||||
if (!NbtUtils.compareNbt(tag.get(skey), toCheckForCompound.get(skey), true))
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
Object override = OVERRIDE_OBJECTS.get(key);
|
|
||||||
|
|
||||||
if (override == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (override instanceof BlockState)
|
|
||||||
return Minecraft.getInstance().getBlockRenderer().getBlockModel((BlockState) override);
|
|
||||||
else
|
|
||||||
return Minecraft.getInstance().getItemRenderer().getModel((ItemStack) override, level, player, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object getOverrideObject(BlockState state, CompoundTag tag)
|
|
||||||
{
|
|
||||||
int stateid = Block.getId(state);
|
|
||||||
CompoundTag[] keys = new CompoundTag[OVERRIDE_OBJECTS.size()];
|
|
||||||
OVERRIDE_OBJECTS.keySet().toArray(keys);
|
|
||||||
for (CompoundTag key : keys)
|
|
||||||
{
|
|
||||||
int id = key.getInt("stateid");
|
|
||||||
Block block = StringParser.getBlock(key.getString("block"));
|
|
||||||
if (id == 0 ? block == state.getBlock() : id == stateid)
|
|
||||||
{
|
|
||||||
CompoundTag toCheckForCompound = key.getCompound("nbttag");
|
|
||||||
Set<String> kSetToCheck = toCheckForCompound.getAllKeys();
|
|
||||||
Set<String> kSetTile = tag.getAllKeys();
|
|
||||||
|
|
||||||
boolean flag = true;
|
|
||||||
if (kSetTile.containsAll(kSetToCheck))
|
|
||||||
{
|
|
||||||
for (String skey : kSetToCheck)
|
|
||||||
{
|
|
||||||
if (!NbtUtils.compareNbt(tag.get(skey), toCheckForCompound.get(skey), true))
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
return OVERRIDE_OBJECTS.get(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,201 +0,0 @@
|
||||||
package tschipp.carryon.common.handler;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.entity.AgeableMob;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.MobCategory;
|
|
||||||
import net.minecraft.world.entity.TamableAnimal;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.GameType;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
|
||||||
import net.minecraftforge.event.level.BlockEvent;
|
|
||||||
import tschipp.carryon.common.config.Configs.Settings;
|
|
||||||
import tschipp.carryon.common.helper.CarryonGamestageHelper;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonBlock;
|
|
||||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
|
||||||
import tschipp.carryon.common.scripting.ScriptChecker;
|
|
||||||
|
|
||||||
public class PickupHandler
|
|
||||||
{
|
|
||||||
|
|
||||||
public static boolean canPlayerPickUpBlock(ServerPlayer player, @Nullable BlockEntity tile, Level level, BlockPos pos)
|
|
||||||
{
|
|
||||||
if (player.gameMode.getGameModeForPlayer() == GameType.SPECTATOR || player.gameMode.getGameModeForPlayer() == GameType.ADVENTURE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BlockState state = level.getBlockState(pos);
|
|
||||||
CompoundTag tag = new CompoundTag();
|
|
||||||
if (tile != null)
|
|
||||||
tile.saveWithId();
|
|
||||||
|
|
||||||
CarryOnOverride override = ScriptChecker.inspectBlock(level.getBlockState(pos), level, pos, tag);
|
|
||||||
if (override != null)
|
|
||||||
{
|
|
||||||
return ScriptChecker.fulfillsConditions(override, player) && handleProtections(player, level, pos, state);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Settings.useWhitelistBlocks.get())
|
|
||||||
{
|
|
||||||
if (!ListHandler.isAllowed(level.getBlockState(pos).getBlock()))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ListHandler.isForbidden(level.getBlockState(pos).getBlock()))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.getDestroySpeed(level, pos) != -1 || player.isCreative())
|
|
||||||
{
|
|
||||||
double distance = Vec3.atLowerCornerOf(pos).distanceTo(player.position());
|
|
||||||
double maxDist = Settings.maxDistance.get();
|
|
||||||
|
|
||||||
if (distance < maxDist && !ItemCarryonBlock.isLocked(pos, level))
|
|
||||||
{
|
|
||||||
|
|
||||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(state))
|
|
||||||
{
|
|
||||||
return CarryonGamestageHelper.hasGamestage(CustomPickupOverrideHandler.getPickupCondition(state), player) && handleProtections(player, level, pos, state);
|
|
||||||
}
|
|
||||||
else if (Settings.pickupAllBlocks.get() ? true : tile != null)
|
|
||||||
{
|
|
||||||
return handleProtections(player, level, pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canPlayerPickUpEntity(ServerPlayer player, Entity toPickUp)
|
|
||||||
{
|
|
||||||
if (player.gameMode.getGameModeForPlayer() == GameType.SPECTATOR || player.gameMode.getGameModeForPlayer() == GameType.ADVENTURE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Vec3 pos = toPickUp.position();
|
|
||||||
|
|
||||||
if (toPickUp instanceof Player)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CarryOnOverride override = ScriptChecker.inspectEntity(toPickUp);
|
|
||||||
if (override != null)
|
|
||||||
{
|
|
||||||
return ScriptChecker.fulfillsConditions(override, player) && handleProtections(player, toPickUp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (toPickUp instanceof AgeableMob living && Settings.allowBabies.get() && (living.getAge() < 0 || living.isBaby()))
|
|
||||||
{
|
|
||||||
|
|
||||||
double distance = pos.distanceToSqr(player.position());
|
|
||||||
if (distance <= Math.pow(Settings.maxDistance.get(), 2) && toPickUp instanceof TamableAnimal tame && tame.getOwnerUUID() != null && tame.getOwnerUUID() != player.getGameProfile().getId())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp))
|
|
||||||
{
|
|
||||||
return CarryonGamestageHelper.hasGamestage(CustomPickupOverrideHandler.getPickupCondition(toPickUp), player) && handleProtections(player, toPickUp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return handleProtections(player, toPickUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Settings.useWhitelistEntities.get())
|
|
||||||
{
|
|
||||||
if (!ListHandler.isAllowed(toPickUp))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ListHandler.isForbidden(toPickUp))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((Settings.pickupHostileMobs.get() ? true : toPickUp.getType().getCategory() != MobCategory.MONSTER || player.isCreative()) && (Settings.pickupHostileMobs.get() ? true : toPickUp.getType().getCategory() != MobCategory.MONSTER || player.isCreative()))
|
|
||||||
{
|
|
||||||
if (toPickUp.getBbHeight() <= Settings.maxEntityHeight.get() && toPickUp.getBbWidth() <= Settings.maxEntityWidth.get() || player.isCreative())
|
|
||||||
{
|
|
||||||
double distance = pos.distanceToSqr(player.position());
|
|
||||||
if (distance < Math.pow(Settings.maxDistance.get(), 2))
|
|
||||||
{
|
|
||||||
if (toPickUp instanceof TamableAnimal tame)
|
|
||||||
{
|
|
||||||
UUID owner = tame.getOwnerUUID();
|
|
||||||
UUID playerID = player.getGameProfile().getId();
|
|
||||||
if (owner != null && !owner.equals(playerID))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp))
|
|
||||||
{
|
|
||||||
return CarryonGamestageHelper.hasGamestage(CustomPickupOverrideHandler.getPickupCondition(toPickUp), player) && handleProtections(player, toPickUp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return handleProtections(player, toPickUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PickUpBlockEvent extends BlockEvent.BreakEvent
|
|
||||||
{
|
|
||||||
public PickUpBlockEvent(Level level, BlockPos pos, BlockState state, Player player)
|
|
||||||
{
|
|
||||||
super(level, pos, state, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PickUpEntityEvent extends AttackEntityEvent
|
|
||||||
{
|
|
||||||
public PickUpEntityEvent(Player player, Entity target)
|
|
||||||
{
|
|
||||||
super(player, target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean handleProtections(ServerPlayer player, Level level, BlockPos pos, BlockState state)
|
|
||||||
{
|
|
||||||
boolean breakable = true;
|
|
||||||
|
|
||||||
PickUpBlockEvent event = new PickUpBlockEvent(level, pos, state, player);
|
|
||||||
MinecraftForge.EVENT_BUS.post(event);
|
|
||||||
|
|
||||||
if (event.isCanceled())
|
|
||||||
breakable = false;
|
|
||||||
|
|
||||||
return breakable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean handleProtections(ServerPlayer player, Entity entity)
|
|
||||||
{
|
|
||||||
boolean canPickup = true;
|
|
||||||
|
|
||||||
PickUpEntityEvent event = new PickUpEntityEvent(player, entity);
|
|
||||||
MinecraftForge.EVENT_BUS.post(event);
|
|
||||||
|
|
||||||
if (event.isCanceled())
|
|
||||||
canPickup = false;
|
|
||||||
|
|
||||||
return canPickup;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
package tschipp.carryon.common.handler;
|
|
||||||
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import net.minecraftforge.registries.RegistryObject;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.client.event.RenderEntityEvents;
|
|
||||||
import tschipp.carryon.client.event.RenderEvents;
|
|
||||||
import tschipp.carryon.common.capabilities.IPosition;
|
|
||||||
import tschipp.carryon.common.capabilities.event.PositionClientEvents;
|
|
||||||
import tschipp.carryon.common.capabilities.event.PositionCommonEvents;
|
|
||||||
import tschipp.carryon.common.event.IMCEvents;
|
|
||||||
import tschipp.carryon.common.event.ItemEntityEvents;
|
|
||||||
import tschipp.carryon.common.event.ItemEvents;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonBlock;
|
|
||||||
import tschipp.carryon.common.item.ItemCarryonEntity;
|
|
||||||
|
|
||||||
@EventBusSubscriber(modid = CarryOn.MODID, bus = Bus.MOD)
|
|
||||||
public class RegistrationHandler
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, CarryOn.MODID);
|
|
||||||
|
|
||||||
public static final RegistryObject<Item> itemTile = ITEMS.register("tile_item", () -> new ItemCarryonBlock());
|
|
||||||
public static final RegistryObject<Item> itemEntity = ITEMS.register("entity_item", () -> new ItemCarryonEntity());
|
|
||||||
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void regCommonEvents()
|
|
||||||
{
|
|
||||||
MinecraftForge.EVENT_BUS.register(new ItemEvents());
|
|
||||||
MinecraftForge.EVENT_BUS.register(new ItemEntityEvents());
|
|
||||||
MinecraftForge.EVENT_BUS.register(new PositionCommonEvents());
|
|
||||||
MinecraftForge.EVENT_BUS.register(new IMCEvents());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void regClientEvents()
|
|
||||||
{
|
|
||||||
MinecraftForge.EVENT_BUS.register(new RenderEvents());
|
|
||||||
MinecraftForge.EVENT_BUS.register(new RenderEntityEvents());
|
|
||||||
MinecraftForge.EVENT_BUS.register(new PositionClientEvents());
|
|
||||||
|
|
||||||
// if(ModList.get().isLoaded("obfuscate"))
|
|
||||||
// MinecraftForge.EVENT_BUS.register(new ObfuscateEvents());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void regOverrideList()
|
|
||||||
{
|
|
||||||
ModelOverridesHandler.initOverrides();
|
|
||||||
CustomPickupOverrideHandler.initPickupOverrides();
|
|
||||||
// ListHandler.initConfigLists();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void regCaps(RegisterCapabilitiesEvent event)
|
|
||||||
{
|
|
||||||
event.register(IPosition.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package tschipp.carryon.common.helper;
|
|
||||||
|
|
||||||
//import net.darkhax.gamestages.GameStageHelper;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
|
|
||||||
public class CarryonGamestageHelper
|
|
||||||
{
|
|
||||||
public static boolean hasGamestage(String stage, Player player)
|
|
||||||
{
|
|
||||||
// return GameStageHelper.hasStage(player, stage);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package tschipp.carryon.common.helper;
|
|
||||||
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
|
|
||||||
public class InvalidConfigException extends Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7161004674405185407L;
|
|
||||||
|
|
||||||
public InvalidConfigException(String cause)
|
|
||||||
{
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void printException()
|
|
||||||
{
|
|
||||||
CarryOn.LOGGER.error(this.getMessage());
|
|
||||||
for (int i = 0; i < this.getStackTrace().length; i++)
|
|
||||||
{
|
|
||||||
StackTraceElement element = this.getStackTrace()[i];
|
|
||||||
CarryOn.LOGGER.error(element.toString());
|
|
||||||
|
|
||||||
if (i >= 10)
|
|
||||||
{
|
|
||||||
CarryOn.LOGGER.error(this.getStackTrace().length - 10 + " more...");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CarryOn.LOGGER.info("");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
package tschipp.carryon.common.helper;
|
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
import org.lwjgl.glfw.GLFWKeyCallback;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.eventbus.api.Cancelable;
|
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
|
||||||
|
|
||||||
public class KeyboardCallbackWrapper
|
|
||||||
{
|
|
||||||
GLFWKeyCallback oldCallback;
|
|
||||||
|
|
||||||
public void setup(Minecraft mc)
|
|
||||||
{
|
|
||||||
this.oldCallback = GLFW.glfwSetKeyCallback(mc.getWindow().getWindow(), this::keyCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void keyCallback(long window, int key, int scancode, int action, int mods)
|
|
||||||
{
|
|
||||||
KeyPressedEvent event = new KeyPressedEvent(key, scancode);
|
|
||||||
MinecraftForge.EVENT_BUS.post(event);
|
|
||||||
|
|
||||||
if (event.isCanceled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (this.oldCallback != null)
|
|
||||||
this.oldCallback.invoke(window, key, scancode, action, mods);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cancelable
|
|
||||||
public static class KeyPressedEvent extends Event
|
|
||||||
{
|
|
||||||
public int key;
|
|
||||||
public int scancode;
|
|
||||||
|
|
||||||
public KeyPressedEvent(int key, int scancode)
|
|
||||||
{
|
|
||||||
this.key = key;
|
|
||||||
this.scancode = scancode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,263 +0,0 @@
|
||||||
/*
|
|
||||||
* Minecraft Forge
|
|
||||||
* Copyright (c) 2016.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation version 2.1
|
|
||||||
* of the License.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package tschipp.carryon.common.helper;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Some reflection helper code.
|
|
||||||
*
|
|
||||||
* @author cpw
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ReflectionHelper
|
|
||||||
{
|
|
||||||
public static class UnableToFindMethodException extends RuntimeException
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
// private String[] methodNames;
|
|
||||||
|
|
||||||
public UnableToFindMethodException(String[] methodNames, Exception failed)
|
|
||||||
{
|
|
||||||
super(failed);
|
|
||||||
// this.methodNames = methodNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UnableToFindMethodException(Throwable failed)
|
|
||||||
{
|
|
||||||
super(failed);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class UnableToFindClassException extends RuntimeException
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
// private String[] classNames;
|
|
||||||
|
|
||||||
public UnableToFindClassException(String[] classNames, @Nullable Exception err)
|
|
||||||
{
|
|
||||||
super(err);
|
|
||||||
// this.classNames = classNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class UnableToAccessFieldException extends RuntimeException
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
// private String[] fieldNameList;
|
|
||||||
|
|
||||||
public UnableToAccessFieldException(String[] fieldNames, Exception e)
|
|
||||||
{
|
|
||||||
super(e);
|
|
||||||
// this.fieldNameList = fieldNames;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class UnableToFindFieldException extends RuntimeException
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
// private String[] fieldNameList;
|
|
||||||
public UnableToFindFieldException(String[] fieldNameList, Exception e)
|
|
||||||
{
|
|
||||||
super(e);
|
|
||||||
// this.fieldNameList = fieldNameList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public static class UnknownConstructorException extends RuntimeException
|
|
||||||
{
|
|
||||||
public UnknownConstructorException(final String message)
|
|
||||||
{
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Field findField(Class<?> clazz, String... fieldNames)
|
|
||||||
{
|
|
||||||
Exception failed = null;
|
|
||||||
for (String fieldName : fieldNames)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Field f = clazz.getDeclaredField(fieldName);
|
|
||||||
f.setAccessible(true);
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
failed = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UnableToFindFieldException(fieldNames, failed);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T, E> T getPrivateValue(Class<? super E> classToAccess, @Nullable E instance, int fieldIndex)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Field f = classToAccess.getDeclaredFields()[fieldIndex];
|
|
||||||
f.setAccessible(true);
|
|
||||||
return (T) f.get(instance);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new UnableToAccessFieldException(new String[0], e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T, E> T getPrivateValue(Class<? super E> classToAccess, E instance, String... fieldNames)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (T) findField(classToAccess, fieldNames).get(instance);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new UnableToAccessFieldException(fieldNames, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, E> void setPrivateValue(Class<? super T> classToAccess, T instance, E value, int fieldIndex)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Field f = classToAccess.getDeclaredFields()[fieldIndex];
|
|
||||||
f.setAccessible(true);
|
|
||||||
f.set(instance, value);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new UnableToAccessFieldException(new String[0], e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, E> void setPrivateValue(Class<? super T> classToAccess, T instance, E value, String... fieldNames)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
findField(classToAccess, fieldNames).set(instance, value);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new UnableToAccessFieldException(fieldNames, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static Class<? super Object> getClass(ClassLoader loader, String... classNames)
|
|
||||||
{
|
|
||||||
Exception err = null;
|
|
||||||
for (String className : classNames)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (Class<? super Object>) Class.forName(className, false, loader);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
err = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UnableToFindClassException(classNames, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds a method with the specified name and parameters in the given class
|
|
||||||
* and makes it accessible. Note: for performance, store the returned value
|
|
||||||
* and avoid calling this repeatedly.
|
|
||||||
* <p>
|
|
||||||
* Throws an exception if the method is not found.
|
|
||||||
*
|
|
||||||
* @param clazz
|
|
||||||
* The class to find the method on.
|
|
||||||
* @param methodName
|
|
||||||
* The name of the method to find (used in developer
|
|
||||||
* environments, i.e. "getLevelTime").
|
|
||||||
* @param methodObfName
|
|
||||||
* The obfuscated name of the method to find (used in obfuscated
|
|
||||||
* environments, i.e. "getLevelTime"). If the name you are
|
|
||||||
* looking for is on a class that is never obfuscated, this
|
|
||||||
* should be null.
|
|
||||||
* @param parameterTypes
|
|
||||||
* The parameter types of the method to find.
|
|
||||||
* @return The method with the specified name and parameters in the given
|
|
||||||
* class.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds a constructor in the specified class that has matching parameter
|
|
||||||
* types.
|
|
||||||
*
|
|
||||||
* @param klass
|
|
||||||
* The class to find the constructor in
|
|
||||||
* @param parameterTypes
|
|
||||||
* The parameter types of the constructor.
|
|
||||||
* @param <T>
|
|
||||||
* The type
|
|
||||||
* @return The constructor
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if {@code klass} is null
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if {@code parameterTypes} is null
|
|
||||||
* @throws UnknownConstructorException
|
|
||||||
* if the constructor could not be found
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
public static <T> Constructor<T> findConstructor(@Nonnull final Class<T> klass, @Nonnull final Class<?>... parameterTypes)
|
|
||||||
{
|
|
||||||
Preconditions.checkNotNull(klass, "class");
|
|
||||||
Preconditions.checkNotNull(parameterTypes, "parameter types");
|
|
||||||
|
|
||||||
final Constructor<T> constructor;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
constructor = klass.getDeclaredConstructor(parameterTypes);
|
|
||||||
constructor.setAccessible(true);
|
|
||||||
}
|
|
||||||
catch (final NoSuchMethodException e)
|
|
||||||
{
|
|
||||||
final StringBuilder desc = new StringBuilder();
|
|
||||||
desc.append(klass.getSimpleName()).append('(');
|
|
||||||
for (int i = 0, length = parameterTypes.length; i < length; i++)
|
|
||||||
{
|
|
||||||
desc.append(parameterTypes[i].getName());
|
|
||||||
if (i > length)
|
|
||||||
{
|
|
||||||
desc.append(',').append(' ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
desc.append(')');
|
|
||||||
throw new UnknownConstructorException("Could not find constructor '" + desc.toString() + "' in " + klass);
|
|
||||||
}
|
|
||||||
return constructor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
package tschipp.carryon.common.helper;
|
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
|
||||||
import java.lang.invoke.MethodHandles;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility methods for reflection.
|
|
||||||
*
|
|
||||||
* @author Choonster
|
|
||||||
*/
|
|
||||||
public class ReflectionUtil
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get a {@link MethodHandle} for a method.
|
|
||||||
*
|
|
||||||
* @param clazz
|
|
||||||
* The class
|
|
||||||
* @param methodName
|
|
||||||
* The possible names of the method
|
|
||||||
* @param methodObfName
|
|
||||||
* The obfuscated method name
|
|
||||||
* @param parameterTypes
|
|
||||||
* The argument types of the method
|
|
||||||
* @return The MethodHandle
|
|
||||||
*/
|
|
||||||
public static MethodHandle findMethod(final Class<?> clazz, final String methodName, @Nullable final String methodObfName, final Class<?>... parameterTypes)
|
|
||||||
{
|
|
||||||
final Method method = ObfuscationReflectionHelper.findMethod(clazz, methodName, parameterTypes);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return MethodHandles.lookup().unreflect(method);
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException e)
|
|
||||||
{
|
|
||||||
throw new ObfuscationReflectionHelper.UnableToFindMethodException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a {@link MethodHandle} for a field's getter.
|
|
||||||
*
|
|
||||||
* @param clazz
|
|
||||||
* The class
|
|
||||||
* @param fieldNames
|
|
||||||
* The possible names of the field
|
|
||||||
* @return The MethodHandle
|
|
||||||
*/
|
|
||||||
public static MethodHandle findFieldGetter(Class<?> clazz, String... fieldNames)
|
|
||||||
{
|
|
||||||
final Field field = ReflectionHelper.findField(clazz, fieldNames);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return MethodHandles.lookup().unreflectGetter(field);
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException e)
|
|
||||||
{
|
|
||||||
throw new ReflectionHelper.UnableToAccessFieldException(fieldNames, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a {@link MethodHandle} for a field's setter.
|
|
||||||
*
|
|
||||||
* @param clazz
|
|
||||||
* The class
|
|
||||||
* @param fieldNames
|
|
||||||
* The possible names of the field
|
|
||||||
* @return The MethodHandle
|
|
||||||
*/
|
|
||||||
public static MethodHandle findFieldSetter(Class<?> clazz, String... fieldNames)
|
|
||||||
{
|
|
||||||
final Field field = ReflectionHelper.findField(clazz, fieldNames);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return MethodHandles.lookup().unreflectSetter(field);
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException e)
|
|
||||||
{
|
|
||||||
throw new ReflectionHelper.UnableToAccessFieldException(fieldNames, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,355 +0,0 @@
|
||||||
package tschipp.carryon.common.helper;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.Tag;
|
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.material.Material;
|
|
||||||
import net.minecraft.world.scores.Objective;
|
|
||||||
import net.minecraft.world.scores.Score;
|
|
||||||
import net.minecraft.world.scores.Scoreboard;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
|
|
||||||
public class ScriptParseHelper
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean matches(double number, String cond)
|
|
||||||
{
|
|
||||||
if (cond == null || cond.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (cond.contains("<="))
|
|
||||||
{
|
|
||||||
return number <= Double.parseDouble(cond.replace("<=", ""));
|
|
||||||
}
|
|
||||||
if (cond.contains(">="))
|
|
||||||
{
|
|
||||||
return number >= Double.parseDouble(cond.replace(">=", ""));
|
|
||||||
}
|
|
||||||
if (cond.contains("<"))
|
|
||||||
{
|
|
||||||
return number < Double.parseDouble(cond.replace("<", ""));
|
|
||||||
}
|
|
||||||
if (cond.contains(">"))
|
|
||||||
{
|
|
||||||
return number > Double.parseDouble(cond.replace(">", ""));
|
|
||||||
}
|
|
||||||
if (cond.contains("="))
|
|
||||||
{
|
|
||||||
return number == Double.parseDouble(cond.replace("=", ""));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return number == Double.parseDouble(cond);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
new InvalidConfigException(e.getMessage()).printException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matches(Block block, String cond)
|
|
||||||
{
|
|
||||||
if (cond == null || cond.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
Block toCheck = StringParser.getBlock(cond);
|
|
||||||
if (toCheck != null)
|
|
||||||
return block == toCheck;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matches(CompoundTag toCheck, CompoundTag toMatch)
|
|
||||||
{
|
|
||||||
if (toCheck == null || toMatch == null || toMatch.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
boolean matching = true;
|
|
||||||
for (String key : toMatch.getAllKeys())
|
|
||||||
{
|
|
||||||
Tag tag = toMatch.get(key);
|
|
||||||
key = key.replace("\"", "");
|
|
||||||
Tag tagToCheck = toCheck.get(key);
|
|
||||||
if (!tag.equals(tagToCheck))
|
|
||||||
matching = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return matching;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[] getXYZArray(String s)
|
|
||||||
{
|
|
||||||
float[] d = new float[3];
|
|
||||||
d[0] = getValueFromString(s, "x");
|
|
||||||
d[1] = getValueFromString(s, "y");
|
|
||||||
d[2] = getValueFromString(s, "z");
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[] getScaled(String s)
|
|
||||||
{
|
|
||||||
float[] d = new float[3];
|
|
||||||
d[0] = getScaledValueFromString(s, "x");
|
|
||||||
d[1] = getScaledValueFromString(s, "y");
|
|
||||||
d[2] = getScaledValueFromString(s, "z");
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getScaledValueFromString(String toGetFrom, String key)
|
|
||||||
{
|
|
||||||
if (toGetFrom == null || toGetFrom.isEmpty())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
String[] s = toGetFrom.split(",");
|
|
||||||
for (String string : s)
|
|
||||||
{
|
|
||||||
if (string.contains(key) && string.contains("="))
|
|
||||||
{
|
|
||||||
float numb = 1;
|
|
||||||
string = string.replace(key + "=", "");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
numb = Float.parseFloat(string);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return numb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matchesScore(Player player, String cond)
|
|
||||||
{
|
|
||||||
if (cond == null || cond.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
Scoreboard score = player.getScoreboard();
|
|
||||||
String numb;
|
|
||||||
String scorename;
|
|
||||||
int iE = cond.indexOf("=");
|
|
||||||
int iG = cond.indexOf(">");
|
|
||||||
int iL = cond.indexOf("<");
|
|
||||||
|
|
||||||
if (iG == -1 ? true : iE < iG && iL == -1 ? true : iE < iL && iE != -1)
|
|
||||||
numb = cond.substring(iE);
|
|
||||||
else if (iE == -1 ? true : iG < iE && iL == -1 ? true : iG < iL && iG != -1)
|
|
||||||
numb = cond.substring(iG);
|
|
||||||
else
|
|
||||||
numb = cond.substring(iL);
|
|
||||||
|
|
||||||
scorename = cond.replace(numb, "");
|
|
||||||
Map<Objective, Score> o = score.getPlayerScores(player.getGameProfile().getName());
|
|
||||||
if (o != null)
|
|
||||||
{
|
|
||||||
Score sc = o.get(score.getObjective(scorename));
|
|
||||||
if (sc != null)
|
|
||||||
{
|
|
||||||
int points = sc.getScore();
|
|
||||||
|
|
||||||
return matches(points, numb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matches(BlockPos pos, String cond)
|
|
||||||
{
|
|
||||||
if (cond == null || cond.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
BlockPos blockpos = new BlockPos(getValueFromString(cond, "x"), getValueFromString(cond, "y"), getValueFromString(cond, "z"));
|
|
||||||
BlockPos expand = new BlockPos(getValueFromString(cond, "dx"), getValueFromString(cond, "dy"), getValueFromString(cond, "dz"));
|
|
||||||
BlockPos expanded = blockpos.offset(expand);
|
|
||||||
|
|
||||||
boolean x = pos.getX() >= blockpos.getX() && pos.getX() <= expanded.getX() || blockpos.getX() == 0;
|
|
||||||
boolean y = pos.getY() >= blockpos.getY() && pos.getY() <= expanded.getY() || blockpos.getY() == 0;
|
|
||||||
boolean z = pos.getZ() >= blockpos.getZ() && pos.getZ() <= expanded.getZ() || blockpos.getZ() == 0;
|
|
||||||
|
|
||||||
return x && y && z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getValueFromString(String toGetFrom, String key)
|
|
||||||
{
|
|
||||||
if (toGetFrom == null || toGetFrom.isEmpty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
String[] s = toGetFrom.split(",");
|
|
||||||
for (String string : s)
|
|
||||||
{
|
|
||||||
if (string.contains(key) && string.contains("="))
|
|
||||||
{
|
|
||||||
float numb = 0;
|
|
||||||
string = string.replace(key + "=", "");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
numb = Float.parseFloat(string);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return numb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasEffects(Player player, String cond)
|
|
||||||
{
|
|
||||||
if (cond == null || cond.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
Collection<MobEffectInstance> effects = player.getActiveEffects();
|
|
||||||
String[] potions = cond.split(",");
|
|
||||||
|
|
||||||
List<String> names = new ArrayList<>();
|
|
||||||
List<Integer> levels = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String pot : potions)
|
|
||||||
{
|
|
||||||
if (pot.contains("#"))
|
|
||||||
{
|
|
||||||
String level = pot.substring(pot.indexOf("#"));
|
|
||||||
String name = pot.substring(0, pot.indexOf("#"));
|
|
||||||
level = level.replace("#", "");
|
|
||||||
int lev = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
lev = Integer.parseInt(level);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
levels.add(lev);
|
|
||||||
names.add(name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
levels.add(0);
|
|
||||||
names.add(pot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int matches = 0;
|
|
||||||
for (MobEffectInstance effect : effects)
|
|
||||||
{
|
|
||||||
int amp = effect.getAmplifier();
|
|
||||||
String name = ForgeRegistries.MOB_EFFECTS.getKey(effect.getEffect()).toString();
|
|
||||||
|
|
||||||
if (names.contains(name))
|
|
||||||
{
|
|
||||||
int idx = names.indexOf(name);
|
|
||||||
int lev = levels.get(idx);
|
|
||||||
|
|
||||||
if (lev == amp)
|
|
||||||
matches++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return matches == potions.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matches(Material material, String cond)
|
|
||||||
{
|
|
||||||
if (cond == null || cond.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
switch (cond)
|
|
||||||
{
|
|
||||||
case "air":
|
|
||||||
return material == Material.AIR;
|
|
||||||
case "anvil":
|
|
||||||
return material == Material.HEAVY_METAL;
|
|
||||||
case "barrier":
|
|
||||||
return material == Material.BARRIER;
|
|
||||||
case "cactus":
|
|
||||||
return material == Material.CACTUS;
|
|
||||||
case "cake":
|
|
||||||
return material == Material.CAKE;
|
|
||||||
case "carpet":
|
|
||||||
return material == Material.CLOTH_DECORATION;
|
|
||||||
case "clay":
|
|
||||||
return material == Material.CLAY;
|
|
||||||
case "cloth":
|
|
||||||
return material == Material.WOOL;
|
|
||||||
case "dragon_egg":
|
|
||||||
return material == Material.EGG;
|
|
||||||
case "fire":
|
|
||||||
return material == Material.FIRE;
|
|
||||||
case "glass":
|
|
||||||
return material == Material.GLASS;
|
|
||||||
case "gourd":
|
|
||||||
return material == Material.VEGETABLE;
|
|
||||||
case "grass":
|
|
||||||
return material == Material.GRASS;
|
|
||||||
case "ground":
|
|
||||||
return material == Material.GRASS;
|
|
||||||
case "ice":
|
|
||||||
return material == Material.ICE;
|
|
||||||
case "iron":
|
|
||||||
return material == Material.METAL;
|
|
||||||
case "lava":
|
|
||||||
return material == Material.LAVA;
|
|
||||||
case "leaves":
|
|
||||||
return material == Material.LEAVES;
|
|
||||||
case "packed_ice":
|
|
||||||
return material == Material.ICE_SOLID;
|
|
||||||
case "piston":
|
|
||||||
return material == Material.PISTON;
|
|
||||||
case "plants":
|
|
||||||
return material == Material.PLANT;
|
|
||||||
case "portal":
|
|
||||||
return material == Material.PORTAL;
|
|
||||||
case "redstone_light":
|
|
||||||
return material == Material.BUILDABLE_GLASS;
|
|
||||||
case "rock":
|
|
||||||
return material == Material.STONE;
|
|
||||||
case "sand":
|
|
||||||
return material == Material.SAND;
|
|
||||||
case "snow":
|
|
||||||
return material == Material.TOP_SNOW;
|
|
||||||
case "sponge":
|
|
||||||
return material == Material.SPONGE;
|
|
||||||
case "structure_void":
|
|
||||||
return material == Material.STRUCTURAL_AIR;
|
|
||||||
case "tnt":
|
|
||||||
return material == Material.EXPLOSIVE;
|
|
||||||
case "vine":
|
|
||||||
return material == Material.PLANT;
|
|
||||||
case "water":
|
|
||||||
return material == Material.WATER;
|
|
||||||
case "web":
|
|
||||||
return material == Material.WEB;
|
|
||||||
case "wood":
|
|
||||||
return material == Material.WOOD;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
package tschipp.carryon.common.helper;
|
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
import org.lwjgl.glfw.GLFWScrollCallback;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.eventbus.api.Cancelable;
|
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
|
||||||
|
|
||||||
//Thanks to gigaherz for the help!
|
|
||||||
public class ScrollCallbackWrapper
|
|
||||||
{
|
|
||||||
GLFWScrollCallback oldCallback;
|
|
||||||
|
|
||||||
public void setup(Minecraft mc)
|
|
||||||
{
|
|
||||||
this.oldCallback = GLFW.glfwSetScrollCallback(mc.getWindow().getWindow(), this::scrollCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scrollCallback(long window, double xoffset, double yoffset)
|
|
||||||
{
|
|
||||||
MouseScrolledEvent event = new MouseScrolledEvent();
|
|
||||||
MinecraftForge.EVENT_BUS.post(event);
|
|
||||||
|
|
||||||
if (event.isCanceled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (this.oldCallback != null)
|
|
||||||
this.oldCallback.invoke(window, xoffset, yoffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cancelable
|
|
||||||
public static class MouseScrolledEvent extends Event
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,133 +0,0 @@
|
||||||
package tschipp.carryon.common.helper;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.mojang.brigadier.StringReader;
|
|
||||||
|
|
||||||
import net.minecraft.commands.arguments.blocks.BlockStateParser;
|
|
||||||
import net.minecraft.commands.arguments.blocks.BlockStateParser.BlockResult;
|
|
||||||
import net.minecraft.commands.arguments.item.ItemParser;
|
|
||||||
import net.minecraft.commands.arguments.item.ItemParser.ItemResult;
|
|
||||||
import net.minecraft.core.HolderLookup;
|
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.TagParser;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
|
|
||||||
public class StringParser
|
|
||||||
{
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static Block getBlock(String string)
|
|
||||||
{
|
|
||||||
BlockState state = getBlockState(string);
|
|
||||||
if (state != null)
|
|
||||||
return state.getBlock();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static BlockState getBlockState(String string)
|
|
||||||
{
|
|
||||||
if (string == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
BlockResult result = BlockStateParser.parseForBlock(HolderLookup.forRegistry(Registry.BLOCK), new StringReader(string), false);
|
|
||||||
return result.blockState();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
new InvalidConfigException("Blockstate parsing Exception at: " + string + " : " + e.getMessage()).printException();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static Item getItem(String string)
|
|
||||||
{
|
|
||||||
if (string == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ItemResult res = ItemParser.parseForItem(HolderLookup.forRegistry(Registry.ITEM), new StringReader(string));
|
|
||||||
return res.item().get();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
new InvalidConfigException("Item parsing Exception at: " + string + " : " + e.getMessage()).printException();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getItemStack(String string)
|
|
||||||
{
|
|
||||||
if (string == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ItemResult res = ItemParser.parseForItem(HolderLookup.forRegistry(Registry.ITEM), new StringReader(string));
|
|
||||||
|
|
||||||
Item item = res.item().get();
|
|
||||||
CompoundTag nbt = res.nbt();
|
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(item, 1);
|
|
||||||
|
|
||||||
if (nbt != null)
|
|
||||||
{
|
|
||||||
stack.setTag(nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
new InvalidConfigException("Item parsing Exception at: " + string + " : " + e.getMessage()).printException();
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static CompoundTag getTagCompound(String string)
|
|
||||||
{
|
|
||||||
CompoundTag tag = null;
|
|
||||||
if (string == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (string.contains("{"))
|
|
||||||
{
|
|
||||||
if (!string.contains("}"))
|
|
||||||
new InvalidConfigException("Missing } at : " + string).printException();
|
|
||||||
|
|
||||||
String nbt = string.substring(string.indexOf("{"));
|
|
||||||
string = string.replace(nbt, "");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
tag = TagParser.parseTag(nbt);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
new InvalidConfigException("Error while parsing NBT: " + e.getMessage()).printException();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (string.contains("}"))
|
|
||||||
new InvalidConfigException("Missing { at : " + string).printException();
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,389 +0,0 @@
|
||||||
package tschipp.carryon.common.item;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.google.common.base.CharMatcher;
|
|
||||||
|
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.chat.ClickEvent;
|
|
||||||
import net.minecraft.network.chat.ClickEvent.Action;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
|
||||||
import net.minecraft.world.effect.MobEffects;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.Blocks;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.common.util.BlockSnapshot;
|
|
||||||
import net.minecraftforge.event.level.BlockEvent.EntityPlaceEvent;
|
|
||||||
import net.minecraftforge.fml.ModList;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
|
||||||
import tschipp.carryon.common.config.Configs.Settings;
|
|
||||||
import tschipp.carryon.common.event.ItemEvents;
|
|
||||||
import tschipp.carryon.common.handler.CustomPickupOverrideHandler;
|
|
||||||
import tschipp.carryon.common.handler.ModelOverridesHandler;
|
|
||||||
|
|
||||||
public class ItemCarryonBlock extends Item
|
|
||||||
{
|
|
||||||
|
|
||||||
public static final String TILE_DATA_KEY = "tileData";
|
|
||||||
public static final String[] FACING_KEYS = { "rotation", "rot", "facing", "face", "direction", "dir", "front", "forward" };
|
|
||||||
|
|
||||||
public ItemCarryonBlock()
|
|
||||||
{
|
|
||||||
super(new Item.Properties().stacksTo(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getName(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (hasTileData(stack))
|
|
||||||
{
|
|
||||||
BlockState state = getBlockState(stack);
|
|
||||||
CompoundTag nbt = getTileData(stack);
|
|
||||||
|
|
||||||
if (ModelOverridesHandler.hasCustomOverrideModel(state, nbt))
|
|
||||||
{
|
|
||||||
Object override = ModelOverridesHandler.getOverrideObject(state, nbt);
|
|
||||||
if (override instanceof ItemStack)
|
|
||||||
return ((ItemStack) override).getHoverName();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BlockState ostate = (BlockState) override;
|
|
||||||
return ostate.getBlock().getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return getItemStack(stack).getHoverName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Component.literal("");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InteractionResult useOn(UseOnContext context)
|
|
||||||
{
|
|
||||||
Direction facing = context.getClickedFace();
|
|
||||||
Player player = context.getPlayer();
|
|
||||||
Level level = context.getLevel();
|
|
||||||
BlockPos pos = context.getClickedPos();
|
|
||||||
ItemStack stack = context.getItemInHand();
|
|
||||||
|
|
||||||
if (ModList.get().isLoaded("betterplacement") && CarryOnKeybinds.isKeyPressed(player))
|
|
||||||
return InteractionResult.FAIL;
|
|
||||||
|
|
||||||
if (hasTileData(stack))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Vec3 vec = player.getLookAngle();
|
|
||||||
Direction facing2 = Direction.getNearest((float) vec.x, 0f, (float) vec.z);
|
|
||||||
BlockPos pos2 = pos;
|
|
||||||
Block containedblock = getBlock(stack);
|
|
||||||
BlockState containedstate = getBlockState(stack);
|
|
||||||
if (!level.getBlockState(pos2).canBeReplaced(new BlockPlaceContext(context)))
|
|
||||||
{
|
|
||||||
pos2 = pos.relative(facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level.getBlockState(pos2).canBeReplaced(new BlockPlaceContext(context)) && containedblock != null)
|
|
||||||
{
|
|
||||||
boolean canPlace = containedstate.canSurvive(level, pos2);
|
|
||||||
|
|
||||||
if (canPlace && player.mayUseItemAt(pos, facing, stack) && level.mayInteract(player, pos2))
|
|
||||||
{
|
|
||||||
|
|
||||||
BlockState placementState = containedblock.getStateForPlacement(new BlockPlaceContext(context));
|
|
||||||
|
|
||||||
BlockState actualState = placementState == null ? containedstate : placementState;
|
|
||||||
|
|
||||||
// Attempted fix for #287
|
|
||||||
// for (IProperty<?> prop :
|
|
||||||
// placementState.getValues().keySet())
|
|
||||||
// {
|
|
||||||
// if (prop instanceof DirectionProperty)
|
|
||||||
// actualState = actualState.with((DirectionProperty)
|
|
||||||
// prop, placementState.get((DirectionProperty) prop));
|
|
||||||
// else if (prop == BlockStateProperties.WATERLOGGED)
|
|
||||||
// actualState = actualState.with((BooleanProperty)
|
|
||||||
// prop, placementState.get((BooleanProperty) prop));
|
|
||||||
// else if(prop instanceof EnumProperty<?>)
|
|
||||||
// {
|
|
||||||
// Object value = placementState.get(prop);
|
|
||||||
// if(value instanceof Direction.Axis)
|
|
||||||
// {
|
|
||||||
// actualState = actualState.with((EnumProperty)prop,
|
|
||||||
// (Direction.Axis)value);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
BlockSnapshot snapshot = BlockSnapshot.create(level.dimension(), level, pos2);
|
|
||||||
EntityPlaceEvent event = new EntityPlaceEvent(snapshot, level.getBlockState(pos), player);
|
|
||||||
MinecraftForge.EVENT_BUS.post(event);
|
|
||||||
|
|
||||||
if (!event.isCanceled())
|
|
||||||
{
|
|
||||||
level.setBlockAndUpdate(pos2, actualState);
|
|
||||||
|
|
||||||
// If the blockstate doesn't handle rotation,
|
|
||||||
// try to
|
|
||||||
// change rotation via NBT
|
|
||||||
if (!getTileData(stack).isEmpty())
|
|
||||||
{
|
|
||||||
CompoundTag tag = getTileData(stack);
|
|
||||||
Set<String> keys = tag.getAllKeys();
|
|
||||||
keytester: for (String key : keys)
|
|
||||||
{
|
|
||||||
for (String facingKey : FACING_KEYS)
|
|
||||||
{
|
|
||||||
if (key.toLowerCase().equals(facingKey))
|
|
||||||
{
|
|
||||||
byte type = tag.getTagType(key);
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case 8:
|
|
||||||
tag.putString(key, CharMatcher.javaUpperCase().matchesAllOf(tag.getString(key)) ? facing2.getOpposite().getName().toUpperCase() : facing2.getOpposite().getName());
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
tag.putInt(key, facing2.getOpposite().get3DDataValue());
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
tag.putByte(key, (byte) facing2.getOpposite().get3DDataValue());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
break keytester;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockEntity tile = level.getBlockEntity(pos2);
|
|
||||||
if (tile != null)
|
|
||||||
{
|
|
||||||
CompoundTag data = getTileData(stack);
|
|
||||||
updateTileLocation(data, pos2);
|
|
||||||
tile.load(data);
|
|
||||||
}
|
|
||||||
clearTileData(stack);
|
|
||||||
player.playSound(actualState.getSoundType(level, pos2, player).getPlaceSound(), 1.0f, 0.5f);
|
|
||||||
player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
|
|
||||||
player.getPersistentData().remove("overrideKey");
|
|
||||||
ItemEvents.sendPacket(player, 9, 0);
|
|
||||||
return InteractionResult.SUCCESS;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
if (level != null && level.isClientSide)
|
|
||||||
{
|
|
||||||
CarryOn.LOGGER.info("Block: " + ItemCarryonBlock.getBlock(stack));
|
|
||||||
CarryOn.LOGGER.info("BlockState: " + ItemCarryonBlock.getBlockState(stack));
|
|
||||||
// CarryOn.LOGGER.info("Meta: " + itemTile.get().getMeta(stack));
|
|
||||||
CarryOn.LOGGER.info("ItemStack: " + ItemCarryonBlock.getItemStack(stack));
|
|
||||||
|
|
||||||
if (ModelOverridesHandler.hasCustomOverrideModel(ItemCarryonBlock.getBlockState(stack), ItemCarryonBlock.getTileData(stack)))
|
|
||||||
CarryOn.LOGGER.info("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemCarryonBlock.getBlockState(stack), ItemCarryonBlock.getTileData(stack)));
|
|
||||||
|
|
||||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemCarryonBlock.getBlockState(stack)))
|
|
||||||
CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemCarryonBlock.getBlockState(stack)));
|
|
||||||
|
|
||||||
player.displayClientMessage(Component.literal(ChatFormatting.RED + "Error detected. Cannot place block. Execute \"/carryon clear\" to remove the item"), false);
|
|
||||||
Component s = Component.literal(ChatFormatting.GOLD + "here");
|
|
||||||
s.getStyle().withClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/Tschipp/CarryOn/issues"));
|
|
||||||
player.displayClientMessage(Component.literal(ChatFormatting.RED + "Please report this error ").append(s), false);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return InteractionResult.FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int itemSlot, boolean isSelected)
|
|
||||||
{
|
|
||||||
if (hasTileData(stack))
|
|
||||||
{
|
|
||||||
if (entity instanceof LivingEntity)
|
|
||||||
{
|
|
||||||
if (entity instanceof Player && Settings.slownessInCreative.get() ? false : ((Player) entity).isCreative())
|
|
||||||
return;
|
|
||||||
|
|
||||||
((LivingEntity) entity).addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 1, potionLevel(stack), false, false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stack = ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasTileData(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
return tag.contains(TILE_DATA_KEY) && tag.contains("block") && tag.contains("stateid");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean storeTileData(@Nullable BlockEntity tile, Level level, BlockPos pos, BlockState state, ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CompoundTag tileTag = new CompoundTag();
|
|
||||||
if (tile != null)
|
|
||||||
tileTag = tile.saveWithId();
|
|
||||||
|
|
||||||
CompoundTag tag = stack.hasTag() ? stack.getTag() : new CompoundTag();
|
|
||||||
if (tag.contains(TILE_DATA_KEY))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
tag.put(TILE_DATA_KEY, tileTag);
|
|
||||||
|
|
||||||
// ItemStack drop = new ItemStack(state.getBlock().getItemDropped(state,
|
|
||||||
// itemRand, 0), 1, state.getBlock().damageDropped(state));
|
|
||||||
|
|
||||||
tag.putString("block", ForgeRegistries.BLOCKS.getKey(state.getBlock()).toString());
|
|
||||||
// Item item = Item.getItemFromBlock(state.getBlock());
|
|
||||||
// tag.setInt("meta", drop.getItemDamage());
|
|
||||||
tag.putInt("stateid", Block.getId(state));
|
|
||||||
stack.setTag(tag);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateTileLocation(CompoundTag tag, BlockPos pos)
|
|
||||||
{
|
|
||||||
tag.putInt("x", pos.getX());
|
|
||||||
tag.putInt("y", pos.getY());
|
|
||||||
tag.putInt("z", pos.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearTileData(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
tag.remove(TILE_DATA_KEY);
|
|
||||||
tag.remove("block");
|
|
||||||
tag.remove("stateid");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CompoundTag getTileData(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
return tag.getCompound(TILE_DATA_KEY);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Block getBlock(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
int id = tag.getInt("stateid");
|
|
||||||
return Block.stateById(id).getBlock();
|
|
||||||
}
|
|
||||||
return Blocks.AIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public static int getMeta(ItemStack stack)
|
|
||||||
// {
|
|
||||||
// if (stack.hasTag())
|
|
||||||
// {
|
|
||||||
// CompoundTag tag = stack.getTag();
|
|
||||||
// int meta = tag.getInt("meta");
|
|
||||||
// return meta;
|
|
||||||
// }
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static ItemStack getItemStack(ItemStack stack)
|
|
||||||
{
|
|
||||||
return new ItemStack(getBlock(stack), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BlockState getBlockState(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
int id = tag.getInt("stateid");
|
|
||||||
return Block.stateById(id);
|
|
||||||
}
|
|
||||||
return Blocks.AIR.defaultBlockState();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isLocked(BlockPos pos, Level level)
|
|
||||||
{
|
|
||||||
BlockEntity te = level.getBlockEntity(pos);
|
|
||||||
if (te != null)
|
|
||||||
{
|
|
||||||
CompoundTag tag = new CompoundTag();
|
|
||||||
te.saveWithId();
|
|
||||||
return tag.contains("Lock") ? !tag.getString("Lock").equals("") : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// private boolean equal(Object[] a, Object[] b)
|
|
||||||
// {
|
|
||||||
// if (a.length != b.length)
|
|
||||||
// return false;
|
|
||||||
//
|
|
||||||
// List lA = Arrays.asList(a);
|
|
||||||
// List lB = Arrays.asList(b);
|
|
||||||
//
|
|
||||||
// return lA.containsAll(lB);
|
|
||||||
// }
|
|
||||||
|
|
||||||
private int potionLevel(ItemStack stack)
|
|
||||||
{
|
|
||||||
String nbt = getTileData(stack).toString();
|
|
||||||
int i = nbt.length() / 500;
|
|
||||||
|
|
||||||
if (i > 4)
|
|
||||||
i = 4;
|
|
||||||
|
|
||||||
if (!Settings.heavyTiles.get())
|
|
||||||
i = 1;
|
|
||||||
|
|
||||||
return (int) (i * Settings.blockSlownessMultiplier.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,280 +0,0 @@
|
||||||
package tschipp.carryon.common.item;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
|
||||||
import net.minecraft.world.effect.MobEffects;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.EntityType;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.Mob;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraftforge.fml.ModList;
|
|
||||||
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
|
||||||
import tschipp.carryon.common.config.Configs.Settings;
|
|
||||||
import tschipp.carryon.common.event.ItemEvents;
|
|
||||||
|
|
||||||
public class ItemCarryonEntity extends Item
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final Method initGoals;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
initGoals = ObfuscationReflectionHelper.findMethod(Mob.class, "m_8099_");
|
|
||||||
initGoals.setAccessible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String ENTITY_DATA_KEY = "entityData";
|
|
||||||
|
|
||||||
public ItemCarryonEntity()
|
|
||||||
{
|
|
||||||
super(new Item.Properties().stacksTo(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getName(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (hasEntityData(stack))
|
|
||||||
{
|
|
||||||
|
|
||||||
return Component.translatable(getEntityType(stack).getDescriptionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Component.literal("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasEntityData(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
return tag.contains(ENTITY_DATA_KEY) && tag.contains("entity");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean storeEntityData(@Nonnull Entity entity, Level level, ItemStack stack)
|
|
||||||
{
|
|
||||||
if (entity == null || stack.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CompoundTag entityData = new CompoundTag();
|
|
||||||
entity.saveWithoutId(entityData);
|
|
||||||
|
|
||||||
String name = EntityType.getKey(entity.getType()).toString();
|
|
||||||
|
|
||||||
CompoundTag tag = stack.hasTag() ? stack.getTag() : new CompoundTag();
|
|
||||||
if (tag.contains(ENTITY_DATA_KEY))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
tag.put(ENTITY_DATA_KEY, entityData);
|
|
||||||
tag.putString("entity", name);
|
|
||||||
stack.setTag(tag);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InteractionResult useOn(UseOnContext context)
|
|
||||||
{
|
|
||||||
Player player = context.getPlayer();
|
|
||||||
Level level = context.getLevel();
|
|
||||||
BlockPos pos = context.getClickedPos();
|
|
||||||
Direction facing = context.getClickedFace();
|
|
||||||
|
|
||||||
ItemStack stack = context.getItemInHand();
|
|
||||||
|
|
||||||
BlockState state = level.getBlockState(pos);
|
|
||||||
|
|
||||||
if (ModList.get().isLoaded("betterplacement") && CarryOnKeybinds.isKeyPressed(player))
|
|
||||||
return InteractionResult.FAIL;
|
|
||||||
|
|
||||||
if (hasEntityData(stack))
|
|
||||||
{
|
|
||||||
BlockPos finalPos = pos;
|
|
||||||
|
|
||||||
if (!state.canBeReplaced(new BlockPlaceContext(context)))
|
|
||||||
{
|
|
||||||
finalPos = pos.relative(facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = getEntity(stack, level);
|
|
||||||
if (entity != null)
|
|
||||||
{
|
|
||||||
if (!level.isClientSide)
|
|
||||||
{
|
|
||||||
entity.absMoveTo(finalPos.getX() + 0.5, finalPos.getY(), finalPos.getZ() + 0.5, 180 + player.yHeadRot, 0.0f);
|
|
||||||
level.addFreshEntity(entity);
|
|
||||||
if (entity instanceof Mob)
|
|
||||||
{
|
|
||||||
((Mob) entity).playAmbientSound();
|
|
||||||
}
|
|
||||||
clearEntityData(stack);
|
|
||||||
player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
|
|
||||||
ItemEvents.sendPacket(player, 9, 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
player.getPersistentData().remove("overrideKey");
|
|
||||||
return InteractionResult.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return InteractionResult.FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int itemSlot, boolean isSelected)
|
|
||||||
{
|
|
||||||
if (hasEntityData(stack))
|
|
||||||
{
|
|
||||||
if (getEntity(stack, level) == null)
|
|
||||||
stack = ItemStack.EMPTY;
|
|
||||||
|
|
||||||
if (entity instanceof LivingEntity)
|
|
||||||
{
|
|
||||||
if (entity instanceof Player && Settings.slownessInCreative.get() ? false : ((Player) entity).isCreative())
|
|
||||||
return;
|
|
||||||
|
|
||||||
((LivingEntity) entity).addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 1, this.potionLevel(stack, level), false, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stack = ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearEntityData(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
tag.remove(ENTITY_DATA_KEY);
|
|
||||||
tag.remove("entity");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CompoundTag getPersistentData(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
return tag.getCompound(ENTITY_DATA_KEY);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Entity getEntity(ItemStack stack, Level level)
|
|
||||||
{
|
|
||||||
if (level == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
String name = getEntityName(stack);
|
|
||||||
|
|
||||||
CompoundTag e = getPersistentData(stack);
|
|
||||||
Optional<EntityType<?>> type = EntityType.byString(name);
|
|
||||||
Entity entity = null;
|
|
||||||
|
|
||||||
if (type.isPresent())
|
|
||||||
{
|
|
||||||
entity = type.get().create(level);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (entity instanceof Mob)
|
|
||||||
initGoals.invoke(entity);
|
|
||||||
entity.deserializeNBT(e);
|
|
||||||
}
|
|
||||||
catch (Exception e1)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
entity.deserializeNBT(e);
|
|
||||||
}
|
|
||||||
catch (Exception e2)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getEntityName(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
return tag.getString("entity");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getCustomName(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
if (tag.contains("CustomName") && !tag.getString("CustomName").isEmpty())
|
|
||||||
{
|
|
||||||
return tag.toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return tag.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityType<?> getEntityType(ItemStack stack)
|
|
||||||
{
|
|
||||||
if (stack.hasTag())
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
String name = tag.getString("entity");
|
|
||||||
Optional<EntityType<?>> type = EntityType.byString(name);
|
|
||||||
if (type.isPresent())
|
|
||||||
return type.get();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int potionLevel(ItemStack stack, Level level)
|
|
||||||
{
|
|
||||||
Entity e = getEntity(stack, level);
|
|
||||||
if (e == null)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
int i = (int) (e.getBbHeight() * e.getBbWidth());
|
|
||||||
if (i > 4)
|
|
||||||
i = 4;
|
|
||||||
|
|
||||||
if (!Settings.heavyEntities.get())
|
|
||||||
i = 1;
|
|
||||||
|
|
||||||
double multiplier = Settings.entitySlownessMultiplier.get();
|
|
||||||
|
|
||||||
return (int) (multiplier * i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,767 +0,0 @@
|
||||||
package tschipp.carryon.common.scripting;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.TagParser;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import tschipp.carryon.common.helper.InvalidConfigException;
|
|
||||||
|
|
||||||
public class CarryOnOverride
|
|
||||||
{
|
|
||||||
// BLOCKS
|
|
||||||
private CompoundTag typeBlockTag = new CompoundTag();
|
|
||||||
private String typeNameBlock = "";
|
|
||||||
private String typeMaterial = "";
|
|
||||||
private String typeHardness = "";
|
|
||||||
private String typeResistance = "";
|
|
||||||
|
|
||||||
// ENTITIES
|
|
||||||
private CompoundTag typeEntityTag;
|
|
||||||
private String typeNameEntity = "";
|
|
||||||
private String typeHeight = "";
|
|
||||||
private String typeWidth = "";
|
|
||||||
private String typeHealth = "";
|
|
||||||
|
|
||||||
// CONDITIONS
|
|
||||||
private String conditionGamestage = "";
|
|
||||||
private String conditionAchievement = "";
|
|
||||||
private String conditionXp = "";
|
|
||||||
private String conditionGamemode = "";
|
|
||||||
private String conditionScoreboard = "";
|
|
||||||
private String conditionPosition = "";
|
|
||||||
private String conditionEffects = "";
|
|
||||||
|
|
||||||
// RENDER
|
|
||||||
private String renderNameBlock = "";
|
|
||||||
private String renderNameEntity = "";
|
|
||||||
private CompoundTag renderNBT = new CompoundTag();
|
|
||||||
private String renderTranslation = "";
|
|
||||||
private String renderRotation = "";
|
|
||||||
private String renderscaled = "";
|
|
||||||
private String renderRotationLeftArm = "";
|
|
||||||
private String renderRotationRightArm = "";
|
|
||||||
private boolean renderLeftArm = true;
|
|
||||||
private boolean renderRightArm = true;
|
|
||||||
|
|
||||||
// EFFECTS
|
|
||||||
private String commandInit = "";
|
|
||||||
private String commandLoop = "";
|
|
||||||
private String commandPlace = "";
|
|
||||||
|
|
||||||
private boolean isBlock;
|
|
||||||
private boolean isEntity;
|
|
||||||
private String resourceLocation = "";
|
|
||||||
public boolean isInvalid = false;
|
|
||||||
|
|
||||||
public CarryOnOverride(String path)
|
|
||||||
{
|
|
||||||
this.resourceLocation = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CarryOnOverride(JsonElement jsonElem, ResourceLocation loc)
|
|
||||||
{
|
|
||||||
boolean errored = false;
|
|
||||||
this.resourceLocation = loc.toString();
|
|
||||||
|
|
||||||
if (jsonElem != null && jsonElem.isJsonObject())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JsonObject json = jsonElem.getAsJsonObject();
|
|
||||||
JsonObject object = (JsonObject) json.get("object");
|
|
||||||
JsonObject conditions = (JsonObject) json.get("conditions");
|
|
||||||
JsonObject render = (JsonObject) json.get("render");
|
|
||||||
JsonObject effects = (JsonObject) json.get("effects");
|
|
||||||
|
|
||||||
if (object != null && (conditions != null || render != null || effects != null))
|
|
||||||
{
|
|
||||||
JsonObject block = (JsonObject) object.get("block");
|
|
||||||
JsonObject entity = (JsonObject) object.get("entity");
|
|
||||||
|
|
||||||
if (block == null && entity == null || block != null && entity != null)
|
|
||||||
errored = true;
|
|
||||||
|
|
||||||
if (!errored)
|
|
||||||
{
|
|
||||||
if (block != null)
|
|
||||||
{
|
|
||||||
this.setBlock(true);
|
|
||||||
JsonElement name = block.get("name");
|
|
||||||
JsonElement material = block.get("material");
|
|
||||||
JsonElement hardness = block.get("hardness");
|
|
||||||
JsonElement resistance = block.get("resistance");
|
|
||||||
JsonObject nbt = (JsonObject) block.get("nbt");
|
|
||||||
|
|
||||||
if (name != null)
|
|
||||||
this.setTypeNameBlock(name.getAsString());
|
|
||||||
if (material != null)
|
|
||||||
this.setTypeMaterial(material.getAsString());
|
|
||||||
if (hardness != null)
|
|
||||||
this.setTypeHardness(hardness.getAsString());
|
|
||||||
if (resistance != null)
|
|
||||||
this.setTypeResistance(resistance.getAsString());
|
|
||||||
if (nbt != null)
|
|
||||||
this.setTypeBlockTag(TagParser.parseTag(nbt.toString()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.setEntity(true);
|
|
||||||
JsonElement name = entity.get("name");
|
|
||||||
JsonElement health = entity.get("health");
|
|
||||||
JsonElement height = entity.get("height");
|
|
||||||
JsonElement width = entity.get("width");
|
|
||||||
JsonObject nbt = (JsonObject) entity.get("nbt");
|
|
||||||
|
|
||||||
if (name != null)
|
|
||||||
this.setTypeNameEntity(name.getAsString());
|
|
||||||
if (health != null)
|
|
||||||
this.setTypeHealth(health.getAsString());
|
|
||||||
if (height != null)
|
|
||||||
this.setTypeHeight(height.getAsString());
|
|
||||||
if (width != null)
|
|
||||||
this.setTypeWidth(width.getAsString());
|
|
||||||
if (nbt != null)
|
|
||||||
this.setTypeEntityTag(TagParser.parseTag(nbt.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conditions != null)
|
|
||||||
{
|
|
||||||
JsonElement gamestage = conditions.get("gamestage");
|
|
||||||
JsonElement achievement = conditions.get("advancement");
|
|
||||||
JsonElement xp = conditions.get("xp");
|
|
||||||
JsonElement gamemode = conditions.get("gamemode");
|
|
||||||
JsonElement scoreboard = conditions.get("scoreboard");
|
|
||||||
JsonElement position = conditions.get("position");
|
|
||||||
JsonElement potionEffects = conditions.get("effects");
|
|
||||||
|
|
||||||
if (gamestage != null)
|
|
||||||
this.setConditionGamestage(gamestage.getAsString());
|
|
||||||
if (achievement != null)
|
|
||||||
this.setConditionAchievement(achievement.getAsString());
|
|
||||||
if (xp != null)
|
|
||||||
this.setConditionXp(xp.getAsString());
|
|
||||||
if (gamemode != null)
|
|
||||||
this.setConditionGamemode(gamemode.getAsString());
|
|
||||||
if (scoreboard != null)
|
|
||||||
this.setConditionScoreboard(scoreboard.getAsString());
|
|
||||||
if (position != null)
|
|
||||||
this.setConditionPosition(position.getAsString());
|
|
||||||
if (potionEffects != null)
|
|
||||||
this.setConditionEffects(potionEffects.getAsString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (render != null)
|
|
||||||
{
|
|
||||||
JsonElement name_block = render.get("name_block");
|
|
||||||
JsonElement name_entity = render.get("name_entity");
|
|
||||||
JsonObject nbt = (JsonObject) render.get("nbt");
|
|
||||||
JsonElement translation = render.get("translation");
|
|
||||||
JsonElement rotation = render.get("rotation");
|
|
||||||
JsonElement scaled = render.get("scale");
|
|
||||||
JsonElement rotationLeftArm = render.get("rotation_left_arm");
|
|
||||||
JsonElement rotationRightArm = render.get("rotation_right_arm");
|
|
||||||
JsonElement renderLeftArm = render.get("render_left_arm");
|
|
||||||
JsonElement renderRightArm = render.get("render_right_arm");
|
|
||||||
|
|
||||||
if (name_block != null)
|
|
||||||
this.setRenderNameBlock(name_block.getAsString());
|
|
||||||
if (name_entity != null)
|
|
||||||
this.setRenderNameEntity(name_entity.getAsString());
|
|
||||||
if (translation != null)
|
|
||||||
this.setRenderTranslation(translation.getAsString());
|
|
||||||
if (rotation != null)
|
|
||||||
this.setRenderRotation(rotation.getAsString());
|
|
||||||
if (scaled != null)
|
|
||||||
this.setRenderscaled(scaled.getAsString());
|
|
||||||
if (nbt != null)
|
|
||||||
this.setRenderNBT(TagParser.parseTag(nbt.toString()));
|
|
||||||
if (rotationLeftArm != null)
|
|
||||||
this.setRenderRotationLeftArm(rotationLeftArm.getAsString());
|
|
||||||
if (rotationRightArm != null)
|
|
||||||
this.setRenderRotationRightArm(rotationRightArm.getAsString());
|
|
||||||
if (renderLeftArm != null)
|
|
||||||
this.setRenderLeftArm(renderLeftArm.getAsBoolean());
|
|
||||||
if (renderRightArm != null)
|
|
||||||
this.setRenderRightArm(renderRightArm.getAsBoolean());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (effects != null)
|
|
||||||
{
|
|
||||||
JsonElement commandInit = effects.get("commandPickup");
|
|
||||||
JsonElement commandLoop = effects.get("commandLoop");
|
|
||||||
JsonElement commandPlace = effects.get("commandPlace");
|
|
||||||
|
|
||||||
if (commandInit != null)
|
|
||||||
this.setCommandInit(commandInit.getAsString());
|
|
||||||
if (commandLoop != null)
|
|
||||||
this.setCommandLoop(commandLoop.getAsString());
|
|
||||||
if (commandPlace != null)
|
|
||||||
this.setCommandPlace(commandPlace.getAsString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this.isInvalid = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
this.isInvalid = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this.isInvalid = true;
|
|
||||||
|
|
||||||
if (!this.isBlock && !this.isEntity)
|
|
||||||
this.isInvalid = true;
|
|
||||||
|
|
||||||
if (this.isInvalid)
|
|
||||||
new InvalidConfigException("The script parsing for " + this.resourceLocation + " has failed! Please double check!").printException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommandInit()
|
|
||||||
{
|
|
||||||
return this.commandInit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommandInit(String commandInit)
|
|
||||||
{
|
|
||||||
this.commandInit = commandInit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommandLoop()
|
|
||||||
{
|
|
||||||
return this.commandLoop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommandLoop(String commandLoop)
|
|
||||||
{
|
|
||||||
this.commandLoop = commandLoop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConditionEffects()
|
|
||||||
{
|
|
||||||
return this.conditionEffects;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditionEffects(String conditionEffects)
|
|
||||||
{
|
|
||||||
this.conditionEffects = conditionEffects;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRenderRotationLeftArm()
|
|
||||||
{
|
|
||||||
return this.renderRotationLeftArm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderRotationLeftArm(String renderRotationLeftArm)
|
|
||||||
{
|
|
||||||
this.renderRotationLeftArm = renderRotationLeftArm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRenderRotationRightArm()
|
|
||||||
{
|
|
||||||
return this.renderRotationRightArm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderRotationRightArm(String renderRotationRightArm)
|
|
||||||
{
|
|
||||||
this.renderRotationRightArm = renderRotationRightArm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRenderLeftArm()
|
|
||||||
{
|
|
||||||
return this.renderLeftArm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderLeftArm(boolean renderLeftArm)
|
|
||||||
{
|
|
||||||
this.renderLeftArm = renderLeftArm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRenderRightArm()
|
|
||||||
{
|
|
||||||
return this.renderRightArm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderRightArm(boolean renderRightArm)
|
|
||||||
{
|
|
||||||
this.renderRightArm = renderRightArm;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
return prime * result + (this.resourceLocation == null ? 0 : this.resourceLocation.hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "Code: " + this.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj)
|
|
||||||
{
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null || this.getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
CarryOnOverride other = (CarryOnOverride) obj;
|
|
||||||
if (!Objects.equals(this.commandInit, other.commandInit) || !Objects.equals(this.commandLoop, other.commandLoop) || !Objects.equals(this.commandPlace, other.commandPlace) || !Objects.equals(this.conditionAchievement, other.conditionAchievement))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.conditionEffects, other.conditionEffects) || !Objects.equals(this.conditionGamemode, other.conditionGamemode) || !Objects.equals(this.conditionGamestage, other.conditionGamestage) || !Objects.equals(this.conditionPosition, other.conditionPosition))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.conditionScoreboard, other.conditionScoreboard))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.conditionXp, other.conditionXp))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.isBlock != other.isBlock)
|
|
||||||
return false;
|
|
||||||
if (this.isEntity != other.isEntity)
|
|
||||||
return false;
|
|
||||||
if (!Objects.equals(this.resourceLocation, other.resourceLocation))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.renderLeftArm != other.renderLeftArm)
|
|
||||||
return false;
|
|
||||||
if (!Objects.equals(this.renderNBT, other.renderNBT))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.renderNameBlock, other.renderNameBlock))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.renderNameEntity, other.renderNameEntity))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.renderRightArm != other.renderRightArm)
|
|
||||||
return false;
|
|
||||||
if (!Objects.equals(this.renderRotation, other.renderRotation))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.renderRotationLeftArm, other.renderRotationLeftArm))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.renderRotationRightArm, other.renderRotationRightArm))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.renderscaled, other.renderscaled))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.renderTranslation, other.renderTranslation))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeBlockTag, other.typeBlockTag))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeEntityTag, other.typeEntityTag))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeHardness, other.typeHardness))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeHealth, other.typeHealth))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeHeight, other.typeHeight))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeMaterial, other.typeMaterial))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeNameBlock, other.typeNameBlock))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeNameEntity, other.typeNameEntity))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeResistance, other.typeResistance))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(this.typeWidth, other.typeWidth))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBlock()
|
|
||||||
{
|
|
||||||
return this.isBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlock(boolean isBlock)
|
|
||||||
{
|
|
||||||
this.isBlock = isBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEntity()
|
|
||||||
{
|
|
||||||
return this.isEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEntity(boolean isEntity)
|
|
||||||
{
|
|
||||||
this.isEntity = isEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompoundTag getTypeBlockTag()
|
|
||||||
{
|
|
||||||
return this.typeBlockTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeNameBlock()
|
|
||||||
{
|
|
||||||
return this.typeNameBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeMaterial()
|
|
||||||
{
|
|
||||||
return this.typeMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeHardness()
|
|
||||||
{
|
|
||||||
return this.typeHardness;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeResistance()
|
|
||||||
{
|
|
||||||
return this.typeResistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompoundTag getTypeEntityTag()
|
|
||||||
{
|
|
||||||
return this.typeEntityTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeNameEntity()
|
|
||||||
{
|
|
||||||
return this.typeNameEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeHeight()
|
|
||||||
{
|
|
||||||
return this.typeHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeWidth()
|
|
||||||
{
|
|
||||||
return this.typeWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeHealth()
|
|
||||||
{
|
|
||||||
return this.typeHealth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConditionGamestage()
|
|
||||||
{
|
|
||||||
return this.conditionGamestage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConditionAchievement()
|
|
||||||
{
|
|
||||||
return this.conditionAchievement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConditionXp()
|
|
||||||
{
|
|
||||||
return this.conditionXp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConditionGamemode()
|
|
||||||
{
|
|
||||||
return this.conditionGamemode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConditionScoreboard()
|
|
||||||
{
|
|
||||||
return this.conditionScoreboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConditionPosition()
|
|
||||||
{
|
|
||||||
return this.conditionPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRenderNameBlock()
|
|
||||||
{
|
|
||||||
return this.renderNameBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRenderNameEntity()
|
|
||||||
{
|
|
||||||
return this.renderNameEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompoundTag getRenderNBT()
|
|
||||||
{
|
|
||||||
return this.renderNBT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRenderTranslation()
|
|
||||||
{
|
|
||||||
return this.renderTranslation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRenderRotation()
|
|
||||||
{
|
|
||||||
return this.renderRotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRenderScaled()
|
|
||||||
{
|
|
||||||
return this.renderscaled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeBlockTag(CompoundTag typeBlockTag)
|
|
||||||
{
|
|
||||||
this.typeBlockTag = typeBlockTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeNameBlock(String typeNameBlock)
|
|
||||||
{
|
|
||||||
this.typeNameBlock = typeNameBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeMaterial(String typeMaterial)
|
|
||||||
{
|
|
||||||
this.typeMaterial = typeMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeHardness(String typeHardness)
|
|
||||||
{
|
|
||||||
this.typeHardness = typeHardness;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeResistance(String typeResistance)
|
|
||||||
{
|
|
||||||
this.typeResistance = typeResistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeEntityTag(CompoundTag typeEntityTag)
|
|
||||||
{
|
|
||||||
this.typeEntityTag = typeEntityTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeNameEntity(String typeNameEntity)
|
|
||||||
{
|
|
||||||
this.typeNameEntity = typeNameEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeHeight(String typeHeight)
|
|
||||||
{
|
|
||||||
this.typeHeight = typeHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeWidth(String typeWidth)
|
|
||||||
{
|
|
||||||
this.typeWidth = typeWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeHealth(String typeHealth)
|
|
||||||
{
|
|
||||||
this.typeHealth = typeHealth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditionGamestage(String conditionGamestage)
|
|
||||||
{
|
|
||||||
this.conditionGamestage = conditionGamestage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditionAchievement(String conditionAchievement)
|
|
||||||
{
|
|
||||||
this.conditionAchievement = conditionAchievement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditionXp(String conditionXp)
|
|
||||||
{
|
|
||||||
this.conditionXp = conditionXp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditionGamemode(String conditionGamemode)
|
|
||||||
{
|
|
||||||
this.conditionGamemode = conditionGamemode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditionScoreboard(String conditionScoreboard)
|
|
||||||
{
|
|
||||||
this.conditionScoreboard = conditionScoreboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditionPosition(String conditionPosition)
|
|
||||||
{
|
|
||||||
this.conditionPosition = conditionPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderNameBlock(String renderNameBlock)
|
|
||||||
{
|
|
||||||
this.renderNameBlock = renderNameBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderNameEntity(String renderNameEntity)
|
|
||||||
{
|
|
||||||
this.renderNameEntity = renderNameEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderNBT(CompoundTag renderNBT)
|
|
||||||
{
|
|
||||||
this.renderNBT = renderNBT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderTranslation(String renderTranslation)
|
|
||||||
{
|
|
||||||
this.renderTranslation = renderTranslation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderRotation(String renderRotation)
|
|
||||||
{
|
|
||||||
this.renderRotation = renderRotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRenderscaled(String renderscaled)
|
|
||||||
{
|
|
||||||
this.renderscaled = renderscaled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommandPlace()
|
|
||||||
{
|
|
||||||
return this.commandPlace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommandPlace(String commandPlace)
|
|
||||||
{
|
|
||||||
this.commandPlace = commandPlace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void serialize(FriendlyByteBuf buf)
|
|
||||||
{
|
|
||||||
// BLOCKS
|
|
||||||
buf.writeNbt(this.typeBlockTag);
|
|
||||||
buf.writeUtf(this.typeNameBlock);
|
|
||||||
buf.writeUtf(this.typeMaterial);
|
|
||||||
buf.writeUtf(this.typeHardness);
|
|
||||||
buf.writeUtf(this.typeResistance);
|
|
||||||
|
|
||||||
// ENTITIES
|
|
||||||
buf.writeNbt(this.typeEntityTag);
|
|
||||||
buf.writeUtf(this.typeNameEntity);
|
|
||||||
buf.writeUtf(this.typeHeight);
|
|
||||||
buf.writeUtf(this.typeWidth);
|
|
||||||
buf.writeUtf(this.typeHealth);
|
|
||||||
|
|
||||||
// CONDITIONS
|
|
||||||
buf.writeUtf(this.conditionGamestage);
|
|
||||||
buf.writeUtf(this.conditionAchievement);
|
|
||||||
buf.writeUtf(this.conditionXp);
|
|
||||||
buf.writeUtf(this.conditionGamemode);
|
|
||||||
buf.writeUtf(this.conditionScoreboard);
|
|
||||||
buf.writeUtf(this.conditionPosition);
|
|
||||||
buf.writeUtf(this.conditionEffects);
|
|
||||||
|
|
||||||
// RENDER
|
|
||||||
buf.writeUtf(this.renderNameBlock);
|
|
||||||
buf.writeUtf(this.renderNameEntity);
|
|
||||||
buf.writeNbt(this.renderNBT);
|
|
||||||
buf.writeUtf(this.renderTranslation);
|
|
||||||
buf.writeUtf(this.renderRotation);
|
|
||||||
buf.writeUtf(this.renderscaled);
|
|
||||||
buf.writeUtf(this.renderRotationLeftArm);
|
|
||||||
buf.writeUtf(this.renderRotationRightArm);
|
|
||||||
buf.writeBoolean(this.renderLeftArm);
|
|
||||||
buf.writeBoolean(this.renderRightArm);
|
|
||||||
|
|
||||||
// EFFECTS
|
|
||||||
buf.writeUtf(this.commandInit);
|
|
||||||
buf.writeUtf(this.commandLoop);
|
|
||||||
buf.writeUtf(this.commandPlace);
|
|
||||||
|
|
||||||
buf.writeBoolean(this.isBlock);
|
|
||||||
buf.writeBoolean(this.isEntity);
|
|
||||||
buf.writeUtf(this.resourceLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CarryOnOverride deserialize(FriendlyByteBuf buf)
|
|
||||||
{
|
|
||||||
CarryOnOverride override = new CarryOnOverride("");
|
|
||||||
override.typeBlockTag = buf.readNbt();
|
|
||||||
override.typeNameBlock = buf.readUtf();
|
|
||||||
override.typeMaterial = buf.readUtf();
|
|
||||||
override.typeHardness = buf.readUtf();
|
|
||||||
override.typeResistance = buf.readUtf();
|
|
||||||
|
|
||||||
// ENTITIES
|
|
||||||
override.typeEntityTag = buf.readNbt();
|
|
||||||
override.typeNameEntity = buf.readUtf();
|
|
||||||
override.typeHeight = buf.readUtf();
|
|
||||||
override.typeWidth = buf.readUtf();
|
|
||||||
override.typeHealth = buf.readUtf();
|
|
||||||
|
|
||||||
// CONDITIONS
|
|
||||||
override.conditionGamestage = buf.readUtf();
|
|
||||||
override.conditionAchievement = buf.readUtf();
|
|
||||||
override.conditionXp = buf.readUtf();
|
|
||||||
override.conditionGamemode = buf.readUtf();
|
|
||||||
override.conditionScoreboard = buf.readUtf();
|
|
||||||
override.conditionPosition = buf.readUtf();
|
|
||||||
override.conditionEffects = buf.readUtf();
|
|
||||||
|
|
||||||
// RENDER
|
|
||||||
override.renderNameBlock = buf.readUtf();
|
|
||||||
override.renderNameEntity = buf.readUtf();
|
|
||||||
override.renderNBT = buf.readNbt();
|
|
||||||
override.renderTranslation = buf.readUtf();
|
|
||||||
override.renderRotation = buf.readUtf();
|
|
||||||
override.renderscaled = buf.readUtf();
|
|
||||||
override.renderRotationLeftArm = buf.readUtf();
|
|
||||||
override.renderRotationRightArm = buf.readUtf();
|
|
||||||
override.renderLeftArm = buf.readBoolean();
|
|
||||||
override.renderRightArm = buf.readBoolean();
|
|
||||||
|
|
||||||
// EFFECTS
|
|
||||||
override.commandInit = buf.readUtf();
|
|
||||||
override.commandLoop = buf.readUtf();
|
|
||||||
override.commandPlace = buf.readUtf();
|
|
||||||
|
|
||||||
override.isBlock = buf.readBoolean();
|
|
||||||
override.isEntity = buf.readBoolean();
|
|
||||||
override.resourceLocation = buf.readUtf();
|
|
||||||
|
|
||||||
return override;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,179 +0,0 @@
|
||||||
package tschipp.carryon.common.scripting;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import net.minecraft.advancements.Advancement;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.ServerAdvancementManager;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.level.material.Material;
|
|
||||||
import net.minecraftforge.fml.ModList;
|
|
||||||
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import tschipp.carryon.common.config.Configs.Settings;
|
|
||||||
import tschipp.carryon.common.handler.ListHandler;
|
|
||||||
import tschipp.carryon.common.helper.ScriptParseHelper;
|
|
||||||
|
|
||||||
public class ScriptChecker
|
|
||||||
{
|
|
||||||
@Nullable
|
|
||||||
public static CarryOnOverride inspectBlock(BlockState state, Level level, BlockPos pos, @Nullable CompoundTag tag)
|
|
||||||
{
|
|
||||||
if (!Settings.useScripts.get())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
Block block = state.getBlock();
|
|
||||||
Material material = state.getMaterial();
|
|
||||||
float hardness = state.getDestroySpeed(level, pos);
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
float resistance = block.getExplosionResistance();
|
|
||||||
CompoundTag nbt = tag;
|
|
||||||
|
|
||||||
boolean isAllowed = Settings.useWhitelistBlocks.get() ? ListHandler.isAllowed(block) : !ListHandler.isForbidden(block);
|
|
||||||
|
|
||||||
if (isAllowed)
|
|
||||||
{
|
|
||||||
for (CarryOnOverride override : ScriptReader.OVERRIDES.values())
|
|
||||||
{
|
|
||||||
if (override.isBlock() && matchesAll(override, block, material, hardness, resistance, nbt))
|
|
||||||
return override;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static CarryOnOverride inspectEntity(Entity entity)
|
|
||||||
{
|
|
||||||
if (!Settings.useScripts.get())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
String name = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()).toString();
|
|
||||||
float height = entity.getBbHeight();
|
|
||||||
float width = entity.getBbWidth();
|
|
||||||
float health = entity instanceof LivingEntity ? ((LivingEntity) entity).getHealth() : 0.0f;
|
|
||||||
CompoundTag tag = entity.serializeNBT();
|
|
||||||
|
|
||||||
boolean isAllowed = Settings.useWhitelistEntities.get() ? ListHandler.isAllowed(entity) : !ListHandler.isForbidden(entity);
|
|
||||||
|
|
||||||
if (isAllowed)
|
|
||||||
{
|
|
||||||
for (CarryOnOverride override : ScriptReader.OVERRIDES.values())
|
|
||||||
{
|
|
||||||
if (override.isEntity() && matchesAll(override, name, height, width, health, tag))
|
|
||||||
return override;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matchesAll(CarryOnOverride override, String name, float height, float width, float health, CompoundTag tag)
|
|
||||||
{
|
|
||||||
boolean matchname = override.getTypeNameEntity().isEmpty() ? true : name.equals(override.getTypeNameEntity());
|
|
||||||
boolean matchheight = ScriptParseHelper.matches(height, override.getTypeHeight());
|
|
||||||
boolean matchwidth = ScriptParseHelper.matches(width, override.getTypeWidth());
|
|
||||||
boolean matchhealth = ScriptParseHelper.matches(health, override.getTypeHealth());
|
|
||||||
boolean matchnbt = ScriptParseHelper.matches(tag, override.getTypeEntityTag());
|
|
||||||
|
|
||||||
return matchname && matchheight && matchwidth && matchhealth && matchnbt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matchesAll(CarryOnOverride override, Block block, Material material, float hardness, float resistance, CompoundTag nbt)
|
|
||||||
{
|
|
||||||
boolean matchnbt = ScriptParseHelper.matches(nbt, override.getTypeBlockTag());
|
|
||||||
boolean matchblock = ScriptParseHelper.matches(block, override.getTypeNameBlock());
|
|
||||||
boolean matchmaterial = ScriptParseHelper.matches(material, override.getTypeMaterial());
|
|
||||||
boolean matchhardness = ScriptParseHelper.matches(hardness, override.getTypeHardness());
|
|
||||||
boolean matchresistance = ScriptParseHelper.matches(resistance, override.getTypeResistance());
|
|
||||||
|
|
||||||
return matchnbt && matchblock && matchmaterial && matchhardness && matchresistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean fulfillsConditions(CarryOnOverride override, Player player)
|
|
||||||
{
|
|
||||||
ServerAdvancementManager manager = ((ServerPlayer) player).server.getAdvancements();
|
|
||||||
Advancement adv = manager.getAdvancement(new ResourceLocation(override.getConditionAchievement().isEmpty() ? "" : override.getConditionAchievement()));
|
|
||||||
|
|
||||||
boolean achievement = adv == null ? true : ((ServerPlayer) player).getAdvancements().getOrStartProgress(adv).isDone();
|
|
||||||
boolean gamemode = ScriptParseHelper.matches(((ServerPlayer) player).gameMode.getGameModeForPlayer().getId(), override.getConditionGamemode());
|
|
||||||
boolean gamestage = true;
|
|
||||||
if (ModList.get().isLoaded("gamestages") && !override.getConditionGamestage().isEmpty())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class<?> gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper");
|
|
||||||
Class<?> iStageData = Class.forName("net.darkhax.gamestages.data.IStageData");
|
|
||||||
|
|
||||||
Method getPlayerData = ObfuscationReflectionHelper.findMethod(gameStageHelper, "getPlayerData", Player.class);
|
|
||||||
Method hasStage = ObfuscationReflectionHelper.findMethod(iStageData, "hasStage", String.class);
|
|
||||||
|
|
||||||
Object stageData = getPlayerData.invoke(null, player);
|
|
||||||
String condition = override.getConditionGamestage();
|
|
||||||
gamestage = (boolean) hasStage.invoke(stageData, condition);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class<?> playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler");
|
|
||||||
Class<?> iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData");
|
|
||||||
|
|
||||||
Method getStageData = ObfuscationReflectionHelper.findMethod(playerDataHandler, "getStageData", Player.class);
|
|
||||||
Method hasUnlockedStage = ObfuscationReflectionHelper.findMethod(iStageData, "hasUnlockedStage", String.class);
|
|
||||||
|
|
||||||
Object stageData = getStageData.invoke(null, player);
|
|
||||||
String condition = override.getConditionGamestage();
|
|
||||||
gamestage = (boolean) hasUnlockedStage.invoke(stageData, condition);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean position = ScriptParseHelper.matches(player.blockPosition(), override.getConditionPosition());
|
|
||||||
boolean xp = ScriptParseHelper.matches(player.experienceLevel, override.getConditionXp());
|
|
||||||
boolean scoreboard = ScriptParseHelper.matchesScore(player, override.getConditionScoreboard());
|
|
||||||
boolean effects = ScriptParseHelper.hasEffects(player, override.getConditionEffects());
|
|
||||||
|
|
||||||
return achievement && gamemode && gamestage && position && xp && scoreboard && effects;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static CarryOnOverride getOverride(Player player)
|
|
||||||
{
|
|
||||||
CompoundTag tag = player.getPersistentData();
|
|
||||||
|
|
||||||
if (tag != null && tag.contains("overrideKey"))
|
|
||||||
{
|
|
||||||
int key = tag.getInt("overrideKey");
|
|
||||||
|
|
||||||
return ScriptReader.OVERRIDES.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setCarryOnOverride(Player player, int i)
|
|
||||||
{
|
|
||||||
CompoundTag tag = player.getPersistentData();
|
|
||||||
|
|
||||||
if (tag != null)
|
|
||||||
tag.putInt("overrideKey", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,191 +0,0 @@
|
||||||
package tschipp.carryon.common.scripting;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class ScriptReader
|
|
||||||
{
|
|
||||||
public static HashMap<Integer, CarryOnOverride> OVERRIDES = new HashMap<>();
|
|
||||||
|
|
||||||
// public static HashSet<CarryOnOverride> OVERRIDES = new
|
|
||||||
// HashSet<CarryOnOverride>();
|
|
||||||
|
|
||||||
// public static void preInit()
|
|
||||||
// {
|
|
||||||
// scripts.clear();
|
|
||||||
//
|
|
||||||
// CarryOn.CONFIGURATION_FILE = new
|
|
||||||
// File(FMLPaths.CONFIGDIR.get().toString(), "/carryon-scripts/");
|
|
||||||
//
|
|
||||||
// if (!CarryOn.CONFIGURATION_FILE.exists())
|
|
||||||
// CarryOn.CONFIGURATION_FILE.mkdir();
|
|
||||||
//
|
|
||||||
// for (File file : CarryOn.CONFIGURATION_FILE.listFiles())
|
|
||||||
// {
|
|
||||||
// if (file.getName().endsWith(".json"))
|
|
||||||
// scripts.add(file);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static void parseScripts()
|
|
||||||
// {
|
|
||||||
// OVERRIDES.clear();
|
|
||||||
//
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// if (!Settings.useScripts.get())
|
|
||||||
// return;
|
|
||||||
//
|
|
||||||
// for (File file : scripts)
|
|
||||||
// {
|
|
||||||
// boolean errored = false;
|
|
||||||
// JsonParser parser = new JsonParser();
|
|
||||||
// JsonObject json = (JsonObject) parser.parse(new
|
|
||||||
// FileReader(file.getAbsolutePath()));
|
|
||||||
//
|
|
||||||
// JsonObject object = (JsonObject) json.get("object");
|
|
||||||
// JsonObject conditions = (JsonObject) json.get("conditions");
|
|
||||||
// JsonObject render = (JsonObject) json.get("render");
|
|
||||||
// JsonObject effects = (JsonObject) json.get("effects");
|
|
||||||
//
|
|
||||||
// if ((object != null && conditions != null) || (object != null && render
|
|
||||||
// != null) || (object != null && effects != null))
|
|
||||||
// {
|
|
||||||
// JsonObject block = (JsonObject) object.get("block");
|
|
||||||
// JsonObject entity = (JsonObject) object.get("entity");
|
|
||||||
//
|
|
||||||
// if ((block == null && entity == null) || (block != null && entity !=
|
|
||||||
// null))
|
|
||||||
// errored = true;
|
|
||||||
//
|
|
||||||
// if (!errored)
|
|
||||||
// {
|
|
||||||
// CarryOnOverride override = new CarryOnOverride(file.getAbsolutePath());
|
|
||||||
//
|
|
||||||
// if (block != null)
|
|
||||||
// {
|
|
||||||
// override.setBlock(true);
|
|
||||||
// JsonElement name = block.get("name");
|
|
||||||
// JsonElement material = block.get("material");
|
|
||||||
// JsonElement hardness = block.get("hardness");
|
|
||||||
// JsonElement resistance = block.get("resistance");
|
|
||||||
// JsonObject nbt = (JsonObject) block.get("nbt");
|
|
||||||
//
|
|
||||||
// if (name != null)
|
|
||||||
// override.setTypeNameBlock(name.getAsString());
|
|
||||||
// if (material != null)
|
|
||||||
// override.setTypeMaterial(material.getAsString());
|
|
||||||
// if (hardness != null)
|
|
||||||
// override.setTypeHardness(hardness.getAsString());
|
|
||||||
// if (resistance != null)
|
|
||||||
// override.setTypeResistance(resistance.getAsString());
|
|
||||||
// if (nbt != null)
|
|
||||||
// override.setTypeBlockTag(JsonToNBT.getTagFromJson(nbt.toString()));
|
|
||||||
// } else
|
|
||||||
// {
|
|
||||||
// override.setEntity(true);
|
|
||||||
// JsonElement name = entity.get("name");
|
|
||||||
// JsonElement health = entity.get("health");
|
|
||||||
// JsonElement height = entity.get("height");
|
|
||||||
// JsonElement width = entity.get("width");
|
|
||||||
// JsonObject nbt = (JsonObject) entity.get("nbt");
|
|
||||||
//
|
|
||||||
// if (name != null)
|
|
||||||
// override.setTypeNameEntity(name.getAsString());
|
|
||||||
// if (health != null)
|
|
||||||
// override.setTypeHealth(health.getAsString());
|
|
||||||
// if (height != null)
|
|
||||||
// override.setTypeHeight(height.getAsString());
|
|
||||||
// if (width != null)
|
|
||||||
// override.setTypeWidth(width.getAsString());
|
|
||||||
// if (nbt != null)
|
|
||||||
// override.setTypeEntityTag(JsonToNBT.getTagFromJson(nbt.toString()));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (conditions != null)
|
|
||||||
// {
|
|
||||||
// JsonElement gamestage = conditions.get("gamestage");
|
|
||||||
// JsonElement achievement = conditions.get("advancement");
|
|
||||||
// JsonElement xp = conditions.get("xp");
|
|
||||||
// JsonElement gamemode = conditions.get("gamemode");
|
|
||||||
// JsonElement scoreboard = conditions.get("scoreboard");
|
|
||||||
// JsonElement position = conditions.get("position");
|
|
||||||
// JsonElement potionEffects = conditions.get("effects");
|
|
||||||
//
|
|
||||||
// if (gamestage != null)
|
|
||||||
// override.setConditionGamestage(gamestage.getAsString());
|
|
||||||
// if (achievement != null)
|
|
||||||
// override.setConditionAchievement(achievement.getAsString());
|
|
||||||
// if (xp != null)
|
|
||||||
// override.setConditionXp(xp.getAsString());
|
|
||||||
// if (gamemode != null)
|
|
||||||
// override.setConditionGamemode(gamemode.getAsString());
|
|
||||||
// if (scoreboard != null)
|
|
||||||
// override.setConditionScoreboard(scoreboard.getAsString());
|
|
||||||
// if (position != null)
|
|
||||||
// override.setConditionPosition(position.getAsString());
|
|
||||||
// if (potionEffects != null)
|
|
||||||
// override.setConditionEffects(potionEffects.getAsString());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (render != null)
|
|
||||||
// {
|
|
||||||
// JsonElement name_block = render.get("name_block");
|
|
||||||
// JsonElement name_entity = render.get("name_entity");
|
|
||||||
// JsonObject nbt = (JsonObject) render.get("nbt");
|
|
||||||
// JsonElement translation = render.get("translation");
|
|
||||||
// JsonElement rotation = render.get("rotation");
|
|
||||||
// JsonElement scaled = render.get("scale");
|
|
||||||
// JsonElement rotationLeftArm = render.get("rotation_left_arm");
|
|
||||||
// JsonElement rotationRightArm = render.get("rotation_right_arm");
|
|
||||||
// JsonElement renderLeftArm = render.get("render_left_arm");
|
|
||||||
// JsonElement renderRightArm = render.get("render_right_arm");
|
|
||||||
//
|
|
||||||
// if (name_block != null)
|
|
||||||
// override.setRenderNameBlock(name_block.getAsString());
|
|
||||||
// if (name_entity != null)
|
|
||||||
// override.setRenderNameEntity(name_entity.getAsString());
|
|
||||||
// if (translation != null)
|
|
||||||
// override.setRenderTranslation(translation.getAsString());
|
|
||||||
// if (rotation != null)
|
|
||||||
// override.setRenderRotation(rotation.getAsString());
|
|
||||||
// if (scaled != null)
|
|
||||||
// override.setRenderscaled(scaled.getAsString());
|
|
||||||
// if (nbt != null)
|
|
||||||
// override.setRenderNBT(JsonToNBT.getTagFromJson(nbt.toString()));
|
|
||||||
// if (rotationLeftArm != null)
|
|
||||||
// override.setRenderRotationLeftArm(rotationLeftArm.getAsString());
|
|
||||||
// if (rotationRightArm != null)
|
|
||||||
// override.setRenderRotationRightArm(rotationRightArm.getAsString());
|
|
||||||
// if (renderLeftArm != null)
|
|
||||||
// override.setRenderLeftArm(renderLeftArm.getAsBoolean());
|
|
||||||
// if (renderRightArm != null)
|
|
||||||
// override.setRenderRightArm(renderRightArm.getAsBoolean());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (effects != null)
|
|
||||||
// {
|
|
||||||
// JsonElement commandInit = effects.get("commandPickup");
|
|
||||||
// JsonElement commandLoop = effects.get("commandLoop");
|
|
||||||
// JsonElement commandPlace = effects.get("commandPlace");
|
|
||||||
//
|
|
||||||
// if (commandInit != null)
|
|
||||||
// override.setCommandInit(commandInit.getAsString());
|
|
||||||
// if (commandLoop != null)
|
|
||||||
// override.setCommandLoop(commandLoop.getAsString());
|
|
||||||
// if (commandPlace != null)
|
|
||||||
// override.setCommandPlace(commandPlace.getAsString());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// OVERRIDES.put(override.hashCode(), override);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// System.out.println("Successfully parsed scripts!");
|
|
||||||
// } catch (Exception e)
|
|
||||||
// {
|
|
||||||
// CarryOn.LOGGER.error(e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
package tschipp.carryon.common.scripting;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.packs.resources.ResourceManager;
|
|
||||||
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
|
|
||||||
import net.minecraft.util.profiling.ProfilerFiller;
|
|
||||||
import net.minecraftforge.event.AddReloadListenerEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
|
||||||
import net.minecraftforge.fml.util.thread.EffectiveSide;
|
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
|
||||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.network.client.ScriptReloadPacket;
|
|
||||||
|
|
||||||
@EventBusSubscriber(modid = CarryOn.MODID, bus = Bus.FORGE)
|
|
||||||
public class ScriptReloadListener extends SimpleJsonResourceReloadListener
|
|
||||||
{
|
|
||||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
|
||||||
|
|
||||||
public ScriptReloadListener()
|
|
||||||
{
|
|
||||||
super(GSON, "carryon/scripts");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void apply(Map<ResourceLocation, JsonElement> objects, ResourceManager manager, ProfilerFiller profiler)
|
|
||||||
{
|
|
||||||
ScriptReader.OVERRIDES.clear();
|
|
||||||
|
|
||||||
objects.forEach((path, jsonElem) -> {
|
|
||||||
CarryOnOverride override = new CarryOnOverride(jsonElem, path);
|
|
||||||
if (!override.isInvalid)
|
|
||||||
ScriptReader.OVERRIDES.put(override.hashCode(), override);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (EffectiveSide.get().isServer() && ServerLifecycleHooks.getCurrentServer() != null)
|
|
||||||
{
|
|
||||||
CarryOn.network.send(PacketDistributor.ALL.noArg(), new ScriptReloadPacket(ScriptReader.OVERRIDES.values()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onDatapackRegister(AddReloadListenerEvent event)
|
|
||||||
{
|
|
||||||
event.addListener(new ScriptReloadListener());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
// package tschipp.carryon.compat.obfuscate;
|
|
||||||
//
|
|
||||||
// import com.mrcrayfish.obfuscate.client.event.PlayerModelEvent;
|
|
||||||
//
|
|
||||||
// import net.minecraft.client.model.PlayerModel;
|
|
||||||
// import net.minecraft.client.renderer.model.ModelRenderer;
|
|
||||||
// import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
// import net.minecraft.world.item.ItemStack;
|
|
||||||
// import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
// import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
// import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
// import tschipp.carryon.common.config.Configs.Settings;
|
|
||||||
// import tschipp.carryon.common.handler.RegistrationHandler;
|
|
||||||
// import tschipp.carryon.common.helper.ScriptParseHelper;
|
|
||||||
// import tschipp.carryon.common.item.ItemCarryonBlock;
|
|
||||||
// import tschipp.carryon.common.item.ItemCarryonEntity;
|
|
||||||
// import tschipp.carryon.common.scripting.CarryOnOverride;
|
|
||||||
// import tschipp.carryon.common.scripting.ScriptChecker;
|
|
||||||
//
|
|
||||||
// public class ObfuscateEvents
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// @SubscribeEvent
|
|
||||||
// public void preModelPlayerEvent(PlayerModelEvent.SetupAngles.Post event)
|
|
||||||
// {
|
|
||||||
// if(!Settings.renderArms.get())
|
|
||||||
// return;
|
|
||||||
//
|
|
||||||
// PlayerEntity player = event.getPlayer();
|
|
||||||
//
|
|
||||||
// Pose pose = player.getPose();
|
|
||||||
// if (pose == Pose.SWIMMING || pose == Pose.FALL_FLYING)
|
|
||||||
// return;
|
|
||||||
//
|
|
||||||
// PlayerModel<?> model = event.getModelPlayer();
|
|
||||||
// ItemStack stack = player.getMainHandItem();
|
|
||||||
// if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile.get() &&
|
|
||||||
// ItemCarryonBlock.hasTileData(stack) || stack.getItem() ==
|
|
||||||
// RegistrationHandler.itemEntity.get() && ItemCarryonEntity.hasEntityData(stack))
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// float rotation = 0;
|
|
||||||
//
|
|
||||||
// CarryOnOverride overrider = ScriptChecker.getOverride(player);
|
|
||||||
// if (overrider != null)
|
|
||||||
// {
|
|
||||||
// float[] rotLeft = null;
|
|
||||||
// float[] rotRight = null;
|
|
||||||
// if (overrider.getRenderRotationLeftArm() != null)
|
|
||||||
// rotLeft =
|
|
||||||
// ScriptParseHelper.getXYZArray(overrider.getRenderRotationLeftArm());
|
|
||||||
// if (overrider.getRenderRotationRightArm() != null)
|
|
||||||
// rotRight =
|
|
||||||
// ScriptParseHelper.getXYZArray(overrider.getRenderRotationRightArm());
|
|
||||||
//
|
|
||||||
// boolean renderRight = overrider.isRenderRightArm();
|
|
||||||
// boolean renderLeft = overrider.isRenderLeftArm();
|
|
||||||
//
|
|
||||||
// if (renderLeft && rotLeft != null)
|
|
||||||
// {
|
|
||||||
// renderArmPre(model.leftArm, (float) rotLeft[0], (float) rotLeft[2],
|
|
||||||
// rotation);
|
|
||||||
// renderArmPre(model.leftSleeve, (float) rotLeft[0], (float) rotLeft[2],
|
|
||||||
// rotation);
|
|
||||||
// }
|
|
||||||
// else if (renderLeft)
|
|
||||||
// {
|
|
||||||
// renderArmPre(model.leftArm, 0.8F + (player.isShiftKeyDown() ? 0.2f : 0f) -
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.2f : 0),
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.15f : 0), rotation);
|
|
||||||
// renderArmPre(model.leftSleeve, 0.8F + (player.isShiftKeyDown() ? 0.2f : 0f) -
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.2f : 0),
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.15f : 0), rotation);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (renderRight && rotRight != null)
|
|
||||||
// {
|
|
||||||
// renderArmPre(model.rightArm, (float) rotRight[0], (float) rotRight[2],
|
|
||||||
// rotation);
|
|
||||||
// renderArmPre(model.rightSleeve, (float) rotRight[0], (float) rotRight[2],
|
|
||||||
// rotation);
|
|
||||||
// }
|
|
||||||
// else if (renderRight)
|
|
||||||
// {
|
|
||||||
// renderArmPre(model.rightArm, 0.8F + (player.isShiftKeyDown() ? 0.2f : 0f) -
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.2f : 0),
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.15f : 0), rotation);
|
|
||||||
// renderArmPre(model.rightSleeve, 0.8F + (player.isShiftKeyDown() ? 0.2f : 0f)
|
|
||||||
// - (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.2f : 0),
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.15f : 0), rotation);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// renderArmPre(model.rightArm, 0.8F + (player.isShiftKeyDown() ? 0.2f : 0f) -
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.2f : 0),
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.15f : 0), rotation);
|
|
||||||
// renderArmPre(model.rightSleeve, 0.8F + (player.isShiftKeyDown() ? 0.2f : 0f)
|
|
||||||
// - (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.2f : 0),
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.15f : 0), rotation);
|
|
||||||
// renderArmPre(model.leftArm, 0.8F + (player.isShiftKeyDown() ? 0.2f : 0f) -
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.2f : 0),
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.15f : 0), rotation);
|
|
||||||
// renderArmPre(model.leftSleeve, 0.8F + (player.isShiftKeyDown() ? 0.2f : 0f) -
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? -0.2f : 0),
|
|
||||||
// (stack.getItem() == RegistrationHandler.itemEntity.get() ? 0.15f : 0), rotation);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @OnlyIn(Dist.CLIENT)
|
|
||||||
// private void renderArmPre(ModelRenderer arm, float x, float z, float
|
|
||||||
// rotation)
|
|
||||||
// {
|
|
||||||
// arm.xRot = (float) -x;
|
|
||||||
// arm.yRot = (float) -Math.toRadians(rotation);
|
|
||||||
// arm.zRot = (float) z;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
package tschipp.carryon.network.client;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
|
||||||
import tschipp.carryon.CarryOn;
|
|
||||||
import tschipp.carryon.common.scripting.ScriptChecker;
|
|
||||||
|
|
||||||
public class CarrySlotPacket
|
|
||||||
{
|
|
||||||
public int slot;
|
|
||||||
public int carryOverride = 0;
|
|
||||||
public int entityid;
|
|
||||||
|
|
||||||
public CarrySlotPacket(ByteBuf buf)
|
|
||||||
{
|
|
||||||
this.slot = buf.readInt();
|
|
||||||
this.carryOverride = buf.readInt();
|
|
||||||
this.entityid = buf.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CarrySlotPacket(int slot, int entityid)
|
|
||||||
{
|
|
||||||
this.slot = slot;
|
|
||||||
this.entityid = entityid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CarrySlotPacket(int slot, int entityid, int carryOverride)
|
|
||||||
{
|
|
||||||
this.slot = slot;
|
|
||||||
this.carryOverride = carryOverride;
|
|
||||||
this.entityid = entityid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toBytes(ByteBuf buf)
|
|
||||||
{
|
|
||||||
buf.writeInt(this.slot);
|
|
||||||
buf.writeInt(this.carryOverride);
|
|
||||||
buf.writeInt(this.entityid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean handle(Supplier<NetworkEvent.Context> ctx)
|
|
||||||
{
|
|
||||||
if (ctx.get().getDirection().getReceptionSide().isClient())
|
|
||||||
{
|
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
|
|
||||||
ctx.get().enqueueWork(() -> {
|
|
||||||
|
|
||||||
Level level = CarryOn.proxy.getLevel();
|
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
|
|
||||||
if (level != null)
|
|
||||||
{
|
|
||||||
Entity e = level.getEntity(this.entityid);
|
|
||||||
|
|
||||||
if (e instanceof Player player)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
if (this.slot >= 9)
|
|
||||||
{
|
|
||||||
player.getPersistentData().remove("carrySlot");
|
|
||||||
player.getPersistentData().remove("overrideKey");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
player.getPersistentData().putInt("carrySlot", this.slot);
|
|
||||||
if (this.carryOverride != 0)
|
|
||||||
ScriptChecker.setCarryOnOverride(player, this.carryOverride);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
package tschipp.carryon.network.client;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
|
||||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
|
||||||
import tschipp.carryon.common.scripting.ScriptReader;
|
|
||||||
|
|
||||||
public class ScriptReloadPacket
|
|
||||||
{
|
|
||||||
private List<CarryOnOverride> overrides = new ArrayList<>();
|
|
||||||
|
|
||||||
// public ScriptReloadPacket()
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
public ScriptReloadPacket(Collection<CarryOnOverride> collection)
|
|
||||||
{
|
|
||||||
this.overrides.addAll(collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScriptReloadPacket(FriendlyByteBuf buf)
|
|
||||||
{
|
|
||||||
int size = buf.readInt();
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
this.overrides.add(CarryOnOverride.deserialize(buf));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toBytes(FriendlyByteBuf buf)
|
|
||||||
{
|
|
||||||
buf.writeInt(this.overrides.size());
|
|
||||||
this.overrides.forEach(override -> override.serialize(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean handle(Supplier<NetworkEvent.Context> ctx)
|
|
||||||
{
|
|
||||||
if (ctx.get().getDirection().getReceptionSide().isClient())
|
|
||||||
{
|
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
ctx.get().enqueueWork(() -> {
|
|
||||||
|
|
||||||
ScriptReader.OVERRIDES.clear();
|
|
||||||
|
|
||||||
this.overrides.forEach(override -> {
|
|
||||||
ScriptReader.OVERRIDES.put(override.hashCode(), override);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
package tschipp.carryon.network.server;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
|
||||||
|
|
||||||
public class SyncKeybindPacket
|
|
||||||
{
|
|
||||||
public boolean pressed;
|
|
||||||
|
|
||||||
public SyncKeybindPacket(ByteBuf buf)
|
|
||||||
{
|
|
||||||
this.pressed = buf.readBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SyncKeybindPacket(boolean pressed)
|
|
||||||
{
|
|
||||||
this.pressed = pressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toBytes(ByteBuf buf)
|
|
||||||
{
|
|
||||||
buf.writeBoolean(this.pressed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean handle(Supplier<NetworkEvent.Context> ctx)
|
|
||||||
{
|
|
||||||
if (ctx.get().getDirection().getReceptionSide().isServer())
|
|
||||||
{
|
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
ctx.get().enqueueWork(() -> {
|
|
||||||
|
|
||||||
ServerPlayer player = ctx.get().getSender();
|
|
||||||
|
|
||||||
CarryOnKeybinds.setKeyPressed(player, this.pressed);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
package tschipp.carryon.proxy;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
|
||||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
|
||||||
import tschipp.carryon.common.helper.KeyboardCallbackWrapper;
|
|
||||||
import tschipp.carryon.common.helper.ScrollCallbackWrapper;
|
|
||||||
|
|
||||||
public class ClientProxy implements IProxy
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setup(FMLCommonSetupEvent event)
|
|
||||||
{
|
|
||||||
RegistrationHandler.regClientEvents();
|
|
||||||
|
|
||||||
new ScrollCallbackWrapper().setup(Minecraft.getInstance());
|
|
||||||
new KeyboardCallbackWrapper().setup(Minecraft.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Player getPlayer()
|
|
||||||
{
|
|
||||||
|
|
||||||
return Minecraft.getInstance().player;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Level getLevel()
|
|
||||||
{
|
|
||||||
return Minecraft.getInstance().level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
package tschipp.carryon.proxy;
|
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
|
|
||||||
public interface IProxy
|
|
||||||
{
|
|
||||||
|
|
||||||
public void setup(final FMLCommonSetupEvent event);
|
|
||||||
|
|
||||||
public Player getPlayer();
|
|
||||||
|
|
||||||
public Level getLevel();
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
package tschipp.carryon.proxy;
|
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
|
|
||||||
public class ServerProxy implements IProxy
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setup(FMLCommonSetupEvent event)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Player getPlayer()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Level getLevel()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
modLoader="javafml"
|
|
||||||
loaderVersion="[41,)"
|
|
||||||
issueTrackerURL="https://github.com/Tschipp/CarryOn/issues"
|
|
||||||
logoFile="logo.png"
|
|
||||||
license="GNU LGPLv3"
|
|
||||||
|
|
||||||
[[mods]]
|
|
||||||
modId="carryon"
|
|
||||||
version="${file.jarVersion}"
|
|
||||||
displayName="Carry On"
|
|
||||||
description='''Carry On is a simple mod that improves game interaction by allowing players to pick up, carry, and place single block Tile Entities using only their empty hands.'''
|
|
||||||
authors="Tschipp, Purplicious_Cow, cy4n" #mandatory
|
|
||||||
displayURL="https://minecraft.curseforge.com/projects/carry-on" #mandatory
|
|
||||||
|
|
||||||
[[dependencies.carryon]] #optional
|
|
||||||
# the modid of the dependency
|
|
||||||
modId="forge" #mandatory
|
|
||||||
# Does this dependency have to exist - if not, ordering below must be specified
|
|
||||||
mandatory=true #mandatory
|
|
||||||
# The version range of the dependency
|
|
||||||
versionRange="[41,)" #mandatory
|
|
||||||
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
|
|
||||||
ordering="NONE"
|
|
||||||
# Side this dependency is applied on - BOTH, CLIENT or SERVER
|
|
||||||
side="BOTH"
|
|
||||||
|
|
||||||
[[dependencies.carryon]]
|
|
||||||
modId="minecraft"
|
|
||||||
mandatory=true
|
|
||||||
versionRange="[1.19,1.20)"
|
|
||||||
ordering="NONE"
|
|
||||||
side="BOTH"
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"carryon.category.settings": "sᵷuᴉʇʇǝS",
|
|
||||||
"carryon.category.blacklist": "ʇsᴉꞁʞɔɐꞁᗺ",
|
|
||||||
"carryon.category.modeloverrides": "(pǝɔuɐʌpⱯ) sǝpᴉɹɹǝʌO ꞁǝpoW",
|
|
||||||
"carryon.category.custompickupconditions": "(pǝɔuɐʌpⱯ) suoᴉʇᴉpuoƆ dnʞɔᴉԀ ɯoʇsnƆ",
|
|
||||||
"carryon.category.whitelist": "ʇsᴉꞁǝʇᴉɥM",
|
|
||||||
|
|
||||||
"carryon.general.modeloverrides.modeloverrides": "sǝpᴉɹɹǝʌO ꞁǝpoW",
|
|
||||||
"carryon.general.blacklist.forbiddenentities": "dn ʞɔᴉd ʇouuɐɔ ɹǝʎɐꞁԀ ǝɥʇ ʇɐɥʇ sǝᴉʇᴉʇuƎ",
|
|
||||||
"carryon.general.blacklist.forbiddentiles": "dn ʞɔᴉd ʇouuɐɔ ɹǝʎɐꞁԀ ǝɥʇ ʇɐɥʇ sʞɔoꞁᗺ",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsblocks": "suoᴉʇᴉpuoƆ dnʞɔᴉԀ ʞɔoꞁᗺ ɯoʇsnƆ",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsentities": "suoᴉʇᴉpuoƆ dnʞɔᴉԀ ʎʇᴉʇuƎ ɯoʇsnƆ",
|
|
||||||
|
|
||||||
"key.carry.desc": "ʎɹɹɐƆ",
|
|
||||||
"key.carry.category": "uO ʎɹɹɐƆ"
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"carryon.category.settings": "Settings",
|
|
||||||
"carryon.category.blacklist": "Blacklist",
|
|
||||||
"carryon.category.modeloverrides": "Model Overrides (Advanced)",
|
|
||||||
"carryon.category.custompickupconditions": "Custom Pickup Conditions (Advanced)",
|
|
||||||
"carryon.category.whitelist": "Whitelist",
|
|
||||||
|
|
||||||
"carryon.general.modeloverrides.modeloverrides": "Model Overrides",
|
|
||||||
"carryon.general.blacklist.forbiddenentities": "Entities that the Player cannot pick up",
|
|
||||||
"carryon.general.blacklist.forbiddentiles": "Blocks that the Player cannot pick up",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsblocks": "Custom Block Pickup Conditions",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsentities": "Custom Entity Pickup Conditions",
|
|
||||||
|
|
||||||
"key.carry.desc": "Carry",
|
|
||||||
"key.carry.category": "Carry On"
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"carryon.category.settings": "Configuración",
|
|
||||||
"carryon.category.blacklist": "Lista negra",
|
|
||||||
"carryon.category.modeloverrides": "Reescribir modelo (Avanzado)",
|
|
||||||
"carryon.category.custompickupconditions": "Customizar condiciones de recoger (Avanzado)",
|
|
||||||
"carryon.category.whitelist": "Lista blanca",
|
|
||||||
|
|
||||||
"carryon.general.modeloverrides.modeloverrides": "Reescribir modelo",
|
|
||||||
"carryon.general.blacklist.forbiddenentities": "Entidades que el jugador no puede recoger",
|
|
||||||
"carryon.general.blacklist.forbiddentiles": "Bloques que el jugador no puede recoger",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsblocks": "Customizar condiciones para recoger bloques",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsentities": "Customizar condiciones para recoger entidades",
|
|
||||||
|
|
||||||
"key.carry.desc": "Agarrar",
|
|
||||||
"key.carry.category": "Carry On"
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"carryon.category.settings": "Inpostazioni",
|
|
||||||
"carryon.category.blacklist": "Blacklist",
|
|
||||||
"carryon.category.modeloverrides": "Sostituzioni modello (avanzate)",
|
|
||||||
"carryon.category.custompickupconditions": "Condizioni di prelievo personalizzate (avanzate)",
|
|
||||||
"carryon.category.whitelist": "Whitelist",
|
|
||||||
|
|
||||||
"carryon.general.modeloverrides.modeloverrides": "Sostituzioni modello",
|
|
||||||
"carryon.general.blacklist.forbiddenentities": "Entità che il giocatore non può raccogliere",
|
|
||||||
"carryon.general.blacklist.forbiddentiles": "Blocchi che il giocatore non può raccogliere",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsblocks": "Condizioni di prelievo blocco personalizzate",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsentities": "Condizioni di prelievo entità personalizzate",
|
|
||||||
|
|
||||||
"key.carry.desc": "Afferra",
|
|
||||||
"key.carry.category": "Carry On Mod"
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"carryon.category.settings": "설정",
|
|
||||||
"carryon.category.blacklist": "블랙리스트",
|
|
||||||
"carryon.category.modeloverrides": "모델 오버라이딩 (고급)",
|
|
||||||
"carryon.category.custompickupconditions": "커스텀 들기 컨디션 (고급)",
|
|
||||||
"carryon.category.whitelist": "화이트리스트",
|
|
||||||
|
|
||||||
"carryon.general.modeloverrides.modeloverrides": "모델 오버라이딩",
|
|
||||||
"carryon.general.blacklist.forbiddenentities": "플레이어가 들 수 없는 엔티티",
|
|
||||||
"carryon.general.blacklist.forbiddentiles": "플레이어가 들 수 없는 블록",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsblocks": "커스텀 블록 들기 컨디션",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsentities": "커스텀 엔티티 들기 컨디션",
|
|
||||||
|
|
||||||
"key.carry.desc": "들고 나르기",
|
|
||||||
"key.carry.category": "Carry On"
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"carryon.category.settings": "Настройки",
|
|
||||||
"carryon.category.blacklist": "Чёрный список",
|
|
||||||
"carryon.category.modeloverrides": "Переопределения модели (Улучшенное)",
|
|
||||||
"carryon.category.custompickupconditions": "Индивидуальные условия поднятия (Улучшенное)",
|
|
||||||
"carryon.category.whitelist": "Белый список",
|
|
||||||
|
|
||||||
"carryon.general.modeloverrides.modeloverrides": "Переопределения модели",
|
|
||||||
"carryon.general.blacklist.forbiddenentities": "Сущности, которых игрок не может поднять",
|
|
||||||
"carryon.general.blacklist.forbiddentiles": "Блоки, которые игрок не может поднять",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsblocks": "Пользовательские условия поднятия блока",
|
|
||||||
"carryon.category.custompickupconditions.custompickupconditionsentities": "Пользовательские условия поднятия сущности",
|
|
||||||
|
|
||||||
"key.carry.desc": "Поднять",
|
|
||||||
"key.carry.category": "Carry On"
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"parent": "item/generated",
|
|
||||||
"textures": {
|
|
||||||
"layer0": "carryon:item/tile"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"parent": "item/generated",
|
|
||||||
"textures": {
|
|
||||||
"layer0": "carryon:item/tile"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 198 B |
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"replace": false,
|
|
||||||
"values": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"replace": false,
|
|
||||||
"values": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"replace": false,
|
|
||||||
"values": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"replace": false,
|
|
||||||
"values": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"replace": false,
|
|
||||||
"values": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"replace": false,
|
|
||||||
"values": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 170 KiB |
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"pack": {
|
|
||||||
"description": "Carryon Resources and Data",
|
|
||||||
"pack_format": 6
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user