Compare commits
No commits in common. "forge-1.16.5-1.9" and "main" have entirely different histories.
forge-1.16
...
main
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,7 +19,7 @@ build
|
|||||||
|
|
||||||
# other
|
# other
|
||||||
eclipse
|
eclipse
|
||||||
run
|
run*
|
||||||
|
|
||||||
# Files from Forge MDK
|
# Files from Forge MDK
|
||||||
forge*changelog.txt
|
forge*changelog.txt
|
||||||
|
193
build.gradle
193
build.gradle
@ -1,63 +1,31 @@
|
|||||||
buildscript {
|
plugins {
|
||||||
repositories {
|
id 'eclipse'
|
||||||
maven { url = 'https://maven.minecraftforge.net' }
|
id 'maven-publish'
|
||||||
maven { url = 'https://maven.parchmentmc.org' }
|
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
|
|
||||||
classpath 'org.parchmentmc:librarian:1.+'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
apply plugin: 'net.minecraftforge.gradle'
|
|
||||||
apply plugin: 'org.parchmentmc.librarian.forgegradle'
|
|
||||||
// edit below this line
|
|
||||||
apply plugin: 'maven-publish'
|
|
||||||
|
|
||||||
version = '1.9'
|
version = rootProject.mod_version
|
||||||
group = 'ru.magistu.siegemachines' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
group = 'com.yourname.modid'
|
||||||
archivesBaseName = 'siegemachines'
|
archivesBaseName = rootProject.archives_base_name
|
||||||
|
|
||||||
java.toolchain.languageVersion = JavaLanguageVersion.of(8) // Mojang ships Java 8 to end users, so your mod should target Java 8.
|
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'))
|
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
|
||||||
minecraft {
|
minecraft {
|
||||||
// The mappings can be changed at any time, and must be in the following format.
|
mappings channel: 'official', version: '1.20.1'
|
||||||
// Channel: Version:
|
|
||||||
// snapshot YYYYMMDD Snapshot are built nightly.
|
|
||||||
// stable # Stables are built at the discretion of the MCP team.
|
|
||||||
// official MCVersion Official field/method names from Mojang mapping files
|
|
||||||
//
|
|
||||||
// You must be aware of the Mojang license when using the 'official' mappings.
|
|
||||||
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
|
|
||||||
//
|
|
||||||
// Use non-default mappings at your own risk. they may not always work.
|
|
||||||
// Simply re-run your setup task after changing the mappings to update your workspace.
|
|
||||||
mappings channel: 'parchment', version: '2022.03.06-1.16.5'
|
|
||||||
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
|
|
||||||
|
|
||||||
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
|
|
||||||
|
|
||||||
// Default run configurations.
|
|
||||||
// These can be tweaked, removed, or duplicated as needed.
|
|
||||||
runs {
|
runs {
|
||||||
client {
|
client {
|
||||||
workingDirectory project.file('run')
|
workingDirectory project.file('run')
|
||||||
|
|
||||||
// Recommended logging data for a userdev environment
|
|
||||||
// The markers can be changed as needed.
|
|
||||||
// "SCAN": For mods scan.
|
|
||||||
// "REGISTRIES": For firing of registry events.
|
|
||||||
// "REGISTRYDUMP": For getting the contents of all registries.
|
|
||||||
property 'forge.logging.markers', 'REGISTRIES'
|
property 'forge.logging.markers', 'REGISTRIES'
|
||||||
|
|
||||||
// Recommended logging level for the console
|
|
||||||
// You can set various levels here.
|
|
||||||
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
property 'forge.logging.console.level', 'debug'
|
||||||
|
|
||||||
|
|
||||||
|
property 'forge.enabledGameTestNamespaces', 'examplemod'
|
||||||
|
|
||||||
mods {
|
mods {
|
||||||
siegemachines {
|
examplemod {
|
||||||
source sourceSets.main
|
source sourceSets.main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,20 +34,30 @@ minecraft {
|
|||||||
server {
|
server {
|
||||||
workingDirectory project.file('run')
|
workingDirectory project.file('run')
|
||||||
|
|
||||||
// Recommended logging data for a userdev environment
|
|
||||||
// The markers can be changed as needed.
|
|
||||||
// "SCAN": For mods scan.
|
|
||||||
// "REGISTRIES": For firing of registry events.
|
|
||||||
// "REGISTRYDUMP": For getting the contents of all registries.
|
|
||||||
property 'forge.logging.markers', 'REGISTRIES'
|
property 'forge.logging.markers', 'REGISTRIES'
|
||||||
|
|
||||||
// Recommended logging level for the console
|
|
||||||
// You can set various levels here.
|
|
||||||
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
property 'forge.logging.console.level', 'debug'
|
||||||
|
|
||||||
|
property 'forge.enabledGameTestNamespaces', 'examplemod'
|
||||||
|
|
||||||
mods {
|
mods {
|
||||||
siegemachines {
|
examplemod {
|
||||||
|
source sourceSets.main
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gameTestServer {
|
||||||
|
workingDirectory project.file('run')
|
||||||
|
|
||||||
|
property 'forge.logging.markers', 'REGISTRIES'
|
||||||
|
|
||||||
|
property 'forge.logging.console.level', 'debug'
|
||||||
|
|
||||||
|
property 'forge.enabledGameTestNamespaces', 'examplemod'
|
||||||
|
|
||||||
|
mods {
|
||||||
|
examplemod {
|
||||||
source sourceSets.main
|
source sourceSets.main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,23 +66,14 @@ minecraft {
|
|||||||
data {
|
data {
|
||||||
workingDirectory project.file('run')
|
workingDirectory project.file('run')
|
||||||
|
|
||||||
// Recommended logging data for a userdev environment
|
|
||||||
// The markers can be changed as needed.
|
|
||||||
// "SCAN": For mods scan.
|
|
||||||
// "REGISTRIES": For firing of registry events.
|
|
||||||
// "REGISTRYDUMP": For getting the contents of all registries.
|
|
||||||
property 'forge.logging.markers', 'REGISTRIES'
|
property 'forge.logging.markers', 'REGISTRIES'
|
||||||
|
|
||||||
// Recommended logging level for the console
|
|
||||||
// You can set various levels here.
|
|
||||||
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
property 'forge.logging.console.level', 'debug'
|
||||||
|
|
||||||
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
|
args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
|
||||||
args '--mod', 'siegemachines', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
|
|
||||||
|
|
||||||
mods {
|
mods {
|
||||||
siegemachines {
|
examplemod {
|
||||||
source sourceSets.main
|
source sourceSets.main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,56 +81,42 @@ minecraft {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include resources generated by data generators.
|
|
||||||
sourceSets.main.resources { srcDir 'src/generated/resources' }
|
sourceSets.main.resources { srcDir 'src/generated/resources' }
|
||||||
|
|
||||||
dependencies {
|
repositories {
|
||||||
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
|
maven { url = "https://cursemaven.com" }
|
||||||
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
|
}
|
||||||
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
|
|
||||||
minecraft 'net.minecraftforge:forge:1.16.5-36.2.39'
|
dependencies {
|
||||||
implementation fg.deobf('software.bernie.geckolib:geckolib-forge-1.16.5:3.0.104')
|
minecraft 'net.minecraftforge:forge:1.20.1-47.3.0'
|
||||||
|
|
||||||
// You may put jars on which you depend on in ./libs or you may define them like so..
|
implementation fg.deobf("curse.maven:geckolib-388172:5675221")
|
||||||
// compile "some.group:artifact:version:classifier"
|
implementation fg.deobf("curse.maven:jei-238222:6075247")
|
||||||
// compile "some.group:artifact:version"
|
}
|
||||||
|
|
||||||
// Real examples
|
processResources {
|
||||||
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
|
inputs.property "version", project.version
|
||||||
// compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
|
|
||||||
|
filesMatching("META-INF/mods.toml") {
|
||||||
// The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
|
expand "version": project.version
|
||||||
// provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
|
}
|
||||||
|
|
||||||
// These dependencies get remapped to your current MCP mappings
|
|
||||||
// deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'
|
|
||||||
|
|
||||||
// For more info...
|
|
||||||
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
|
|
||||||
// http://www.gradle.org/docs/current/userguide/dependency_management.html
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example for how to get properties into the manifest for reading by the runtime..
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes([
|
attributes([
|
||||||
"Specification-Title": "siegemachines",
|
"Specification-Title" : "examplemod",
|
||||||
"Specification-Vendor": "siegemachinessareus",
|
"Specification-Vendor" : "examplemodsareus",
|
||||||
"Specification-Version": "1", // We are version 1 of ourselves
|
"Specification-Version" : "1",
|
||||||
"Implementation-Title": project.name,
|
"Implementation-Title" : project.name,
|
||||||
"Implementation-Version": "${version}",
|
"Implementation-Version" : project.jar.archiveVersion,
|
||||||
"Implementation-Vendor" :"siegemachinessareus",
|
"Implementation-Vendor" : "examplemodsareus",
|
||||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example configuration to allow publishing using the maven-publish task
|
jar.finalizedBy('reobfJar')
|
||||||
// This is the preferred method to reobfuscate your jar file
|
|
||||||
jar.finalizedBy('reobfJar')
|
|
||||||
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
|
|
||||||
//publish.dependsOn('reobfJar')
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
@ -171,33 +126,11 @@ publishing {
|
|||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
url "file:///${project.projectDir}/mcmodsrepo"
|
url "file://${project.projectDir}/mcmodsrepo"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
// GeckoLib maven repo
|
options.encoding = 'UTF-8'
|
||||||
maven {
|
|
||||||
url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/'
|
|
||||||
}
|
|
||||||
|
|
||||||
// JEI api maven repo
|
|
||||||
maven {
|
|
||||||
name = "Progwml6 maven"
|
|
||||||
url = "https://dvs1.progwml6.com/files/maven/"
|
|
||||||
}
|
|
||||||
|
|
||||||
// location of a maven mirror for JEI files, as a fallback
|
|
||||||
maven {
|
|
||||||
name = "ModMaven"
|
|
||||||
url = "https://modmaven.dev"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.jetbrains:annotations:20.1.0'
|
|
||||||
implementation fg.deobf('software.bernie.geckolib:geckolib-forge-1.16.5:3.0.104')
|
|
||||||
compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api")
|
|
||||||
runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}")
|
|
||||||
}
|
|
@ -2,5 +2,9 @@
|
|||||||
# This is required to provide enough memory for the Minecraft decompilation process.
|
# This is required to provide enough memory for the Minecraft decompilation process.
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
mc_version=1.16.5
|
|
||||||
jei_version=7.7.1.153
|
mod_version=1.18
|
||||||
|
archives_base_name=[1.19.2]-Medieval-Siege-Machines
|
||||||
|
|
||||||
|
mc_version=1.19.2
|
||||||
|
jei_version=11.5.0.297
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
275
gradlew
vendored
275
gradlew
vendored
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright 2015 the original author or authors.
|
# Copyright © 2015-2021 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -17,67 +17,101 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
#
|
||||||
## Gradle start up script for UN*X
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
##
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
app_path=$0
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
# Need this for daisy-chained symlinks.
|
||||||
ls=`ls -ld "$PRG"`
|
while
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
[ -h "$app_path" ]
|
||||||
PRG="$link"
|
do
|
||||||
else
|
ls=$( ls -ld "$app_path" )
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
link=${ls#*' -> '}
|
||||||
fi
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
APP_NAME="Gradle"
|
||||||
APP_BASE_NAME=`basename "$0"`
|
APP_BASE_NAME=${0##*/}
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD=maximum
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$( uname )" in #(
|
||||||
CYGWIN* )
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
cygwin=true
|
Darwin* ) darwin=true ;; #(
|
||||||
;;
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
Darwin* )
|
NONSTOP* ) nonstop=true ;;
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
|||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="java"
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
@ -106,80 +140,101 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
case $MAX_FD in #(
|
||||||
if [ $? -eq 0 ] ; then
|
max*)
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
warn "Could not query maximum file descriptor limit"
|
||||||
fi
|
esac
|
||||||
ulimit -n $MAX_FD
|
case $MAX_FD in #(
|
||||||
if [ $? -ne 0 ] ; then
|
'' | soft) :;; #(
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
*)
|
||||||
fi
|
ulimit -n "$MAX_FD" ||
|
||||||
else
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=`expr $i + 1`
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
0) set -- ;;
|
|
||||||
1) set -- "$args0" ;;
|
|
||||||
2) set -- "$args0" "$args1" ;;
|
|
||||||
3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
save () {
|
# * args from the command line
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
# * the main class name
|
||||||
echo " "
|
# * -classpath
|
||||||
}
|
# * -D...appname settings
|
||||||
APP_ARGS=`save "$@"`
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command;
|
||||||
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
# double quotes to make sure that they get re-expanded; and
|
||||||
|
# * put everything else in single quotes, so that it's not re-expanded.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
14
gradlew.bat
vendored
14
gradlew.bat
vendored
@ -14,7 +14,7 @@
|
|||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@ -25,7 +25,7 @@
|
|||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
|||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
6
settings.gradle
Normal file
6
settings.gradle
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
maven { url = 'https://maven.minecraftforge.net/' }
|
||||||
|
}
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
package magistu.plugins.jei;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.data.recipes.ModRecipes;
|
|
||||||
import mezz.jei.api.registration.IRecipeRegistration;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.item.crafting.IRecipeType;
|
|
||||||
import net.minecraft.item.crafting.RecipeManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
import mezz.jei.api.IModPlugin;
|
|
||||||
import mezz.jei.api.JeiPlugin;
|
|
||||||
import mezz.jei.api.helpers.IGuiHelper;
|
|
||||||
import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@JeiPlugin
|
|
||||||
public class JeiSupport implements IModPlugin
|
|
||||||
{
|
|
||||||
private static final ResourceLocation PLUGIN_ID = new ResourceLocation(SiegeMachines.ID, "jei_plugin");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getPluginUid()
|
|
||||||
{
|
|
||||||
return PLUGIN_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
@Override
|
|
||||||
public void registerRecipes(IRecipeRegistration registration)
|
|
||||||
{
|
|
||||||
RecipeManager manager = Minecraft.getInstance().level.getRecipeManager();
|
|
||||||
|
|
||||||
registration.addRecipes(getRecipes(manager, ModRecipes.SIEGE_WORKBENCH_RECIPE), SiegeWorkbenchRecipeCategory.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerCategories(IRecipeCategoryRegistration registration)
|
|
||||||
{
|
|
||||||
IGuiHelper helper = registration.getJeiHelpers().getGuiHelper();
|
|
||||||
|
|
||||||
registration.addRecipeCategories(new SiegeWorkbenchRecipeCategory(helper));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Collection<?> getRecipes(RecipeManager manager, IRecipeType<?> type)
|
|
||||||
{
|
|
||||||
return manager.getRecipes().parallelStream().filter(recipe -> recipe.getType() == type).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,96 +0,0 @@
|
|||||||
package magistu.plugins.jei;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.block.ModBlocks;
|
|
||||||
import magistu.siegemachines.data.recipes.SiegeWorkbenchRecipe;
|
|
||||||
import mezz.jei.api.constants.VanillaTypes;
|
|
||||||
import mezz.jei.api.gui.IRecipeLayout;
|
|
||||||
import mezz.jei.api.gui.drawable.IDrawable;
|
|
||||||
import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
|
|
||||||
import mezz.jei.api.helpers.IGuiHelper;
|
|
||||||
import mezz.jei.api.ingredients.IIngredients;
|
|
||||||
import mezz.jei.api.recipe.category.IRecipeCategory;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class SiegeWorkbenchRecipeCategory implements IRecipeCategory<SiegeWorkbenchRecipe>
|
|
||||||
{
|
|
||||||
public static final ResourceLocation ID = new ResourceLocation(SiegeMachines.ID, ".siege_workbench_recipe_category");
|
|
||||||
|
|
||||||
private final IDrawable background;
|
|
||||||
private final IDrawable overlay;
|
|
||||||
private final IDrawable icon;
|
|
||||||
|
|
||||||
public SiegeWorkbenchRecipeCategory(IGuiHelper helper)
|
|
||||||
{
|
|
||||||
this.background = helper.createBlankDrawable(116, 54);
|
|
||||||
this.overlay = helper.createDrawable(new ResourceLocation(SiegeMachines.ID, "textures/gui/siege_workbench.png"), 29, 16, 116, 54);
|
|
||||||
this.icon = helper.createDrawableIngredient(new ItemStack(ModBlocks.SIEGE_WORKBENCH.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ResourceLocation getUid()
|
|
||||||
{
|
|
||||||
return ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Class<? extends SiegeWorkbenchRecipe> getRecipeClass()
|
|
||||||
{
|
|
||||||
return SiegeWorkbenchRecipe.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull String getTitle()
|
|
||||||
{
|
|
||||||
return new TranslationTextComponent("category." + SiegeMachines.ID + ".siege_workbench_crafting").getString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull IDrawable getBackground()
|
|
||||||
{
|
|
||||||
return background;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(SiegeWorkbenchRecipe recipe, MatrixStack matrixStack, double mouseX, double mouseY)
|
|
||||||
{
|
|
||||||
this.overlay.draw(matrixStack, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull IDrawable getIcon()
|
|
||||||
{
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIngredients(SiegeWorkbenchRecipe recipe, IIngredients ingredients)
|
|
||||||
{
|
|
||||||
ingredients.setInputIngredients(recipe.getIngredients());
|
|
||||||
ingredients.setOutput(VanillaTypes.ITEM, recipe.getResultItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRecipe(IRecipeLayout recipeLayout, SiegeWorkbenchRecipe recipe, IIngredients ingredients)
|
|
||||||
{
|
|
||||||
IGuiItemStackGroup group = recipeLayout.getItemStacks();
|
|
||||||
|
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
group.init(n++, false, 94, 18);
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < 3; ++j)
|
|
||||||
{
|
|
||||||
group.init(n++, true, j * 18, i * 18);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
group.set(ingredients);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
package magistu.siegemachines;
|
|
||||||
|
|
||||||
import magistu.siegemachines.block.ModBlocks;
|
|
||||||
import magistu.siegemachines.client.ClientProxy;
|
|
||||||
import magistu.siegemachines.client.SoundTypes;
|
|
||||||
import magistu.siegemachines.config.SpecsConfig;
|
|
||||||
import magistu.siegemachines.data.recipes.ModRecipes;
|
|
||||||
import magistu.siegemachines.gui.ContainerTypes;
|
|
||||||
import magistu.siegemachines.entity.EntityTypes;
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import magistu.siegemachines.network.PacketHandler;
|
|
||||||
import magistu.siegemachines.proxy.IProxy;
|
|
||||||
import magistu.siegemachines.server.ServerProxy;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
|
||||||
import net.minecraftforge.fml.InterModComms;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
|
|
||||||
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
// The value here should match an entry in the META-INF/mods.toml file
|
|
||||||
@Mod(SiegeMachines.ID)
|
|
||||||
public class SiegeMachines
|
|
||||||
{
|
|
||||||
public static final String ID = "siegemachines";
|
|
||||||
|
|
||||||
public static final IProxy PROXY = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> ServerProxy::new);
|
|
||||||
public static final int RENDER_UPDATE_RANGE = 128;
|
|
||||||
public static final int RENDER_UPDATE_TIME = 20;
|
|
||||||
public static final int RENDER_UPDATE_RANGE_SQR = RENDER_UPDATE_RANGE * RENDER_UPDATE_RANGE;
|
|
||||||
|
|
||||||
public static final UUID CHAT_UUID = new UUID(100L, 100L);
|
|
||||||
|
|
||||||
// Directly reference a log4j logger.
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
|
||||||
|
|
||||||
|
|
||||||
public SiegeMachines()
|
|
||||||
{
|
|
||||||
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
|
||||||
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
|
|
||||||
|
|
||||||
EntityTypes.register(eventBus);
|
|
||||||
SoundTypes.register(eventBus);
|
|
||||||
ContainerTypes.register(eventBus);
|
|
||||||
ModBlocks.register(eventBus);
|
|
||||||
ModItems.register(eventBus);
|
|
||||||
ModRecipes.register(eventBus);
|
|
||||||
SpecsConfig.register();
|
|
||||||
|
|
||||||
PacketHandler.init();
|
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void setup(final FMLCommonSetupEvent event)
|
|
||||||
{
|
|
||||||
// some preinit code
|
|
||||||
LOGGER.info("HELLO FROM PREINIT");
|
|
||||||
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doClientStuff(final FMLClientSetupEvent event)
|
|
||||||
{
|
|
||||||
// do something that can only be done on the client
|
|
||||||
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().options);
|
|
||||||
|
|
||||||
PROXY.clientSetup(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enqueueIMC(final InterModEnqueueEvent event)
|
|
||||||
{
|
|
||||||
// some example code to dispatch IMC to another mod
|
|
||||||
InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processIMC(final InterModProcessEvent event)
|
|
||||||
{
|
|
||||||
// some example code to receive and process InterModComms from other mods
|
|
||||||
LOGGER.info("Got IMC {}", event.getIMCStream().
|
|
||||||
map(m->m.getMessageSupplier().get()).
|
|
||||||
collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onServerStarting(FMLServerStartingEvent event)
|
|
||||||
{
|
|
||||||
// do something when the server starts
|
|
||||||
LOGGER.info("HELLO from server starting");
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
|
|
||||||
// Event bus for receiving Registry Events)
|
|
||||||
@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
|
|
||||||
public static class RegistryEvents
|
|
||||||
{
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent)
|
|
||||||
{
|
|
||||||
// register a new block here
|
|
||||||
LOGGER.info("HELLO from Register Block");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package magistu.siegemachines.block;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.block.AbstractBlock;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.SoundType;
|
|
||||||
import net.minecraft.block.material.Material;
|
|
||||||
import net.minecraft.item.BlockItem;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.fml.RegistryObject;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class ModBlocks
|
|
||||||
{
|
|
||||||
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, SiegeMachines.ID);
|
|
||||||
public static final RegistryObject<SiegeWorkbench> SIEGE_WORKBENCH = registerBlock("siege_workbench", () -> new SiegeWorkbench(AbstractBlock.Properties.of(Material.WOOD).strength(2.5f).sound(SoundType.WOOD)));
|
|
||||||
|
|
||||||
private static <T extends Block>RegistryObject<T> registerBlock(String name, Supplier<T> block)
|
|
||||||
{
|
|
||||||
RegistryObject<T> toReturn = BLOCKS.register(name, block);
|
|
||||||
registerBlockItem(name, toReturn);
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T extends Block> void registerBlockItem(String name, RegistryObject<T> block)
|
|
||||||
{
|
|
||||||
ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties().tab(ModItems.GROUP_SM)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void register(IEventBus eventBus)
|
|
||||||
{
|
|
||||||
BLOCKS.register(eventBus);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package magistu.siegemachines.block;
|
|
||||||
|
|
||||||
import magistu.siegemachines.gui.SiegeWorkbenchContainer;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.CraftingTableBlock;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
|
||||||
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
|
|
||||||
import net.minecraft.util.ActionResultType;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.IWorldPosCallable;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class SiegeWorkbench extends CraftingTableBlock
|
|
||||||
{
|
|
||||||
private static final ITextComponent CONTAINER_TITLE = new TranslationTextComponent("container.crafting");
|
|
||||||
|
|
||||||
public SiegeWorkbench(Properties p_i48422_1_)
|
|
||||||
{
|
|
||||||
super(p_i48422_1_);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ActionResultType use(BlockState blockstate, World level, BlockPos blockpos, PlayerEntity player, Hand hand, BlockRayTraceResult result)
|
|
||||||
{
|
|
||||||
if (level.isClientSide)
|
|
||||||
{
|
|
||||||
return ActionResultType.SUCCESS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NetworkHooks.openGui((ServerPlayerEntity) player, this.getMenuProvider(blockstate, level, blockpos));
|
|
||||||
return ActionResultType.CONSUME;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public INamedContainerProvider getMenuProvider(BlockState blockstate, World level, BlockPos blockpos)
|
|
||||||
{
|
|
||||||
return new SimpleNamedContainerProvider((p_220270_2_, p_220270_3_, p_220270_4_) ->
|
|
||||||
new SiegeWorkbenchContainer(p_220270_2_, p_220270_3_, IWorldPosCallable.create(level, blockpos)), CONTAINER_TITLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package magistu.siegemachines.block;
|
|
||||||
|
|
||||||
import net.minecraft.inventory.CraftingInventory;
|
|
||||||
import net.minecraft.inventory.container.Container;
|
|
||||||
|
|
||||||
public class StacksCraftingInventory extends CraftingInventory
|
|
||||||
{
|
|
||||||
public StacksCraftingInventory(Container p_i1807_1_, int p_i1807_2_, int p_i1807_3_)
|
|
||||||
{
|
|
||||||
super(p_i1807_1_, p_i1807_2_, p_i1807_3_);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package magistu.siegemachines.client;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.client.renderer.*;
|
|
||||||
import magistu.siegemachines.entity.EntityTypes;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(modid = SiegeMachines.ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
|
||||||
public class ClientListener
|
|
||||||
{
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void registerRenderers(final FMLClientSetupEvent event)
|
|
||||||
{
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.MORTAR.get(), MortarGeoRenderer::new);
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.CULVERIN.get(), CulverinGeoRenderer::new);
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.TREBUCHET.get(), TrebuchetGeoRenderer::new);
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.CATAPULT.get(), CatapultGeoRenderer::new);
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.BALLISTA.get(), BallistaGeoRenderer::new);
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.BATTERING_RAM.get(), BatteringRamGeoRenderer::new);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package magistu.siegemachines.client;
|
|
||||||
|
|
||||||
import magistu.siegemachines.client.renderer.GiantArrowRenderer;
|
|
||||||
import magistu.siegemachines.entity.EntityTypes;
|
|
||||||
import magistu.siegemachines.gui.ContainerTypes;
|
|
||||||
import magistu.siegemachines.gui.MachineInventoryScreen;
|
|
||||||
import magistu.siegemachines.gui.SiegeWorkbenchScreen;
|
|
||||||
import magistu.siegemachines.proxy.IProxy;
|
|
||||||
import net.minecraft.client.gui.ScreenManager;
|
|
||||||
import net.minecraft.client.renderer.ItemRenderer;
|
|
||||||
import net.minecraft.client.renderer.entity.SpriteRenderer;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
||||||
|
|
||||||
public class ClientProxy implements IProxy
|
|
||||||
{
|
|
||||||
public void setup(IEventBus modEventBus, IEventBus forgeEventBus)
|
|
||||||
{
|
|
||||||
modEventBus.addListener(this::clientSetup);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clientSetup(FMLClientSetupEvent event)
|
|
||||||
{
|
|
||||||
ScreenManager.register(ContainerTypes.MACHINE_CONTAINER.get(), MachineInventoryScreen::new);
|
|
||||||
ScreenManager.register(ContainerTypes.SIEGE_WORKBENCH_CONTAINER.get(), SiegeWorkbenchScreen::new);
|
|
||||||
|
|
||||||
ItemRenderer renderer = event.getMinecraftSupplier().get().getItemRenderer();
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.CANNONBALL.get(), (renderManager) -> new SpriteRenderer<>(renderManager, renderer));
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.STONE.get(), (renderManager) -> new SpriteRenderer<>(renderManager, renderer));
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.GIANT_STONE.get(), (renderManager) -> new SpriteRenderer<>(renderManager, renderer));
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityTypes.GIANT_ARROW.get(), GiantArrowRenderer::new);
|
|
||||||
KeyBindings.register();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPreInit() {}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package magistu.siegemachines.client;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
|
||||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
|
||||||
|
|
||||||
public class KeyBindings
|
|
||||||
{
|
|
||||||
public static KeyBinding MACHINE_USE = new KeyBinding(SiegeMachines.ID + ".machine_use", 70, SiegeMachines.ID + ".category");
|
|
||||||
public static KeyBinding MACHINE_INVENTORY = new KeyBinding(SiegeMachines.ID + ".machine_inventory", 73, SiegeMachines.ID + ".category");
|
|
||||||
|
|
||||||
public static void register()
|
|
||||||
{
|
|
||||||
ClientRegistry.registerKeyBinding(MACHINE_USE);
|
|
||||||
ClientRegistry.registerKeyBinding(MACHINE_INVENTORY);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package magistu.siegemachines.client;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.SoundEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.fml.RegistryObject;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import software.bernie.geckolib3.GeckoLib;
|
|
||||||
|
|
||||||
public class SoundTypes
|
|
||||||
{
|
|
||||||
public static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS,
|
|
||||||
SiegeMachines.ID);
|
|
||||||
|
|
||||||
public static RegistryObject<SoundEvent> TREBUCHET_SHOOTING = SOUNDS.register("trebuchet_shooting",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "trebuchet_shooting")));
|
|
||||||
public static RegistryObject<SoundEvent> TREBUCHET_RELOADING = SOUNDS.register("trebuchet_reloading",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "trebuchet_reloading")));
|
|
||||||
public static RegistryObject<SoundEvent> CATAPULT_SHOOTING = SOUNDS.register("catapult_shooting",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "catapult_shooting")));
|
|
||||||
public static RegistryObject<SoundEvent> CATAPULT_RELOADING = SOUNDS.register("catapult_reloading",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "catapult_reloading")));
|
|
||||||
public static RegistryObject<SoundEvent> BALLISTA_SHOOTING = SOUNDS.register("ballista_shooting",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "ballista_shooting")));
|
|
||||||
public static RegistryObject<SoundEvent> BALLISTA_RELOADING = SOUNDS.register("ballista_reloading",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "ballista_reloading")));
|
|
||||||
public static RegistryObject<SoundEvent> MORTAR_SHOOTING = SOUNDS.register("mortar_shooting",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "mortar_shooting")));
|
|
||||||
public static RegistryObject<SoundEvent> FUSE = SOUNDS.register("fuse",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "fuse")));
|
|
||||||
public static RegistryObject<SoundEvent> CANNON_WHEELS = SOUNDS.register("cannon_wheels",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "cannon_wheels")));
|
|
||||||
public static RegistryObject<SoundEvent> RAM_WHEELS = SOUNDS.register("ram_wheels",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "ram_wheels")));
|
|
||||||
public static RegistryObject<SoundEvent> RAM_HITTING = SOUNDS.register("ram_hitting",
|
|
||||||
() -> new SoundEvent(new ResourceLocation(SiegeMachines.ID, "ram_hitting")));
|
|
||||||
|
|
||||||
public static void register(IEventBus eventBus)
|
|
||||||
{
|
|
||||||
SOUNDS.register(eventBus);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineItemModel;
|
|
||||||
|
|
||||||
public class BallistaItemGeoRenderer extends MachineItemGeoRenderer
|
|
||||||
{
|
|
||||||
public BallistaItemGeoRenderer()
|
|
||||||
{
|
|
||||||
super(new MachineItemModel<>("ballista"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineModel;
|
|
||||||
import magistu.siegemachines.entity.machine.Ballista;
|
|
||||||
import magistu.siegemachines.entity.machine.BatteringRam;
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
|
||||||
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class BatteringRamGeoRenderer extends MachineGeoRenderer<BatteringRam>
|
|
||||||
{
|
|
||||||
public BatteringRamGeoRenderer(EntityRendererManager renderManager)
|
|
||||||
{
|
|
||||||
super(renderManager, new MachineModel<>("battering_ram"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RenderType getRenderType(BatteringRam animatable, float partialTicks, MatrixStack stack,
|
|
||||||
IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn,
|
|
||||||
ResourceLocation textureLocation)
|
|
||||||
{
|
|
||||||
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineItemModel;
|
|
||||||
|
|
||||||
public class BatteringRamItemGeoRenderer extends MachineItemGeoRenderer
|
|
||||||
{
|
|
||||||
public BatteringRamItemGeoRenderer()
|
|
||||||
{
|
|
||||||
super(new MachineItemModel<>("battering_ram"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineModel;
|
|
||||||
import magistu.siegemachines.entity.machine.Catapult;
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
public class CatapultGeoRenderer extends MachineGeoRenderer<Catapult>
|
|
||||||
{
|
|
||||||
public CatapultGeoRenderer(EntityRendererManager renderManager)
|
|
||||||
{
|
|
||||||
super(renderManager, new MachineModel<>("catapult"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RenderType getRenderType(Catapult animatable, float partialTicks, MatrixStack stack,
|
|
||||||
IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn,
|
|
||||||
ResourceLocation textureLocation)
|
|
||||||
{
|
|
||||||
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineItemModel;
|
|
||||||
|
|
||||||
public class CatapultItemGeoRenderer extends MachineItemGeoRenderer
|
|
||||||
{
|
|
||||||
public CatapultItemGeoRenderer()
|
|
||||||
{
|
|
||||||
super(new MachineItemModel<>("catapult"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineModel;
|
|
||||||
import magistu.siegemachines.entity.machine.Culverin;
|
|
||||||
import magistu.siegemachines.entity.machine.Mortar;
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
|
||||||
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class CulverinGeoRenderer extends MachineGeoRenderer<Culverin>
|
|
||||||
{
|
|
||||||
public CulverinGeoRenderer(EntityRendererManager renderManager)
|
|
||||||
{
|
|
||||||
super(renderManager, new MachineModel<>("culverin"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RenderType getRenderType(Culverin animatable, float partialTicks, MatrixStack stack,
|
|
||||||
IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn,
|
|
||||||
ResourceLocation textureLocation)
|
|
||||||
{
|
|
||||||
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineItemModel;
|
|
||||||
|
|
||||||
public class CulverinItemGeoRenderer extends MachineItemGeoRenderer
|
|
||||||
{
|
|
||||||
public CulverinItemGeoRenderer()
|
|
||||||
{
|
|
||||||
super(new MachineItemModel<>("culverin"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import magistu.siegemachines.client.renderer.MachineGeoRenderer;
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineItemModel;
|
|
||||||
import magistu.siegemachines.entity.machine.Mortar;
|
|
||||||
import magistu.siegemachines.item.MachineItem;
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
|
||||||
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
|
||||||
import software.bernie.geckolib3.renderers.geo.GeoItemRenderer;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class MachineItemGeoRenderer extends GeoItemRenderer<MachineItem>
|
|
||||||
{
|
|
||||||
public MachineItemGeoRenderer(MachineItemModel<MachineItem> model)
|
|
||||||
{
|
|
||||||
super(model);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import magistu.siegemachines.client.renderer.MachineItemGeoRenderer;
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineItemModel;
|
|
||||||
|
|
||||||
public class MortarItemGeoRenderer extends MachineItemGeoRenderer
|
|
||||||
{
|
|
||||||
public MortarItemGeoRenderer()
|
|
||||||
{
|
|
||||||
super(new MachineItemModel<>("mortar"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineModel;
|
|
||||||
import magistu.siegemachines.entity.machine.Trebuchet;
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
|
||||||
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class TrebuchetGeoRenderer extends MachineGeoRenderer<Trebuchet>
|
|
||||||
{
|
|
||||||
public TrebuchetGeoRenderer(EntityRendererManager renderManager)
|
|
||||||
{
|
|
||||||
super(renderManager, new MachineModel<>("trebuchet"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RenderType getRenderType(Trebuchet animatable, float partialTicks, MatrixStack stack,
|
|
||||||
IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn,
|
|
||||||
ResourceLocation textureLocation)
|
|
||||||
{
|
|
||||||
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderEarly(Trebuchet animatable, MatrixStack stackIn, float ticks, IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float partialTicks)
|
|
||||||
{
|
|
||||||
GeoModelProvider<Trebuchet> modelProvider = this.getGeoModelProvider();
|
|
||||||
GeoModel model = modelProvider.getModel(modelProvider.getModelLocation(animatable));
|
|
||||||
|
|
||||||
Optional<GeoBone> projectile = model.getBone("Cobblestone");
|
|
||||||
int projectilesize = (animatable.state == Trebuchet.State.IDLE_RELOADED || animatable.shootingticks > 0) && animatable.hasAmmo() ? 1 : 0;
|
|
||||||
projectile.ifPresent(bone -> bone.setScaleX(projectilesize));
|
|
||||||
projectile.ifPresent(bone -> bone.setScaleY(projectilesize));
|
|
||||||
projectile.ifPresent(bone -> bone.setScaleZ(projectilesize));
|
|
||||||
|
|
||||||
super.renderEarly(animatable, stackIn, ticks, renderTypeBuffer, vertexBuilder, packedLightIn, packedOverlayIn, red, green, blue, partialTicks);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
|
||||||
|
|
||||||
import magistu.siegemachines.client.renderer.MachineItemGeoRenderer;
|
|
||||||
import magistu.siegemachines.client.renderer.model.MachineItemModel;
|
|
||||||
|
|
||||||
public class TrebuchetItemGeoRenderer extends MachineItemGeoRenderer
|
|
||||||
{
|
|
||||||
public TrebuchetItemGeoRenderer()
|
|
||||||
{
|
|
||||||
super(new MachineItemModel<>("trebuchet"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer.model;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.model.Model;
|
|
||||||
import net.minecraft.client.renderer.model.ModelRenderer;
|
|
||||||
|
|
||||||
public class GiantArrowModel extends Model
|
|
||||||
{
|
|
||||||
private final ModelRenderer cube_r0;
|
|
||||||
private final ModelRenderer cube_r1;
|
|
||||||
private final ModelRenderer cube_r2;
|
|
||||||
|
|
||||||
public GiantArrowModel()
|
|
||||||
{
|
|
||||||
super(RenderType::entityCutout);
|
|
||||||
texWidth = 64;
|
|
||||||
texHeight = 64;
|
|
||||||
|
|
||||||
cube_r0 = new ModelRenderer(this);
|
|
||||||
cube_r0.setPos(0.0F, 0.0F, 0.0F);
|
|
||||||
setRotationAngle(cube_r0, 0.0F, 0.0F, 0.0F);
|
|
||||||
|
|
||||||
cube_r1 = new ModelRenderer(this);
|
|
||||||
cube_r1.setPos(0.0F, 0.0F, 3.0F);
|
|
||||||
cube_r0.addChild(cube_r1);
|
|
||||||
setRotationAngle(cube_r1, 0.0F, 0.0F, -0.7854F);
|
|
||||||
cube_r1.texOffs(15, 0).addBox(-2.0F, 0.0F, -10.0F, 4.0F, 0.0F, 4.0F, 0.0F, false);
|
|
||||||
cube_r1.texOffs(-34, 0).addBox(-2.5F, 0.0F, -7.0F, 5.0F, 0.0F, 34.0F, 0.0F, false);
|
|
||||||
|
|
||||||
cube_r2 = new ModelRenderer(this);
|
|
||||||
cube_r2.setPos(0.0F, 0.0F, 3.0F);
|
|
||||||
cube_r0.addChild(cube_r2);
|
|
||||||
setRotationAngle(cube_r2, 0.0F, 0.0F, 0.7854F);
|
|
||||||
cube_r2.texOffs(7, 0).addBox(-2.0F, 0.0F, -10.0F, 4.0F, 0.0F, 4.0F, 0.0F, false);
|
|
||||||
cube_r2.texOffs(-34, 0).addBox(-2.5F, 0.0F, -7.0F, 5.0F, 0.0F, 34.0F, 0.0F, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setupAnim(float p_225603_1_, float p_225603_2_, float p_225603_3_)
|
|
||||||
{
|
|
||||||
this.cube_r0.yRot = p_225603_2_ * ((float)Math.PI / 180F);
|
|
||||||
this.cube_r0.xRot = p_225603_3_ * ((float)Math.PI / 180F);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z)
|
|
||||||
{
|
|
||||||
modelRenderer.xRot = x;
|
|
||||||
modelRenderer.yRot = y;
|
|
||||||
modelRenderer.zRot = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderToBuffer(MatrixStack p_225598_1_, IVertexBuilder p_225598_2_, int p_225598_3_, int p_225598_4_, float p_225598_5_, float p_225598_6_, float p_225598_7_, float p_225598_8_)
|
|
||||||
{
|
|
||||||
cube_r0.render(p_225598_1_, p_225598_2_, p_225598_3_, p_225598_4_, p_225598_5_, p_225598_6_, p_225598_7_, p_225598_8_);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer.model;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.item.MachineItem;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import software.bernie.geckolib3.core.IAnimatable;
|
|
||||||
import software.bernie.geckolib3.model.AnimatedGeoModel;
|
|
||||||
|
|
||||||
|
|
||||||
public class MachineItemModel<T extends MachineItem & IAnimatable> extends AnimatedGeoModel<T>
|
|
||||||
{
|
|
||||||
public final String name;
|
|
||||||
public final ResourceLocation animationlocation;
|
|
||||||
public final ResourceLocation modellocation;
|
|
||||||
public final ResourceLocation texturelocation;
|
|
||||||
|
|
||||||
public MachineItemModel(String name)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
this.animationlocation = new ResourceLocation(SiegeMachines.ID, "animations/none.animation.json");
|
|
||||||
this.modellocation = new ResourceLocation(SiegeMachines.ID, "geo/" + this.name + "_item.geo.json");
|
|
||||||
this.texturelocation = new ResourceLocation(SiegeMachines.ID, "textures/entity/" + this.name + ".png");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getAnimationFileLocation(T entity)
|
|
||||||
{
|
|
||||||
return this.animationlocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getModelLocation(T entity)
|
|
||||||
{
|
|
||||||
return this.modellocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getTextureLocation(T entity)
|
|
||||||
{
|
|
||||||
return this.texturelocation;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package magistu.siegemachines.client.renderer.model;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import software.bernie.geckolib3.core.IAnimatable;
|
|
||||||
import software.bernie.geckolib3.model.AnimatedGeoModel;
|
|
||||||
|
|
||||||
|
|
||||||
public class MachineModel<T extends Machine & IAnimatable> extends AnimatedGeoModel<T>
|
|
||||||
{
|
|
||||||
public final String name;
|
|
||||||
public final ResourceLocation animationlocation;
|
|
||||||
public final ResourceLocation modellocation;
|
|
||||||
public final ResourceLocation texturelocation;
|
|
||||||
|
|
||||||
public MachineModel(String name)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
this.animationlocation = new ResourceLocation(SiegeMachines.ID, "animations/" + this.name + ".animation.json");
|
|
||||||
this.modellocation = new ResourceLocation(SiegeMachines.ID, "geo/" + this.name + ".geo.json");
|
|
||||||
this.texturelocation = new ResourceLocation(SiegeMachines.ID, "textures/entity/" + this.name + ".png");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getAnimationFileLocation(T entity)
|
|
||||||
{
|
|
||||||
return this.animationlocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getModelLocation(T entity)
|
|
||||||
{
|
|
||||||
return this.modellocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getTextureLocation(T entity)
|
|
||||||
{
|
|
||||||
return this.texturelocation;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package magistu.siegemachines.data.recipes;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import net.minecraft.inventory.CraftingInventory;
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
|
||||||
import net.minecraft.item.crafting.IRecipeType;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public interface ISiegeWorkbenchRecipe extends IRecipe<CraftingInventory>
|
|
||||||
{
|
|
||||||
ResourceLocation TYPE_ID = new ResourceLocation(SiegeMachines.ID, "siege_workbench");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default @NotNull IRecipeType<?> getType(){
|
|
||||||
return Registry.RECIPE_TYPE.getOptional(TYPE_ID).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default boolean canCraftInDimensions(int width, int height)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default boolean isSpecial()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package magistu.siegemachines.data.recipes;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
|
||||||
import net.minecraft.item.crafting.IRecipeType;
|
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.fml.RegistryObject;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
|
|
||||||
public class ModRecipes
|
|
||||||
{
|
|
||||||
public static final DeferredRegister<IRecipeSerializer<?>> RECIPE_SERIALIZER = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, SiegeMachines.ID);
|
|
||||||
public static final RegistryObject<SiegeWorkbenchRecipe.Serializer> SIEGE_WORKBENCH_SERIALIZER = RECIPE_SERIALIZER.register("siege_workbench", SiegeWorkbenchRecipe.Serializer::new);
|
|
||||||
|
|
||||||
public static IRecipeType<SiegeWorkbenchRecipe> SIEGE_WORKBENCH_RECIPE = new SiegeWorkbenchRecipe.SiegeWorkbenchRecipeType();
|
|
||||||
|
|
||||||
public static void register(IEventBus eventBus)
|
|
||||||
{
|
|
||||||
RECIPE_SERIALIZER.register(eventBus);
|
|
||||||
|
|
||||||
Registry.register(Registry.RECIPE_TYPE, SiegeWorkbenchRecipe.TYPE_ID, SIEGE_WORKBENCH_RECIPE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,580 +0,0 @@
|
|||||||
package magistu.siegemachines.data.recipes;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.gson.*;
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.block.ModBlocks;
|
|
||||||
import net.minecraft.inventory.CraftingInventory;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.*;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.tags.ITag;
|
|
||||||
import net.minecraft.tags.TagCollectionManager;
|
|
||||||
import net.minecraft.util.JSONUtils;
|
|
||||||
import net.minecraft.util.NonNullList;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import java.util.stream.StreamSupport;
|
|
||||||
|
|
||||||
|
|
||||||
public class SiegeWorkbenchRecipe implements ISiegeWorkbenchRecipe, net.minecraftforge.common.crafting.IShapedRecipe<CraftingInventory>
|
|
||||||
{
|
|
||||||
static int MAX_WIDTH = 3;
|
|
||||||
static int MAX_HEIGHT = 3;
|
|
||||||
/**
|
|
||||||
* Expand the max width and height allowed in the deserializer.
|
|
||||||
* This should be called by modders who add custom crafting tables that are larger than the vanilla 3x3.
|
|
||||||
* @param width your max recipe width
|
|
||||||
* @param height your max recipe height
|
|
||||||
*/
|
|
||||||
public static void setCraftingSize(int width, int height)
|
|
||||||
{
|
|
||||||
if (MAX_WIDTH < width) MAX_WIDTH = width;
|
|
||||||
if (MAX_HEIGHT < height) MAX_HEIGHT = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final int width;
|
|
||||||
private final int height;
|
|
||||||
private final NonNullList<Ingredient> recipeItems;
|
|
||||||
private final ItemStack result;
|
|
||||||
private final ResourceLocation id;
|
|
||||||
private final String group;
|
|
||||||
|
|
||||||
public SiegeWorkbenchRecipe(ResourceLocation p_i48162_1_, String p_i48162_2_, int p_i48162_3_, int p_i48162_4_, NonNullList<Ingredient> p_i48162_5_, ItemStack p_i48162_6_)
|
|
||||||
{
|
|
||||||
this.id = p_i48162_1_;
|
|
||||||
this.group = p_i48162_2_;
|
|
||||||
this.width = p_i48162_3_;
|
|
||||||
this.height = p_i48162_4_;
|
|
||||||
this.recipeItems = p_i48162_5_;
|
|
||||||
this.result = p_i48162_6_;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SiegeWorkbenchRecipeType implements IRecipeType<SiegeWorkbenchRecipe>
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return SiegeWorkbenchRecipe.TYPE_ID.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceLocation getId()
|
|
||||||
{
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRecipeSerializer<?> getSerializer()
|
|
||||||
{
|
|
||||||
return ModRecipes.SIEGE_WORKBENCH_SERIALIZER.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGroup()
|
|
||||||
{
|
|
||||||
return this.group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getResultItem()
|
|
||||||
{
|
|
||||||
return this.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull NonNullList<Ingredient> getIngredients()
|
|
||||||
{
|
|
||||||
return this.recipeItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canCraftInDimensions(int p_194133_1_, int p_194133_2_)
|
|
||||||
{
|
|
||||||
return p_194133_1_ >= this.width && p_194133_2_ >= this.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean testIngredient(Ingredient ingredient, @Nullable ItemStack p_test_1_)
|
|
||||||
{
|
|
||||||
if (p_test_1_ == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ingredient.getItems().length == 0)
|
|
||||||
{
|
|
||||||
return p_test_1_.isEmpty();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (ItemStack itemstack : ingredient.getItems())
|
|
||||||
{
|
|
||||||
if (itemstack.getItem() == p_test_1_.getItem() && itemstack.getCount() == p_test_1_.getCount())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(CraftingInventory p_77569_1_, World p_77569_2_)
|
|
||||||
{
|
|
||||||
for (int i = 0; i <= p_77569_1_.getWidth() - this.width; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j <= p_77569_1_.getHeight() - this.height; ++j)
|
|
||||||
{
|
|
||||||
if (this.matches(p_77569_1_, i, j, true))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.matches(p_77569_1_, i, j, false))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean matches(CraftingInventory p_77573_1_, int p_77573_2_, int p_77573_3_, boolean p_77573_4_)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < p_77573_1_.getWidth(); ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < p_77573_1_.getHeight(); ++j)
|
|
||||||
{
|
|
||||||
int k = i - p_77573_2_;
|
|
||||||
int l = j - p_77573_3_;
|
|
||||||
Ingredient ingredient = Ingredient.EMPTY;
|
|
||||||
if (k >= 0 && l >= 0 && k < this.width && l < this.height)
|
|
||||||
{
|
|
||||||
if (p_77573_4_)
|
|
||||||
{
|
|
||||||
ingredient = this.recipeItems.get(this.width - k - 1 + l * this.width);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ingredient = this.recipeItems.get(k + l * this.width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ItemStack itemstack = p_77573_1_.getItem(i + j * p_77573_1_.getWidth());
|
|
||||||
|
|
||||||
if (!this.testIngredient(ingredient, itemstack))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack assemble(CraftingInventory p_77572_1_)
|
|
||||||
{
|
|
||||||
return this.getResultItem().copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWidth()
|
|
||||||
{
|
|
||||||
return this.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRecipeWidth()
|
|
||||||
{
|
|
||||||
return getWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeight()
|
|
||||||
{
|
|
||||||
return this.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRecipeHeight()
|
|
||||||
{
|
|
||||||
return getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ItemStack getToastSymbol()
|
|
||||||
{
|
|
||||||
return new ItemStack(ModBlocks.SIEGE_WORKBENCH.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static NonNullList<Ingredient> dissolvePattern(String[] p_192402_0_, Map<String, Ingredient> p_192402_1_, int p_192402_2_, int p_192402_3_)
|
|
||||||
{
|
|
||||||
NonNullList<Ingredient> nonnulllist = NonNullList.withSize(p_192402_2_ * p_192402_3_, Ingredient.EMPTY);
|
|
||||||
Set<String> set = Sets.newHashSet(p_192402_1_.keySet());
|
|
||||||
set.remove(" ");
|
|
||||||
|
|
||||||
for (int i = 0; i < p_192402_0_.length; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < p_192402_0_[i].length(); ++j)
|
|
||||||
{
|
|
||||||
String s = p_192402_0_[i].substring(j, j + 1);
|
|
||||||
Ingredient ingredient = p_192402_1_.get(s);
|
|
||||||
if (ingredient == null)
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Pattern references symbol '" + s + "' but it's not defined in the key");
|
|
||||||
}
|
|
||||||
|
|
||||||
set.remove(s);
|
|
||||||
nonnulllist.set(j + p_192402_2_ * i, ingredient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!set.isEmpty())
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + set);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return nonnulllist;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static String[] shrink(String... p_194134_0_)
|
|
||||||
{
|
|
||||||
int i = Integer.MAX_VALUE;
|
|
||||||
int j = 0;
|
|
||||||
int k = 0;
|
|
||||||
int l = 0;
|
|
||||||
|
|
||||||
for (int i1 = 0; i1 < p_194134_0_.length; ++i1)
|
|
||||||
{
|
|
||||||
String s = p_194134_0_[i1];
|
|
||||||
i = Math.min(i, firstNonSpace(s));
|
|
||||||
int j1 = lastNonSpace(s);
|
|
||||||
j = Math.max(j, j1);
|
|
||||||
if (j1 < 0)
|
|
||||||
{
|
|
||||||
if (k == i1)
|
|
||||||
{
|
|
||||||
++k;
|
|
||||||
}
|
|
||||||
|
|
||||||
++l;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
l = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_194134_0_.length == l)
|
|
||||||
{
|
|
||||||
return new String[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String[] astring = new String[p_194134_0_.length - l - k];
|
|
||||||
|
|
||||||
for (int k1 = 0; k1 < astring.length; ++k1)
|
|
||||||
{
|
|
||||||
astring[k1] = p_194134_0_[k1 + k].substring(i, j + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return astring;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int firstNonSpace(String p_194135_0_)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < p_194135_0_.length() && p_194135_0_.charAt(i) == ' '; ++i)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int lastNonSpace(String p_194136_0_)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = p_194136_0_.length() - 1; i >= 0 && p_194136_0_.charAt(i) == ' '; --i)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String[] patternFromJson(JsonArray p_192407_0_)
|
|
||||||
{
|
|
||||||
String[] astring = new String[p_192407_0_.size()];
|
|
||||||
if (astring.length > MAX_HEIGHT)
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Invalid pattern: too many rows, " + MAX_HEIGHT + " is maximum");
|
|
||||||
} else if (astring.length == 0)
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int i = 0; i < astring.length; ++i)
|
|
||||||
{
|
|
||||||
String s = JSONUtils.convertToString(p_192407_0_.get(i), "pattern[" + i + "]");
|
|
||||||
if (s.length() > MAX_WIDTH)
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Invalid pattern: too many columns, " + MAX_WIDTH + " is maximum");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i > 0 && astring[0].length() != s.length())
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Invalid pattern: each row must be the same width");
|
|
||||||
}
|
|
||||||
|
|
||||||
astring[i] = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return astring;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TagStackList extends Ingredient.TagList
|
|
||||||
{
|
|
||||||
private final int count;
|
|
||||||
|
|
||||||
public TagStackList(ITag<Item> p_i48193_1_, int count)
|
|
||||||
{
|
|
||||||
super(p_i48193_1_);
|
|
||||||
this.count = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<ItemStack> getItems()
|
|
||||||
{
|
|
||||||
Collection<ItemStack> list = super.getItems();
|
|
||||||
list.forEach(ele -> ele.setCount(this.count));
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull JsonObject serialize()
|
|
||||||
{
|
|
||||||
JsonObject jsonobject = super.serialize();
|
|
||||||
return jsonobject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Ingredient.IItemList valueFromJson(JsonObject p_199803_0_)
|
|
||||||
{
|
|
||||||
int count = JSONUtils.getAsInt(p_199803_0_, "count", 1);
|
|
||||||
if (p_199803_0_.has("item") && p_199803_0_.has("tag"))
|
|
||||||
{
|
|
||||||
throw new JsonParseException("An ingredient entry is either a tag or an item, not both");
|
|
||||||
}
|
|
||||||
else if (p_199803_0_.has("item"))
|
|
||||||
{
|
|
||||||
ResourceLocation resourcelocation1 = new ResourceLocation(JSONUtils.getAsString(p_199803_0_, "item"));
|
|
||||||
Item item = Registry.ITEM.getOptional(resourcelocation1).orElseThrow(() -> new JsonSyntaxException("Unknown item '" + resourcelocation1 + "'"));
|
|
||||||
return new Ingredient.SingleItemList(new ItemStack(item, count));
|
|
||||||
}
|
|
||||||
else if (p_199803_0_.has("tag"))
|
|
||||||
{
|
|
||||||
ResourceLocation resourcelocation = new ResourceLocation(JSONUtils.getAsString(p_199803_0_, "tag"));
|
|
||||||
ITag<Item> itag = TagCollectionManager.getInstance().getItems().getTag(resourcelocation);
|
|
||||||
if (itag == null)
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Unknown item tag '" + resourcelocation + "'");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new TagStackList(itag, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new JsonParseException("An ingredient entry needs either a tag or an item");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// public static class CompoundIngredientE extends CompoundIngredient
|
|
||||||
// {
|
|
||||||
// protected CompoundIngredientE(List<Ingredient> children)
|
|
||||||
// {
|
|
||||||
// super(children);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// public static Ingredient getIngredient(JsonElement json)
|
|
||||||
// {
|
|
||||||
// if (json == null || json.isJsonNull())
|
|
||||||
// throw new JsonSyntaxException("Json cannot be null");
|
|
||||||
//
|
|
||||||
// if (json.isJsonArray())
|
|
||||||
// {
|
|
||||||
// List<Ingredient> ingredients = Lists.newArrayList();
|
|
||||||
// List<Ingredient> vanilla = Lists.newArrayList();
|
|
||||||
// json.getAsJsonArray().forEach((ele) ->
|
|
||||||
// {
|
|
||||||
// Ingredient ing = getIngredient(ele);
|
|
||||||
//
|
|
||||||
// if (ing.getClass() == Ingredient.class) //Vanilla, Due to how we read it splits each itemstack, so we pull out to re-merge later
|
|
||||||
// vanilla.add(ing);
|
|
||||||
// else
|
|
||||||
// ingredients.add(ing);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// if (!vanilla.isEmpty())
|
|
||||||
// ingredients.add(Ingredient.merge(vanilla));
|
|
||||||
//
|
|
||||||
// if (ingredients.size() == 0)
|
|
||||||
// throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
|
|
||||||
//
|
|
||||||
// if (ingredients.size() == 1)
|
|
||||||
// return ingredients.get(0);
|
|
||||||
//
|
|
||||||
// return new CompoundIngredientE(ingredients);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (!json.isJsonObject())
|
|
||||||
// throw new JsonSyntaxException("Expcted ingredient to be a object or array of objects");
|
|
||||||
//
|
|
||||||
// JsonObject obj = (JsonObject)json;
|
|
||||||
//
|
|
||||||
// String type = JSONUtils.getAsString(obj, "type", "minecraft:item");
|
|
||||||
// if (type.isEmpty())
|
|
||||||
// throw new JsonSyntaxException("Ingredient type can not be an empty string");
|
|
||||||
//
|
|
||||||
// IIngredientSerializer<?> serializer = ingredients.get(new ResourceLocation(type));
|
|
||||||
// if (serializer == null)
|
|
||||||
// throw new JsonSyntaxException("Unknown ingredient type: " + type);
|
|
||||||
//
|
|
||||||
// return serializer.parse(obj);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public static Ingredient ingredientFromJson(@Nullable JsonElement p_199802_0_)
|
|
||||||
{
|
|
||||||
if (p_199802_0_ != null && !p_199802_0_.isJsonNull())
|
|
||||||
{
|
|
||||||
// Ingredient ret = CraftingHelper.getIngredient(p_199802_0_);
|
|
||||||
// if (ret != null) return ret;
|
|
||||||
|
|
||||||
if (p_199802_0_.isJsonObject())
|
|
||||||
{
|
|
||||||
return Ingredient.fromValues(Stream.of(valueFromJson(p_199802_0_.getAsJsonObject())));
|
|
||||||
}
|
|
||||||
else if (p_199802_0_.isJsonArray())
|
|
||||||
{
|
|
||||||
JsonArray jsonarray = p_199802_0_.getAsJsonArray();
|
|
||||||
if (jsonarray.size() == 0)
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Ingredient.fromValues(StreamSupport.stream(jsonarray.spliterator(), false).map((p_209355_0_) -> valueFromJson(JSONUtils.convertToJsonObject(p_209355_0_, "item"))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Expected item to be object or array of objects");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Item cannot be null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Map<String, Ingredient> keyFromJson(JsonObject p_192408_0_)
|
|
||||||
{
|
|
||||||
Map<String, Ingredient> map = Maps.newHashMap();
|
|
||||||
|
|
||||||
for (Map.Entry<String, JsonElement> entry : p_192408_0_.entrySet())
|
|
||||||
{
|
|
||||||
if (entry.getKey().length() != 1)
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only).");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (" ".equals(entry.getKey()))
|
|
||||||
{
|
|
||||||
throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ingredient ingredient = ingredientFromJson(entry.getValue());
|
|
||||||
|
|
||||||
map.put(entry.getKey(), ingredient);
|
|
||||||
}
|
|
||||||
|
|
||||||
map.put(" ", Ingredient.EMPTY);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack itemFromJson(JsonObject p_199798_0_)
|
|
||||||
{
|
|
||||||
String s = JSONUtils.getAsString(p_199798_0_, "item");
|
|
||||||
Item item = Registry.ITEM.getOptional(new ResourceLocation(s)).orElseThrow(() -> new JsonSyntaxException("Unknown item '" + s + "'"));
|
|
||||||
if (p_199798_0_.has("data"))
|
|
||||||
{
|
|
||||||
throw new JsonParseException("Disallowed data tag found");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int i = JSONUtils.getAsInt(p_199798_0_, "count", 1);
|
|
||||||
return net.minecraftforge.common.crafting.CraftingHelper.getItemStack(p_199798_0_, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Serializer extends net.minecraftforge.registries.ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<SiegeWorkbenchRecipe>
|
|
||||||
{
|
|
||||||
private static final ResourceLocation NAME = new ResourceLocation(SiegeMachines.ID, "siege_workbench");
|
|
||||||
|
|
||||||
public SiegeWorkbenchRecipe fromJson(ResourceLocation p_199425_1_, JsonObject p_199425_2_)
|
|
||||||
{
|
|
||||||
String s = JSONUtils.getAsString(p_199425_2_, "group", "");
|
|
||||||
Map<String, Ingredient> map = SiegeWorkbenchRecipe.keyFromJson(JSONUtils.getAsJsonObject(p_199425_2_, "key"));
|
|
||||||
String[] astring = SiegeWorkbenchRecipe.shrink(SiegeWorkbenchRecipe.patternFromJson(JSONUtils.getAsJsonArray(p_199425_2_, "pattern")));
|
|
||||||
int i = astring[0].length();
|
|
||||||
int j = astring.length;
|
|
||||||
NonNullList<Ingredient> nonnulllist = SiegeWorkbenchRecipe.dissolvePattern(astring, map, i, j);
|
|
||||||
ItemStack itemstack = SiegeWorkbenchRecipe.itemFromJson(JSONUtils.getAsJsonObject(p_199425_2_, "result"));
|
|
||||||
return new SiegeWorkbenchRecipe(p_199425_1_, s, i, j, nonnulllist, itemstack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SiegeWorkbenchRecipe fromNetwork(ResourceLocation p_199426_1_, PacketBuffer p_199426_2_)
|
|
||||||
{
|
|
||||||
int i = p_199426_2_.readVarInt();
|
|
||||||
int j = p_199426_2_.readVarInt();
|
|
||||||
String s = p_199426_2_.readUtf(32767);
|
|
||||||
NonNullList<Ingredient> nonnulllist = NonNullList.withSize(i * j, Ingredient.EMPTY);
|
|
||||||
|
|
||||||
for (int k = 0; k < nonnulllist.size(); ++k)
|
|
||||||
{
|
|
||||||
nonnulllist.set(k, Ingredient.fromNetwork(p_199426_2_));
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack itemstack = p_199426_2_.readItem();
|
|
||||||
return new SiegeWorkbenchRecipe(p_199426_1_, s, i, j, nonnulllist, itemstack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toNetwork(PacketBuffer p_199427_1_, SiegeWorkbenchRecipe p_199427_2_)
|
|
||||||
{
|
|
||||||
p_199427_1_.writeVarInt(p_199427_2_.width);
|
|
||||||
p_199427_1_.writeVarInt(p_199427_2_.height);
|
|
||||||
p_199427_1_.writeUtf(p_199427_2_.group);
|
|
||||||
|
|
||||||
for (Ingredient ingredient : p_199427_2_.recipeItems)
|
|
||||||
{
|
|
||||||
ingredient.toNetwork(p_199427_1_);
|
|
||||||
}
|
|
||||||
|
|
||||||
p_199427_1_.writeItem(p_199427_2_.result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,326 +0,0 @@
|
|||||||
package magistu.siegemachines.entity;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|
||||||
import net.minecraft.block.AbstractFireBlock;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.enchantment.ProtectionEnchantment;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.item.ItemEntity;
|
|
||||||
import net.minecraft.entity.item.TNTEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
|
||||||
import net.minecraft.fluid.FluidState;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.loot.LootContext;
|
|
||||||
import net.minecraft.loot.LootParameters;
|
|
||||||
import net.minecraft.particles.ParticleTypes;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.DamageSource;
|
|
||||||
import net.minecraft.util.math.*;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
import net.minecraft.world.EntityExplosionContext;
|
|
||||||
import net.minecraft.world.Explosion;
|
|
||||||
import net.minecraft.world.ExplosionContext;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Breakdown
|
|
||||||
{
|
|
||||||
private static final ExplosionContext EXPLOSION_DAMAGE_CALCULATOR = new ExplosionContext();
|
|
||||||
private final boolean fire;
|
|
||||||
private final Explosion.Mode blockInteraction;
|
|
||||||
private final Random random = new Random();
|
|
||||||
private final World level;
|
|
||||||
private final double x;
|
|
||||||
private final double y;
|
|
||||||
private final double z;
|
|
||||||
@Nullable
|
|
||||||
private final Entity source;
|
|
||||||
private final float radius;
|
|
||||||
private final DamageSource damageSource;
|
|
||||||
private final ExplosionContext damageCalculator;
|
|
||||||
private final List<BlockPos> toBlow = Lists.newArrayList();
|
|
||||||
private final Map<PlayerEntity, Vector3d> hitPlayers = Maps.newHashMap();
|
|
||||||
private final Vector3d position;
|
|
||||||
private final Explosion explosion;
|
|
||||||
private final Entity machine;
|
|
||||||
private final float power;
|
|
||||||
|
|
||||||
public Breakdown(World p_i50007_1_, @Nullable Entity machine, @Nullable Entity p_i50007_2_, double p_i50007_3_, double p_i50007_5_, double p_i50007_7_, float p_i50007_9_, boolean p_i50007_10_, float power, Explosion.Mode p_i50007_11_) {
|
|
||||||
this(p_i50007_1_, p_i50007_2_, machine, (DamageSource)null, (ExplosionContext)null, p_i50007_3_, p_i50007_5_, p_i50007_7_, p_i50007_9_, p_i50007_10_, power, p_i50007_11_);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Breakdown(World p_i231610_1_, @Nullable Entity machine, @Nullable Entity p_i231610_2_, @Nullable DamageSource p_i231610_3_, @Nullable ExplosionContext p_i231610_4_, double p_i231610_5_, double p_i231610_7_, double p_i231610_9_, float p_i231610_11_, boolean p_i231610_12_, float power, Explosion.Mode p_i231610_13_) {
|
|
||||||
this.explosion = new Explosion(p_i231610_1_, p_i231610_2_, p_i231610_3_, p_i231610_4_, p_i231610_5_, p_i231610_7_, p_i231610_9_, p_i231610_11_, p_i231610_12_, p_i231610_13_);
|
|
||||||
this.level = p_i231610_1_;
|
|
||||||
this.machine = machine;
|
|
||||||
this.source = p_i231610_2_;
|
|
||||||
this.radius = p_i231610_11_;
|
|
||||||
this.x = p_i231610_5_;
|
|
||||||
this.y = p_i231610_7_;
|
|
||||||
this.z = p_i231610_9_;
|
|
||||||
this.fire = p_i231610_12_;
|
|
||||||
this.power = power;
|
|
||||||
this.blockInteraction = p_i231610_13_;
|
|
||||||
this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? DamageSource.explosion((LivingEntity) p_i231610_2_) : p_i231610_3_;
|
|
||||||
this.damageCalculator = p_i231610_4_ == null ? this.makeDamageCalculator(p_i231610_2_) : p_i231610_4_;
|
|
||||||
this.position = new Vector3d(this.x, this.y, this.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ExplosionContext makeDamageCalculator(@Nullable Entity p_234894_1_) {
|
|
||||||
return (ExplosionContext)(p_234894_1_ == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityExplosionContext(p_234894_1_));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getSeenPercent(Vector3d p_222259_0_, Entity p_222259_1_) {
|
|
||||||
AxisAlignedBB axisalignedbb = p_222259_1_.getBoundingBox();
|
|
||||||
double d0 = 1.0D / ((axisalignedbb.maxX - axisalignedbb.minX) * 2.0D + 1.0D);
|
|
||||||
double d1 = 1.0D / ((axisalignedbb.maxY - axisalignedbb.minY) * 2.0D + 1.0D);
|
|
||||||
double d2 = 1.0D / ((axisalignedbb.maxZ - axisalignedbb.minZ) * 2.0D + 1.0D);
|
|
||||||
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
|
|
||||||
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
|
|
||||||
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D)) {
|
|
||||||
int i = 0;
|
|
||||||
int j = 0;
|
|
||||||
|
|
||||||
for(float f = 0.0F; f <= 1.0F; f = (float)((double)f + d0)) {
|
|
||||||
for(float f1 = 0.0F; f1 <= 1.0F; f1 = (float)((double)f1 + d1)) {
|
|
||||||
for(float f2 = 0.0F; f2 <= 1.0F; f2 = (float)((double)f2 + d2)) {
|
|
||||||
double d5 = MathHelper.lerp((double)f, axisalignedbb.minX, axisalignedbb.maxX);
|
|
||||||
double d6 = MathHelper.lerp((double)f1, axisalignedbb.minY, axisalignedbb.maxY);
|
|
||||||
double d7 = MathHelper.lerp((double)f2, axisalignedbb.minZ, axisalignedbb.maxZ);
|
|
||||||
Vector3d vector3d = new Vector3d(d5 + d3, d6, d7 + d4);
|
|
||||||
if (p_222259_1_.level.clip(new RayTraceContext(vector3d, p_222259_0_, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, p_222259_1_)).getType() == RayTraceResult.Type.MISS) {
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
++j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (float)i / (float)j;
|
|
||||||
} else {
|
|
||||||
return 0.0F;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void explode()
|
|
||||||
{
|
|
||||||
Set<BlockPos> set = Sets.newHashSet();
|
|
||||||
int i = 16;
|
|
||||||
|
|
||||||
for(int j = 0; j < 16; ++j) {
|
|
||||||
for(int k = 0; k < 16; ++k) {
|
|
||||||
for(int l = 0; l < 16; ++l) {
|
|
||||||
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
|
|
||||||
double d0 = (double)((float)j / 15.0F * 2.0F - 1.0F);
|
|
||||||
double d1 = (double)((float)k / 15.0F * 2.0F - 1.0F);
|
|
||||||
double d2 = (double)((float)l / 15.0F * 2.0F - 1.0F);
|
|
||||||
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
|
|
||||||
d0 = d0 / d3;
|
|
||||||
d1 = d1 / d3;
|
|
||||||
d2 = d2 / d3;
|
|
||||||
float f = this.power * this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
|
|
||||||
double d4 = this.x;
|
|
||||||
double d6 = this.y;
|
|
||||||
double d8 = this.z;
|
|
||||||
|
|
||||||
for(float f1 = 0.3F; f > 0.0F; f -= this.power * 0.5F) {
|
|
||||||
BlockPos blockpos = new BlockPos(d4, d6, d8);
|
|
||||||
BlockState blockstate = this.level.getBlockState(blockpos);
|
|
||||||
FluidState fluidstate = this.level.getFluidState(blockpos);
|
|
||||||
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this.explosion, this.level, blockpos, blockstate, fluidstate);
|
|
||||||
if (optional.isPresent()) {
|
|
||||||
f -= (optional.get() + 0.3F) * 0.3F;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this.explosion, this.level, blockpos, blockstate, f)) {
|
|
||||||
set.add(blockpos);
|
|
||||||
}
|
|
||||||
|
|
||||||
d4 += d0 * (double)0.3F;
|
|
||||||
d6 += d1 * (double)0.3F;
|
|
||||||
d8 += d2 * (double)0.3F;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.toBlow.addAll(set);
|
|
||||||
float f2 = 1.5f * this.radius;
|
|
||||||
int k1 = MathHelper.floor(this.x - (double)f2 - 1.0D);
|
|
||||||
int l1 = MathHelper.floor(this.x + (double)f2 + 1.0D);
|
|
||||||
int i2 = MathHelper.floor(this.y - (double)f2 - 1.0D);
|
|
||||||
int i1 = MathHelper.floor(this.y + (double)f2 + 1.0D);
|
|
||||||
int j2 = MathHelper.floor(this.z - (double)f2 - 1.0D);
|
|
||||||
int j1 = MathHelper.floor(this.z + (double)f2 + 1.0D);
|
|
||||||
List<Entity> list = this.level.getEntities(this.source, new AxisAlignedBB((double)k1, (double)i2, (double)j2, (double)l1, (double)i1, (double)j1));
|
|
||||||
Vector3d vector3d = new Vector3d(this.x, this.y, this.z);
|
|
||||||
|
|
||||||
for(int k2 = 0; k2 < list.size(); ++k2) {
|
|
||||||
Entity entity = list.get(k2);
|
|
||||||
if (!entity.ignoreExplosion() && !entity.equals(this.machine) && !entity.equals(this.source)) {
|
|
||||||
double d12 = (MathHelper.sqrt(entity.distanceToSqr(vector3d)) / f2);
|
|
||||||
if (d12 <= 1.0D) {
|
|
||||||
double d5 = entity.getX() - this.x;
|
|
||||||
double d7 = (entity instanceof TNTEntity ? entity.getY() : entity.getEyeY()) - this.y;
|
|
||||||
double d9 = entity.getZ() - this.z;
|
|
||||||
double d13 = (double)MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
|
|
||||||
if (d13 != 0.0D) {
|
|
||||||
d5 = d5 / d13;
|
|
||||||
d7 = d7 / d13;
|
|
||||||
d9 = d9 / d13;
|
|
||||||
double d14 = (double)getSeenPercent(vector3d, entity);
|
|
||||||
double d10 = (1.0D - d12) * d14;
|
|
||||||
if (!(entity instanceof ItemEntity)) {
|
|
||||||
entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D)));
|
|
||||||
}
|
|
||||||
double d11 = d10;
|
|
||||||
if (entity instanceof LivingEntity) {
|
|
||||||
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity)entity, d10);
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
|
|
||||||
if (entity instanceof PlayerEntity) {
|
|
||||||
PlayerEntity playerentity = (PlayerEntity)entity;
|
|
||||||
if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.abilities.flying)) {
|
|
||||||
this.hitPlayers.put(playerentity, new Vector3d(d5 * d10, d7 * d10, d9 * d10));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void finalizeExplosion(boolean p_77279_1_) {
|
|
||||||
if (this.level.isClientSide) {
|
|
||||||
//this.level.playLocalSound(this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean flag = this.blockInteraction != Explosion.Mode.NONE;
|
|
||||||
if (p_77279_1_) {
|
|
||||||
if (!(this.radius < 2.0F) && flag) {
|
|
||||||
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
|
|
||||||
} else {
|
|
||||||
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flag) {
|
|
||||||
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
|
|
||||||
Collections.shuffle(this.toBlow, this.level.random);
|
|
||||||
|
|
||||||
for(BlockPos blockpos : this.toBlow) {
|
|
||||||
BlockState blockstate = this.level.getBlockState(blockpos);
|
|
||||||
Block block = blockstate.getBlock();
|
|
||||||
if (!blockstate.isAir(this.level, blockpos)) {
|
|
||||||
BlockPos blockpos1 = blockpos.immutable();
|
|
||||||
this.level.getProfiler().push("explosion_blocks");
|
|
||||||
if (this.level instanceof ServerWorld) {
|
|
||||||
TileEntity tileentity = blockstate.hasTileEntity() ? this.level.getBlockEntity(blockpos) : null;
|
|
||||||
LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld)this.level)).withRandom(this.level.random).withParameter(LootParameters.ORIGIN, Vector3d.atCenterOf(blockpos)).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withOptionalParameter(LootParameters.BLOCK_ENTITY, tileentity).withOptionalParameter(LootParameters.THIS_ENTITY, this.source);
|
|
||||||
if (this.blockInteraction == Explosion.Mode.DESTROY) {
|
|
||||||
lootcontext$builder.withParameter(LootParameters.EXPLOSION_RADIUS, this.radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
blockstate.getDrops(lootcontext$builder).forEach((p_229977_2_) -> {
|
|
||||||
addBlockDrops(objectarraylist, p_229977_2_, blockpos1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.level.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
|
|
||||||
this.level.getProfiler().pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Pair<ItemStack, BlockPos> pair : objectarraylist) {
|
|
||||||
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.fire) {
|
|
||||||
for(BlockPos blockpos2 : this.toBlow) {
|
|
||||||
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
|
|
||||||
this.level.setBlockAndUpdate(blockpos2, AbstractFireBlock.getState(this.level, blockpos2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> p_229976_0_, ItemStack p_229976_1_, BlockPos p_229976_2_) {
|
|
||||||
int i = p_229976_0_.size();
|
|
||||||
|
|
||||||
for(int j = 0; j < i; ++j) {
|
|
||||||
Pair<ItemStack, BlockPos> pair = p_229976_0_.get(j);
|
|
||||||
ItemStack itemstack = pair.getFirst();
|
|
||||||
if (ItemEntity.areMergable(itemstack, p_229976_1_)) {
|
|
||||||
ItemStack itemstack1 = ItemEntity.merge(itemstack, p_229976_1_, 16);
|
|
||||||
p_229976_0_.set(j, Pair.of(itemstack1, pair.getSecond()));
|
|
||||||
if (p_229976_1_.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p_229976_0_.add(Pair.of(p_229976_1_, p_229976_2_));
|
|
||||||
}
|
|
||||||
|
|
||||||
public DamageSource getDamageSource() {
|
|
||||||
return this.damageSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<PlayerEntity, Vector3d> getHitPlayers() {
|
|
||||||
return this.hitPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public LivingEntity getSourceMob() {
|
|
||||||
if (this.source == null) {
|
|
||||||
return null;
|
|
||||||
} else if (this.source instanceof TNTEntity) {
|
|
||||||
return ((TNTEntity)this.source).getOwner();
|
|
||||||
} else if (this.source instanceof LivingEntity) {
|
|
||||||
return (LivingEntity)this.source;
|
|
||||||
} else {
|
|
||||||
if (this.source instanceof ProjectileEntity) {
|
|
||||||
Entity entity = ((ProjectileEntity)this.source).getOwner();
|
|
||||||
if (entity instanceof LivingEntity) {
|
|
||||||
return (LivingEntity)entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearToBlow() {
|
|
||||||
this.toBlow.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<BlockPos> getToBlow() {
|
|
||||||
return this.toBlow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3d getPosition() {
|
|
||||||
return this.position;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Entity getExploder() {
|
|
||||||
return this.source;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package magistu.siegemachines.entity;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.entity.machine.*;
|
|
||||||
import magistu.siegemachines.entity.projectile.Cannonball;
|
|
||||||
import magistu.siegemachines.entity.projectile.GiantArrow;
|
|
||||||
import magistu.siegemachines.entity.projectile.GiantStone;
|
|
||||||
import magistu.siegemachines.entity.projectile.Stone;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EntityClassification;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.fml.RegistryObject;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
|
|
||||||
public class EntityTypes
|
|
||||||
{
|
|
||||||
public static final DeferredRegister<EntityType<?>> DEFERRED_REGISTER = DeferredRegister.create(ForgeRegistries.ENTITIES, SiegeMachines.ID);
|
|
||||||
|
|
||||||
public static final RegistryObject<EntityType<Cannonball>> CANNONBALL = addRegistry("cannonball", Cannonball::new, 0.5f, 0.5f, 8);
|
|
||||||
public static final RegistryObject<EntityType<Stone>> STONE = addRegistry("stone", Stone::new, 0.6f, 0.6f, 8);
|
|
||||||
public static final RegistryObject<EntityType<GiantStone>> GIANT_STONE = addRegistry("giant_stone", GiantStone::new, 1.1f, 1.1f, 8);
|
|
||||||
public static final RegistryObject<EntityType<GiantArrow>> GIANT_ARROW = addRegistry("giant_arrow", GiantArrow::new, 0.5f, 0.5f, 8, 20);
|
|
||||||
|
|
||||||
public static final RegistryObject<EntityType<Mortar>> MORTAR = addRegistry("mortar", Mortar::new, 2.0f, 1.0f, 8);
|
|
||||||
public static final RegistryObject<EntityType<Culverin>> CULVERIN = addRegistry("culverin", Culverin::new, 2.0f, 1.0f, 8);
|
|
||||||
public static final RegistryObject<EntityType<Trebuchet>> TREBUCHET = addRegistry("trebuchet", Trebuchet::new, 5.0f, 9.0f, 8);
|
|
||||||
public static final RegistryObject<EntityType<Catapult>> CATAPULT = addRegistry("catapult", Catapult::new, 3.0f, 3.0f, 8);
|
|
||||||
public static final RegistryObject<EntityType<Ballista>> BALLISTA = addRegistry("ballista", Ballista::new, 1.5f, 1.5f, 8);
|
|
||||||
public static final RegistryObject<EntityType<BatteringRam>> BATTERING_RAM = addRegistry("battering_ram", BatteringRam::new, 4.0f, 3.0f);
|
|
||||||
|
|
||||||
|
|
||||||
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.IFactory<T> constructor, float sizex, float sizey)
|
|
||||||
{
|
|
||||||
return DEFERRED_REGISTER.register(name, () -> EntityType.Builder.of(constructor, EntityClassification.MISC).sized(sizex, sizey).build(new ResourceLocation(SiegeMachines.ID, name).toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.IFactory<T> constructor, float sizex, float sizey, int trackingrange)
|
|
||||||
{
|
|
||||||
return DEFERRED_REGISTER.register(name, () -> EntityType.Builder.of(constructor, EntityClassification.MISC).clientTrackingRange(trackingrange).sized(sizex, sizey).build(new ResourceLocation(SiegeMachines.ID, name).toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.IFactory<T> constructor, float sizex, float sizey, int trackingrange, int updateinterval)
|
|
||||||
{
|
|
||||||
return DEFERRED_REGISTER.register(name, () -> EntityType.Builder.of(constructor, EntityClassification.MISC).clientTrackingRange(trackingrange).updateInterval(updateinterval).sized(sizex, sizey).build(new ResourceLocation(SiegeMachines.ID, name).toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void register(IEventBus eventBus)
|
|
||||||
{
|
|
||||||
DEFERRED_REGISTER.register(eventBus);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,862 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.machine;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.gui.MachineContainer;
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import magistu.siegemachines.network.PacketHandler;
|
|
||||||
import magistu.siegemachines.network.PacketMachine;
|
|
||||||
import net.minecraft.advancements.CriteriaTriggers;
|
|
||||||
import net.minecraft.block.HoneyBlock;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.MobEntity;
|
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
|
|
||||||
import net.minecraft.entity.ai.attributes.Attributes;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.entity.projectile.AbstractArrowEntity;
|
|
||||||
import net.minecraft.inventory.Inventory;
|
|
||||||
import net.minecraft.inventory.container.Container;
|
|
||||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
import net.minecraft.nbt.ListNBT;
|
|
||||||
import net.minecraft.particles.ParticleTypes;
|
|
||||||
import net.minecraft.potion.Effects;
|
|
||||||
import net.minecraft.util.*;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public abstract class Machine extends MobEntity implements INamedContainerProvider
|
|
||||||
{
|
|
||||||
public MachineInventory inventory;
|
|
||||||
|
|
||||||
public final MachineType type;
|
|
||||||
|
|
||||||
private float turretpitch = -25.0f;
|
|
||||||
private float turretpitchprev = this.turretpitch;
|
|
||||||
protected float turretpitchdest = this.turretpitch;
|
|
||||||
private float turretyaw = 0.0f;
|
|
||||||
private float turretyawprev = this.turretyaw;
|
|
||||||
protected float turretyawdest = this.turretyaw;
|
|
||||||
protected float yawdest = this.yRot;
|
|
||||||
|
|
||||||
public int useticks = -1;
|
|
||||||
public int delayticks;
|
|
||||||
protected int renderupdateticks = 0;
|
|
||||||
public int deploymentticks = 0;
|
|
||||||
|
|
||||||
protected Machine(EntityType<? extends MobEntity> entitytype, World level, MachineType type)
|
|
||||||
{
|
|
||||||
super(entitytype, level);
|
|
||||||
this.type = type;
|
|
||||||
this.delayticks = this.type.specs.delaytime.get();
|
|
||||||
inventory = new MachineInventory(this.type.containersize);
|
|
||||||
|
|
||||||
this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(type.specs.durability.get());
|
|
||||||
this.setHealth(type.specs.durability.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AttributeModifierMap.MutableAttribute setEntityAttributes(MachineType type)
|
|
||||||
{
|
|
||||||
return MobEntity.createMobAttributes()
|
|
||||||
.add(Attributes.MAX_HEALTH, type.specs.durability.get())
|
|
||||||
.add(Attributes.KNOCKBACK_RESISTANCE, 0.5F)
|
|
||||||
.add(Attributes.MOVEMENT_SPEED, 0.0D)
|
|
||||||
.add(Attributes.ATTACK_DAMAGE, 0.0D)
|
|
||||||
.add(Attributes.FOLLOW_RANGE, 0.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getMachineItemWithData()
|
|
||||||
{
|
|
||||||
ItemStack stack = new ItemStack(this.getMachineItem());
|
|
||||||
CompoundNBT nbt = this.saveWithoutId(new CompoundNBT());
|
|
||||||
nbt.remove("Pos");
|
|
||||||
nbt.remove("Motion");
|
|
||||||
nbt.remove("FallDistance");
|
|
||||||
nbt.remove("Fire");
|
|
||||||
nbt.remove("Air");
|
|
||||||
nbt.remove("OnGround");
|
|
||||||
nbt.remove("Invulnerable");
|
|
||||||
nbt.remove("PortalCooldown");
|
|
||||||
nbt.remove("UUID");
|
|
||||||
nbt.remove("Passengers");
|
|
||||||
nbt.remove("DelayTicks");
|
|
||||||
nbt.remove("UseTicks");
|
|
||||||
stack.addTagElement("EntityTag", nbt);
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInvulnerableTo(DamageSource damagesource)
|
|
||||||
{
|
|
||||||
return damagesource == DamageSource.CACTUS ||
|
|
||||||
damagesource == DamageSource.WITHER ||
|
|
||||||
damagesource == DamageSource.MAGIC ||
|
|
||||||
damagesource == DamageSource.DROWN ||
|
|
||||||
damagesource == DamageSource.STARVE ||
|
|
||||||
super.isInvulnerableTo(damagesource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float adjustDamage(DamageSource damagesource, float f)
|
|
||||||
{
|
|
||||||
if (damagesource.isFire())
|
|
||||||
{
|
|
||||||
f *= 1.5f;
|
|
||||||
}
|
|
||||||
if (damagesource.isExplosion())
|
|
||||||
{
|
|
||||||
f *= 1.25f;
|
|
||||||
}
|
|
||||||
if (damagesource.getEntity() instanceof AbstractArrowEntity)
|
|
||||||
{
|
|
||||||
f *= 0.5;
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Item getMachineItem();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick()
|
|
||||||
{
|
|
||||||
if (this.deploymentticks > 0)
|
|
||||||
{
|
|
||||||
this.deploymentticks--;
|
|
||||||
}
|
|
||||||
super.tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hurt(@NotNull DamageSource damagesource, float f)
|
|
||||||
{
|
|
||||||
if (!net.minecraftforge.common.ForgeHooks.onLivingAttack(this, damagesource, f)) return false;
|
|
||||||
if (damagesource.getEntity() instanceof PlayerEntity && !damagesource.isProjectile() && !damagesource.isExplosion() && !damagesource.isMagic() && this.getPassengers().isEmpty())
|
|
||||||
{
|
|
||||||
this.spawnAtLocation(this.getMachineItemWithData());
|
|
||||||
this.remove();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.isInvulnerableTo(damagesource))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (this.level.isClientSide)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (this.isDeadOrDying())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (damagesource.isFire() && this.hasEffect(Effects.FIRE_RESISTANCE))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
f = adjustDamage(damagesource, f);
|
|
||||||
|
|
||||||
this.noActionTime = 0;
|
|
||||||
|
|
||||||
this.animationSpeed = 1.5F;
|
|
||||||
boolean flag1 = true;
|
|
||||||
if ((float) this.invulnerableTime > 10.0F)
|
|
||||||
{
|
|
||||||
if (f <= this.lastHurt)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.actuallyHurt(damagesource, f - this.lastHurt);
|
|
||||||
this.lastHurt = f;
|
|
||||||
flag1 = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.lastHurt = f;
|
|
||||||
this.invulnerableTime = 20;
|
|
||||||
this.actuallyHurt(damagesource, f);
|
|
||||||
this.hurtDuration = 10;
|
|
||||||
this.hurtTime = this.hurtDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.hurtDir = 0.0F;
|
|
||||||
Entity entity1 = damagesource.getEntity();
|
|
||||||
if (entity1 != null)
|
|
||||||
{
|
|
||||||
if (entity1 instanceof LivingEntity)
|
|
||||||
{
|
|
||||||
this.setLastHurtByMob((LivingEntity) entity1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity1 instanceof PlayerEntity)
|
|
||||||
{
|
|
||||||
this.lastHurtByPlayerTime = 100;
|
|
||||||
this.lastHurtByPlayer = (PlayerEntity) entity1;
|
|
||||||
}
|
|
||||||
else if (entity1 instanceof net.minecraft.entity.passive.TameableEntity)
|
|
||||||
{
|
|
||||||
net.minecraft.entity.passive.TameableEntity wolfentity = (net.minecraft.entity.passive.TameableEntity) entity1;
|
|
||||||
if (wolfentity.isTame())
|
|
||||||
{
|
|
||||||
this.lastHurtByPlayerTime = 100;
|
|
||||||
LivingEntity livingentity = wolfentity.getOwner();
|
|
||||||
if (livingentity != null && livingentity.getType() == EntityType.PLAYER)
|
|
||||||
{
|
|
||||||
this.lastHurtByPlayer = (PlayerEntity) livingentity;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.lastHurtByPlayer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flag1)
|
|
||||||
{
|
|
||||||
if (damagesource instanceof EntityDamageSource && ((EntityDamageSource) damagesource).isThorns())
|
|
||||||
{
|
|
||||||
this.level.broadcastEntityEvent(this, (byte) 33);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
byte b0;
|
|
||||||
if (damagesource.isFire())
|
|
||||||
{
|
|
||||||
b0 = 37;
|
|
||||||
}
|
|
||||||
else if (damagesource == DamageSource.SWEET_BERRY_BUSH)
|
|
||||||
{
|
|
||||||
b0 = 44;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
b0 = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.level.broadcastEntityEvent(this, b0);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.markHurt();
|
|
||||||
|
|
||||||
if (entity1 != null)
|
|
||||||
{
|
|
||||||
double d1 = entity1.getX() - this.getX();
|
|
||||||
|
|
||||||
double d0;
|
|
||||||
for (d0 = entity1.getZ() - this.getZ(); d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D)
|
|
||||||
{
|
|
||||||
d1 = (Math.random() - Math.random()) * 0.01D;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.hurtDir = (float) (MathHelper.atan2(d0, d1) * (double) (180F / (float) Math.PI) - (double) this.yRot);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.hurtDir = (float) ((int) (Math.random() * 2.0D) * 180);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isDeadOrDying())
|
|
||||||
{
|
|
||||||
SoundEvent soundevent = this.getDeathSound();
|
|
||||||
if (flag1 && soundevent != null)
|
|
||||||
{
|
|
||||||
this.playSound(soundevent, this.getSoundVolume(), this.getVoicePitch());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.die(damagesource);
|
|
||||||
}
|
|
||||||
else if (flag1)
|
|
||||||
{
|
|
||||||
this.playHurtSound(damagesource);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity1 instanceof ServerPlayerEntity)
|
|
||||||
{
|
|
||||||
CriteriaTriggers.PLAYER_HURT_ENTITY.trigger((ServerPlayerEntity) entity1, this, damagesource, f, f, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
protected SoundEvent getHurtSound(@NotNull DamageSource p_184601_1_)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
protected SoundEvent getDeathSound()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull SoundEvent getFallDamageSound(int n)
|
|
||||||
{
|
|
||||||
return SoundEvents.WOOD_FALL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean removeWhenFarAway(double p_213397_1_)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public Entity getControllingPassenger()
|
|
||||||
{
|
|
||||||
return this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBeControlledByRider()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addAdditionalSaveData(@NotNull CompoundNBT nbt)
|
|
||||||
{
|
|
||||||
super.addAdditionalSaveData(nbt);
|
|
||||||
|
|
||||||
ListNBT listnbt = new ListNBT();
|
|
||||||
for(ItemStack itemstack : this.inventory.items)
|
|
||||||
{
|
|
||||||
CompoundNBT compoundnbt = new CompoundNBT();
|
|
||||||
if (!itemstack.isEmpty())
|
|
||||||
{
|
|
||||||
itemstack.save(compoundnbt);
|
|
||||||
}
|
|
||||||
listnbt.add(compoundnbt);
|
|
||||||
}
|
|
||||||
nbt.put("Items", listnbt);
|
|
||||||
nbt.put("TurretRotations", this.newFloatList(this.turretpitch, this.turretyaw));
|
|
||||||
nbt.putInt("DealyTicks", this.delayticks);
|
|
||||||
nbt.putInt("UseTicks", this.useticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void dropCustomDeathLoot(DamageSource p_213333_1_, int p_213333_2_, boolean p_213333_3_)
|
|
||||||
{
|
|
||||||
super.dropCustomDeathLoot(p_213333_1_, p_213333_2_, p_213333_3_);
|
|
||||||
this.dropWreckage(p_213333_1_, p_213333_2_, p_213333_3_);
|
|
||||||
this.inventory.items.forEach(this::spawnAtLocation);
|
|
||||||
this.inventory.removeAllItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void dropWreckage(DamageSource p_213333_1_, int p_213333_2_, boolean p_213333_3_)
|
|
||||||
{
|
|
||||||
if (p_213333_1_.isFire())
|
|
||||||
{
|
|
||||||
Arrays.stream(this.type.wreckage).forEach(itemstack -> {
|
|
||||||
if (itemstack.getItem().equals(Items.OAK_PLANKS))
|
|
||||||
{
|
|
||||||
itemstack = new ItemStack(Items.CHARCOAL, (int) (0.25f * new Random().nextInt(itemstack.getCount() + 1) - 1));
|
|
||||||
}
|
|
||||||
else if (!itemstack.getItem().equals(Items.STICK) && !itemstack.getItem().equals(ModItems.BEAM.get()))
|
|
||||||
{
|
|
||||||
itemstack.setCount(new Random().nextInt(itemstack.getCount() + 1) - 1);
|
|
||||||
}
|
|
||||||
spawnAtLocation(itemstack);
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Arrays.stream(this.type.wreckage).forEach(itemstack -> {
|
|
||||||
itemstack.setCount(new Random().nextInt(itemstack.getCount() + 1) - 1);
|
|
||||||
spawnAtLocation(itemstack);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove()
|
|
||||||
{
|
|
||||||
if (!this.removed && !this.dead)
|
|
||||||
{
|
|
||||||
this.dead = true;
|
|
||||||
this.level.broadcastEntityEvent(this, (byte)3);
|
|
||||||
}
|
|
||||||
super.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public void handleEntityEvent(byte p_70103_1_)
|
|
||||||
{
|
|
||||||
switch(p_70103_1_)
|
|
||||||
{
|
|
||||||
case 2:
|
|
||||||
case 33:
|
|
||||||
case 36:
|
|
||||||
case 37:
|
|
||||||
case 44:
|
|
||||||
boolean flag1 = p_70103_1_ == 33;
|
|
||||||
boolean flag2 = p_70103_1_ == 36;
|
|
||||||
boolean flag3 = p_70103_1_ == 37;
|
|
||||||
boolean flag = p_70103_1_ == 44;
|
|
||||||
this.animationSpeed = 1.5F;
|
|
||||||
this.invulnerableTime = 20;
|
|
||||||
this.hurtDuration = 10;
|
|
||||||
this.hurtTime = this.hurtDuration;
|
|
||||||
this.hurtDir = 0.0F;
|
|
||||||
if (flag1)
|
|
||||||
{
|
|
||||||
this.playSound(SoundEvents.THORNS_HIT, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
|
|
||||||
}
|
|
||||||
|
|
||||||
DamageSource damagesource;
|
|
||||||
if (flag3)
|
|
||||||
{
|
|
||||||
damagesource = DamageSource.ON_FIRE;
|
|
||||||
} else if (flag2)
|
|
||||||
{
|
|
||||||
damagesource = DamageSource.DROWN;
|
|
||||||
} else if (flag)
|
|
||||||
{
|
|
||||||
damagesource = DamageSource.SWEET_BERRY_BUSH;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
damagesource = DamageSource.GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundEvent soundevent1 = this.getHurtSound(damagesource);
|
|
||||||
if (soundevent1 != null)
|
|
||||||
{
|
|
||||||
this.playSound(soundevent1, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.hurt(DamageSource.GENERIC, 0.0F);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
SoundEvent soundevent = this.getDeathSound();
|
|
||||||
if (soundevent != null)
|
|
||||||
{
|
|
||||||
this.playSound(soundevent, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
|
|
||||||
}
|
|
||||||
this.setHealth(0.0F);
|
|
||||||
this.remove();
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
case 7:
|
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
case 10:
|
|
||||||
case 11:
|
|
||||||
case 12:
|
|
||||||
case 13:
|
|
||||||
case 14:
|
|
||||||
case 15:
|
|
||||||
case 16:
|
|
||||||
case 17:
|
|
||||||
case 18:
|
|
||||||
case 19:
|
|
||||||
case 20:
|
|
||||||
case 21:
|
|
||||||
case 22:
|
|
||||||
case 23:
|
|
||||||
case 24:
|
|
||||||
case 25:
|
|
||||||
case 26:
|
|
||||||
case 27:
|
|
||||||
case 28:
|
|
||||||
case 31:
|
|
||||||
case 32:
|
|
||||||
case 34:
|
|
||||||
case 35:
|
|
||||||
case 38:
|
|
||||||
case 39:
|
|
||||||
case 40:
|
|
||||||
case 41:
|
|
||||||
case 42:
|
|
||||||
case 43:
|
|
||||||
case 45:
|
|
||||||
case 53:
|
|
||||||
default:
|
|
||||||
super.handleEntityEvent(p_70103_1_);
|
|
||||||
break;
|
|
||||||
case 29:
|
|
||||||
case 30:
|
|
||||||
case 46:
|
|
||||||
int i = 128;
|
|
||||||
|
|
||||||
for (int j = 0; j < 128; ++j)
|
|
||||||
{
|
|
||||||
double d0 = (double) j / 127.0D;
|
|
||||||
float f = (this.random.nextFloat() - 0.5F) * 0.2F;
|
|
||||||
float f1 = (this.random.nextFloat() - 0.5F) * 0.2F;
|
|
||||||
float f2 = (this.random.nextFloat() - 0.5F) * 0.2F;
|
|
||||||
double d1 = MathHelper.lerp(d0, this.xo, this.getX()) + (this.random.nextDouble() - 0.5D) * (double) this.getBbWidth() * 2.0D;
|
|
||||||
double d2 = MathHelper.lerp(d0, this.yo, this.getY()) + this.random.nextDouble() * (double) this.getBbHeight();
|
|
||||||
double d3 = MathHelper.lerp(d0, this.zo, this.getZ()) + (this.random.nextDouble() - 0.5D) * (double) this.getBbWidth() * 2.0D;
|
|
||||||
this.level.addParticle(ParticleTypes.PORTAL, d1, d2, d3, (double) f, (double) f1, (double) f2);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 54:
|
|
||||||
HoneyBlock.showJumpParticles(this);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readAdditionalSaveData(@NotNull CompoundNBT nbt)
|
|
||||||
{
|
|
||||||
super.readAdditionalSaveData(nbt);
|
|
||||||
if (nbt.contains("Items", 9))
|
|
||||||
{
|
|
||||||
ListNBT listnbt = nbt.getList("Items", 10);
|
|
||||||
|
|
||||||
for(int i = 0; i < this.inventory.items.size(); ++i)
|
|
||||||
{
|
|
||||||
this.inventory.items.set(i, ItemStack.of(listnbt.getCompound(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nbt.contains("TurretRotations", 5))
|
|
||||||
{
|
|
||||||
ListNBT turretrotations = nbt.getList("TurretRotations", 5);
|
|
||||||
setTurretRotations(turretrotations.getFloat(0), turretrotations.getFloat(1));
|
|
||||||
}
|
|
||||||
if (nbt.contains("DealyTicks"))
|
|
||||||
{
|
|
||||||
this.delayticks = nbt.getInt("DealyTicks");
|
|
||||||
}
|
|
||||||
if (nbt.contains("UseTicks"))
|
|
||||||
{
|
|
||||||
this.useticks = nbt.getInt("UseTicks");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getGlobalTurretYaw()
|
|
||||||
{
|
|
||||||
return MathHelper.lerp(0.5f, this.yRotO, this.yRot) + MathHelper.lerp(0.5f, this.turretyawprev, this.turretyaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getYaw()
|
|
||||||
{
|
|
||||||
return this.yRot;
|
|
||||||
}
|
|
||||||
public void setYaw(float yaw)
|
|
||||||
{
|
|
||||||
this.yRot = yaw;
|
|
||||||
this.yRotO = this.yRot;
|
|
||||||
this.yBodyRot = this.yRot;
|
|
||||||
this.yHeadRot = this.yBodyRot;
|
|
||||||
|
|
||||||
this.setRot(this.yRot, this.xRot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getYawDest()
|
|
||||||
{
|
|
||||||
return this.yawdest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setYawDest(float yaw)
|
|
||||||
{
|
|
||||||
this.yawdest = yaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTurretPitch(float f)
|
|
||||||
{
|
|
||||||
return MathHelper.lerp(f, this.turretpitchprev, this.turretpitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTurretYaw(float f)
|
|
||||||
{
|
|
||||||
return MathHelper.lerp(f, this.turretyawprev, this.turretyaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTurretPitch()
|
|
||||||
{
|
|
||||||
return this.getTurretPitch(0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTurretYaw()
|
|
||||||
{
|
|
||||||
return this.getTurretYaw(0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTurretRotations(float pitch, float yaw)
|
|
||||||
{
|
|
||||||
this.turretpitchprev = this.turretpitch;
|
|
||||||
this.turretyawprev = this.turretyaw;
|
|
||||||
this.turretpitch = pitch;
|
|
||||||
this.turretyaw = yaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTurretPitchDest()
|
|
||||||
{
|
|
||||||
return this.turretpitchdest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTurretYawDest()
|
|
||||||
{
|
|
||||||
return this.turretyawdest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTurretRotationsDest(float pitch, float yaw)
|
|
||||||
{
|
|
||||||
this.turretpitchdest = pitch;
|
|
||||||
this.turretyawdest = yaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateMachineRender()
|
|
||||||
{
|
|
||||||
if (!this.level.isClientSide())
|
|
||||||
{
|
|
||||||
PacketHandler.sendPacketToAllInArea(new PacketMachine(
|
|
||||||
this.getId(),
|
|
||||||
this.delayticks,
|
|
||||||
this.useticks,
|
|
||||||
this.turretpitch,
|
|
||||||
this.turretyaw), this.blockPosition(), SiegeMachines.RENDER_UPDATE_RANGE_SQR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateYaw()
|
|
||||||
{
|
|
||||||
float newyaw = this.turn(this.getYaw(), this.getYawDest(), this.type.rotationspeed);
|
|
||||||
|
|
||||||
if (this.getYaw() != newyaw)
|
|
||||||
this.setYaw(newyaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateTurretRotations()
|
|
||||||
{
|
|
||||||
float newyaw = this.turn(this.getTurretYaw(), this.getTurretYawDest(), this.type.turretspeed, this.type.turretminyaw, this.type.turretmaxyaw);
|
|
||||||
boolean shouldrotate = this.checkYaw(newyaw, this.getTurretYaw(), this.type.turretspeed, this.type.turretminyaw, this.type.turretmaxyaw);
|
|
||||||
float newpitch = shouldrotate ? this.turn(this.getTurretPitch(), this.getTurretPitchDest(), this.type.turretspeed, this.type.turretminpitch, this.type.turretmaxpitch) : this.getTurretPitch();
|
|
||||||
|
|
||||||
if (this.turretpitch != newpitch || this.turretyaw != newyaw)
|
|
||||||
this.setTurretRotations(newpitch, newyaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkYaw(float yaw, float currentyaw, float speed, float minyaw, float maxuaw)
|
|
||||||
{
|
|
||||||
return !this.type.yawfirst || Math.abs(yaw - currentyaw) <= speed / 2 || yaw <= this.type.turretminyaw || yaw >= this.type.turretmaxyaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float turn(float rotation, float rotationdest, float speed)
|
|
||||||
{
|
|
||||||
return this.turn(rotation, rotationdest, speed, -180, 180);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float turn(float rotation, float rotationdest, float speed, float minrotation, float maxrotation)
|
|
||||||
{
|
|
||||||
boolean haslimit = maxrotation - minrotation < 360;
|
|
||||||
|
|
||||||
float deltarotation = rotationdest - rotation;
|
|
||||||
deltarotation = MathHelper.wrapDegrees(deltarotation);
|
|
||||||
|
|
||||||
float newrotation;
|
|
||||||
if (deltarotation > speed / 2)
|
|
||||||
{
|
|
||||||
newrotation = rotation + speed;
|
|
||||||
}
|
|
||||||
else if (deltarotation < -speed / 2)
|
|
||||||
{
|
|
||||||
newrotation = rotation - speed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newrotation = rotation + deltarotation / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (haslimit)
|
|
||||||
{
|
|
||||||
if (newrotation > -minrotation)
|
|
||||||
{
|
|
||||||
newrotation = -minrotation;
|
|
||||||
}
|
|
||||||
if (newrotation < -maxrotation)
|
|
||||||
{
|
|
||||||
newrotation = -maxrotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return newrotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static Vector3d applyRotations(Vector3d vec, double pitch, double yaw)
|
|
||||||
{
|
|
||||||
double d0 = vec.x * Math.cos(yaw) - vec.y * Math.sin(pitch) * Math.sin(yaw) - vec.z * Math.sin(yaw) * Math.cos(pitch);
|
|
||||||
double d1 = vec.y * Math.cos(pitch) - vec.z * Math.sin(pitch);
|
|
||||||
double d2 = vec.x * Math.sin(yaw) + vec.y * Math.sin(pitch) * Math.cos(yaw) + vec.z * Math.cos(yaw) * Math.cos(pitch);
|
|
||||||
return new Vector3d(d0, d1, d2);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected float getVolumeFromDist(float maxvolume, float maxdist, float dist)
|
|
||||||
{
|
|
||||||
return maxvolume * Math.max(maxdist - dist, 0.0f) / maxdist;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void use(PlayerEntity player);
|
|
||||||
|
|
||||||
public abstract void useRealise();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Container createMenu(int id, @NotNull PlayerInventory inv, @NotNull PlayerEntity player)
|
|
||||||
{
|
|
||||||
return new MachineContainer(id, inv, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openInventoryGui()
|
|
||||||
{
|
|
||||||
Entity passenger = this.getControllingPassenger();
|
|
||||||
if (passenger instanceof ServerPlayerEntity)
|
|
||||||
{
|
|
||||||
this.stopRiding();
|
|
||||||
NetworkHooks.openGui((ServerPlayerEntity) passenger, this, this.blockPosition());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Vector3d getDismountLocationForPassenger(LivingEntity entity)
|
|
||||||
{
|
|
||||||
double yaw = (this.getGlobalTurretYaw()) * Math.PI / 180.0;
|
|
||||||
|
|
||||||
return this.position().add(applyRotations(this.type.passengerpos, 0.0, yaw));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRiderSit()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void positionRider(@NotNull Entity entity)
|
|
||||||
{
|
|
||||||
IMoveCallback setpos = Entity::setPos;
|
|
||||||
if (this.hasPassenger(entity))
|
|
||||||
{
|
|
||||||
double yaw = (this.getGlobalTurretYaw()) * Math.PI / 180.0;
|
|
||||||
|
|
||||||
Vector3d pos = this.position().add(applyRotations(this.type.passengerpos, 0.0, yaw));
|
|
||||||
setpos.accept(entity, pos.x, pos.y, pos.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MachineInventory extends Inventory
|
|
||||||
{
|
|
||||||
private final int containersize;
|
|
||||||
public NonNullList<ItemStack> items;
|
|
||||||
|
|
||||||
public MachineInventory(int containersize)
|
|
||||||
{
|
|
||||||
this.containersize = containersize;
|
|
||||||
items = NonNullList.withSize(this.containersize, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getContainerSize()
|
|
||||||
{
|
|
||||||
return this.containersize;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ItemStack getItem(int id)
|
|
||||||
{
|
|
||||||
return this.items.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ItemStack removeItem(int id, int p_70298_2_)
|
|
||||||
{
|
|
||||||
return this.items.set(id, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ItemStack removeItemNoUpdate(int id)
|
|
||||||
{
|
|
||||||
return this.items.remove(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setItem(int id, @NotNull ItemStack item)
|
|
||||||
{
|
|
||||||
this.items.set(id, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setChanged()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean stillValid(@NotNull PlayerEntity player)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearContent()
|
|
||||||
{
|
|
||||||
this.items = NonNullList.withSize(this.containersize, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsItem(Item item)
|
|
||||||
{
|
|
||||||
return this.items.stream().anyMatch(itemstack -> itemstack.getItem().equals(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putItem(Item item)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < this.items.size(); ++i)
|
|
||||||
{
|
|
||||||
ItemStack itemstack = this.items.get(i);
|
|
||||||
if (itemstack.isEmpty())
|
|
||||||
{
|
|
||||||
this.items.set(i, new ItemStack(item));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (itemstack.getItem().equals(item) && itemstack.getCount() < itemstack.getMaxStackSize())
|
|
||||||
{
|
|
||||||
itemstack.setCount(itemstack.getCount() + 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int shrinkItem(Item item)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < this.containersize; ++i)
|
|
||||||
{
|
|
||||||
ItemStack itemstack = this.items.get(i);
|
|
||||||
if (itemstack.getItem().equals(item))
|
|
||||||
{
|
|
||||||
itemstack.shrink(1);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,96 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.machine;
|
|
||||||
|
|
||||||
import magistu.siegemachines.config.SiegeMachineSpecs;
|
|
||||||
import magistu.siegemachines.config.SpecsConfig;
|
|
||||||
import magistu.siegemachines.entity.projectile.ProjectileBuilder;
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
|
|
||||||
public enum MachineType
|
|
||||||
{
|
|
||||||
MORTAR(SpecsConfig.MORTAR, 18, 0.0f, 85.0f, 0.0f, 0.0f, 0.5f, 0.5f, true, 10, 10,
|
|
||||||
new Vector3d(-0.5, 0.0, -20.0).scale(1 / 16.0), new Vector3d(0.0, 17.0, 7.0).scale(1 / 16.0), new Vector3d(0.0, 0.0, 12.0).scale(1 / 16.0),
|
|
||||||
ProjectileBuilder.CANNON_AMMO, true,
|
|
||||||
new ItemStack[] {new ItemStack(Items.OAK_PLANKS, 2), new ItemStack(ModItems.BEAM.get(), 1), new ItemStack(Items.STICK, 5), new ItemStack(Items.IRON_NUGGET, 21)}),
|
|
||||||
CULVERIN(SpecsConfig.CULVERIN, 9, 0.0f, 85.0f, 0.0f, 0.0f, 0.5f, 0.5f, true, 10, 10,
|
|
||||||
new Vector3d(-0.5, 0.0, -20.0).scale(1 / 16.0), new Vector3d(0.0, 17.0, 7.0).scale(1 / 16.0), new Vector3d(0.0, 0.0, 12.0).scale(1 / 16.0),
|
|
||||||
ProjectileBuilder.CANNON_AMMO, true,
|
|
||||||
new ItemStack[] {new ItemStack(Items.OAK_PLANKS, 2), new ItemStack(ModItems.BEAM.get(), 1), new ItemStack(Items.STICK, 5), new ItemStack(Items.IRON_NUGGET, 21)}),
|
|
||||||
TREBUCHET(SpecsConfig.TREBUCHET, 9, -45.0f, 75.0f, 0.0f, 0.0f, 0.05f, 0.5f, true, 38, 137,
|
|
||||||
new Vector3d(-34.0, 0.0, -94.0).scale(1 / 16.0), new Vector3d(0.0, 19.0, -3.0), new Vector3d(0.0, 10.0, -1.0),
|
|
||||||
ProjectileBuilder.GIANT_THROWING_AMMO, false,
|
|
||||||
new ItemStack[] {new ItemStack(Items.OAK_PLANKS, 8), new ItemStack(ModItems.BEAM.get(), 12), new ItemStack(Items.STICK, 20), new ItemStack(Items.IRON_NUGGET, 36), new ItemStack(Items.COBBLESTONE, 2)}),
|
|
||||||
CATAPULT(SpecsConfig.CATAPULT, 9, 0.0f, 75.0f, 0.0f, 0.0f, 0.2f, 1.0f, true, 2, 10,
|
|
||||||
new Vector3d(30.0, 0.0, -40.0).scale(1 / 16.0), new Vector3d(0.0, 51.0, -5.0).scale(1 / 16.0), new Vector3d(0.0, 0.0, 0.0),
|
|
||||||
ProjectileBuilder.THROWING_AMMO, false,
|
|
||||||
new ItemStack[] {new ItemStack(Items.OAK_PLANKS, 5), new ItemStack(ModItems.BEAM.get(), 6), new ItemStack(Items.STICK, 10), new ItemStack(Items.IRON_NUGGET, 14)}),
|
|
||||||
BALLISTA(SpecsConfig.BALLISTA, 9, -30.0f, 60.0f, -180.0f, 180.0f, 0.0f, 3.0f, false, 1, 20,
|
|
||||||
new Vector3d(0.0, 0.0, -30.0).scale(1 / 16.0), new Vector3d(0.0, 22.5, 0.0).scale(1 / 16.0), new Vector3d(0.0, 0.0, 17.0).scale(1 / 16.0),
|
|
||||||
ProjectileBuilder.BALLISTA_AMMO, false,
|
|
||||||
new ItemStack[] {new ItemStack(Items.OAK_PLANKS, 2), new ItemStack(ModItems.BEAM.get(), 1), new ItemStack(Items.STICK, 5), new ItemStack(Items.IRON_NUGGET, 8)}),
|
|
||||||
BATTERING_RAM(SpecsConfig.BATTERING_RAM, 9, 0.0f, 0.0f, 0.0f, 0.0f, 0.1f, 0.0f, false, 5, 5,
|
|
||||||
new Vector3d(12.0, 0.0, -48.0).scale(1 / 16.0), new Vector3d(0.0, 26.0, 36.0).scale(1 / 16.0), new Vector3d(0.0, 0.0, 32.0).scale(1 / 16.0),
|
|
||||||
ProjectileBuilder.NO_AMMO, false,
|
|
||||||
new ItemStack[] {new ItemStack(Items.OAK_PLANKS, 6), new ItemStack(ModItems.BEAM.get(), 8), new ItemStack(Items.STICK, 12), new ItemStack(Items.IRON_NUGGET, 8)});
|
|
||||||
|
|
||||||
public final SiegeMachineSpecs specs;
|
|
||||||
public final int containersize;
|
|
||||||
public final float turretminpitch;
|
|
||||||
public final float turretmaxpitch;
|
|
||||||
public final float turretminyaw;
|
|
||||||
public final float turretmaxyaw;
|
|
||||||
public final float rotationspeed;
|
|
||||||
public final float turretspeed;
|
|
||||||
public final boolean yawfirst;
|
|
||||||
public final int userealisetime;
|
|
||||||
public final int usetime;
|
|
||||||
|
|
||||||
public final Vector3d passengerpos;
|
|
||||||
public final Vector3d turretpivot;
|
|
||||||
public final Vector3d turretvector;
|
|
||||||
|
|
||||||
public final ProjectileBuilder[] ammo;
|
|
||||||
public final boolean usesgunpowder;
|
|
||||||
|
|
||||||
public final ItemStack[] wreckage;
|
|
||||||
|
|
||||||
MachineType(
|
|
||||||
SiegeMachineSpecs specs,
|
|
||||||
int containersize,
|
|
||||||
float turretminpitch,
|
|
||||||
float turretmaxpitch,
|
|
||||||
float turretminyaw,
|
|
||||||
float turretmaxyaw,
|
|
||||||
float rotationspeed,
|
|
||||||
float turretspeed,
|
|
||||||
boolean yawfirst,
|
|
||||||
int shootingtime,
|
|
||||||
int usetime,
|
|
||||||
Vector3d passengerpos,
|
|
||||||
Vector3d turretpivot,
|
|
||||||
Vector3d turretvector,
|
|
||||||
ProjectileBuilder[] ammo,
|
|
||||||
boolean usesgunpowder,
|
|
||||||
ItemStack[] wreckage)
|
|
||||||
{
|
|
||||||
this.specs = specs;
|
|
||||||
this.containersize = containersize;
|
|
||||||
this.turretminpitch = turretminpitch;
|
|
||||||
this.turretmaxpitch = turretmaxpitch;
|
|
||||||
this.turretminyaw = turretminyaw;
|
|
||||||
this.turretmaxyaw = turretmaxyaw;
|
|
||||||
this.rotationspeed = rotationspeed;
|
|
||||||
this.turretspeed = turretspeed;
|
|
||||||
this.yawfirst = yawfirst;
|
|
||||||
this.userealisetime = shootingtime;
|
|
||||||
this.usetime = usetime;
|
|
||||||
this.passengerpos = passengerpos;
|
|
||||||
this.turretpivot = turretpivot;
|
|
||||||
this.turretvector = turretvector;
|
|
||||||
this.ammo = ammo;
|
|
||||||
this.usesgunpowder = usesgunpowder;
|
|
||||||
this.wreckage = wreckage;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.projectile;
|
|
||||||
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class Cannonball extends Missile
|
|
||||||
{
|
|
||||||
public Cannonball(EntityType<Cannonball> type, World level)
|
|
||||||
{
|
|
||||||
super(type, level);
|
|
||||||
this.item = ModItems.CANNONBALL.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cannonball(EntityType<Stone> entitytype, World level, Vector3d pos, LivingEntity entity, Item item)
|
|
||||||
{
|
|
||||||
super(entitytype, level, pos, entity, MissileType.CANNONBALL, item);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.projectile;
|
|
||||||
|
|
||||||
public enum FlightType
|
|
||||||
{
|
|
||||||
NONE,
|
|
||||||
AHEAD,
|
|
||||||
SPINNING
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.projectile;
|
|
||||||
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.entity.*;
|
|
||||||
import net.minecraft.entity.projectile.AbstractArrowEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.network.IPacket;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class GiantArrow extends AbstractArrowEntity
|
|
||||||
{
|
|
||||||
private final IPacket<?> spawningpacket = NetworkHooks.getEntitySpawningPacket(this);
|
|
||||||
|
|
||||||
public GiantArrow(EntityType<GiantArrow> type, World level)
|
|
||||||
{
|
|
||||||
super(type, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GiantArrow(EntityType<GiantArrow> entitytype, World level, Vector3d pos, LivingEntity entity, Item item)
|
|
||||||
{
|
|
||||||
super(entitytype, entity, level);
|
|
||||||
this.setPos(pos.x, pos.y, pos.z);
|
|
||||||
this.setBaseDamage(15.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull ItemStack getPickupItem()
|
|
||||||
{
|
|
||||||
return new ItemStack(ModItems.GIANT_ARROW.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull IPacket<?> getAddEntityPacket()
|
|
||||||
{
|
|
||||||
return spawningpacket;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.projectile;
|
|
||||||
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class GiantStone extends Missile
|
|
||||||
{
|
|
||||||
public GiantStone(EntityType<GiantStone> entitytype, World level)
|
|
||||||
{
|
|
||||||
super(entitytype, level);
|
|
||||||
this.item = ModItems.GIANT_STONE.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GiantStone(EntityType<GiantStone> entitytype, World level, Vector3d pos, LivingEntity entity, Item item)
|
|
||||||
{
|
|
||||||
super(entitytype, level, pos, entity, MissileType.GIANT_STONE, item);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.projectile;
|
|
||||||
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public interface IProjectileFactory<T extends ProjectileEntity>
|
|
||||||
{
|
|
||||||
T create(EntityType<T> entitytype, World level, Vector3d pos, LivingEntity entity, Item item);
|
|
||||||
}
|
|
@ -1,188 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.projectile;
|
|
||||||
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.ai.attributes.Attributes;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.projectile.ProjectileItemEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.particles.BlockParticleData;
|
|
||||||
import net.minecraft.network.IPacket;
|
|
||||||
import net.minecraft.particles.IParticleData;
|
|
||||||
import net.minecraft.util.*;
|
|
||||||
import net.minecraft.particles.ParticleTypes;
|
|
||||||
import net.minecraft.util.math.*;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
import net.minecraft.world.Explosion;
|
|
||||||
import net.minecraft.world.ExplosionContext;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public abstract class Missile extends ProjectileItemEntity
|
|
||||||
{
|
|
||||||
public MissileType type = MissileType.STONE;
|
|
||||||
public Item item = ModItems.STONE.get();
|
|
||||||
|
|
||||||
public Missile(EntityType<? extends Missile> entitytype, World level)
|
|
||||||
{
|
|
||||||
super(entitytype, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Missile(EntityType<? extends Missile> entitytype, World level, Vector3d pos, LivingEntity entity, MissileType type, Item item)
|
|
||||||
{
|
|
||||||
super(entitytype, entity, level);
|
|
||||||
this.type = type;
|
|
||||||
this.item = item;
|
|
||||||
this.setPos(pos.x, pos.y, pos.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Item getDefaultItem()
|
|
||||||
{
|
|
||||||
return this.item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull IPacket<?> getAddEntityPacket()
|
|
||||||
{
|
|
||||||
return NetworkHooks.getEntitySpawningPacket(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onHit(RayTraceResult result)
|
|
||||||
{
|
|
||||||
if (result.getType() == RayTraceResult.Type.ENTITY)
|
|
||||||
{
|
|
||||||
EntityRayTraceResult entityRTR = (EntityRayTraceResult)result;
|
|
||||||
Vector3d pos = entityRTR.getLocation();
|
|
||||||
Entity entity = entityRTR.getEntity();
|
|
||||||
float damage = this.type.specs.mass.get() * (float) this.getDeltaMovement().length();
|
|
||||||
|
|
||||||
DamageSource damagesource = DamageSource.thrown(this, this.getOwner());
|
|
||||||
if (this.type.armorpiercing >= 1.0f)
|
|
||||||
{
|
|
||||||
damagesource = damagesource.bypassArmor();
|
|
||||||
}
|
|
||||||
else if (this.type.armorpiercing > 0.0f && entity instanceof LivingEntity)
|
|
||||||
{
|
|
||||||
LivingEntity livingentity = (LivingEntity) entity;
|
|
||||||
damage -= (1.0f - this.type.armorpiercing) * (damage - CombatRules.getDamageAfterAbsorb(damage, (float) livingentity.getArmorValue(), (float) livingentity.getAttributeValue(Attributes.ARMOR_TOUGHNESS)));
|
|
||||||
damagesource = damagesource.bypassArmor();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.level.isClientSide() && this.type.explosive)
|
|
||||||
{
|
|
||||||
this.level.explode(this.getOwner(), pos.x, pos.y, pos.z, 3.0F, Explosion.Mode.NONE);
|
|
||||||
this.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.hurt(damagesource, damage);
|
|
||||||
Vector3d vector3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) this.type.knockback * 0.6D);
|
|
||||||
if (vector3d.lengthSqr() > 0.0D)
|
|
||||||
{
|
|
||||||
entity.push(vector3d.x, 0.1D, vector3d.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.getType() == RayTraceResult.Type.BLOCK)
|
|
||||||
{
|
|
||||||
BlockRayTraceResult blockRTR = (BlockRayTraceResult)result;
|
|
||||||
BlockPos blockpos = blockRTR.getBlockPos();
|
|
||||||
BlockState blockstate = this.level.getBlockState(blockpos);
|
|
||||||
boolean smoothimpact =
|
|
||||||
!this.type.specs.destroysground.get() && (
|
|
||||||
blockstate == Blocks.SAND.defaultBlockState() ||
|
|
||||||
blockstate == Blocks.RED_SAND.defaultBlockState() ||
|
|
||||||
blockstate == Blocks.DIRT.defaultBlockState() ||
|
|
||||||
blockstate == Blocks.GRASS_BLOCK.defaultBlockState() ||
|
|
||||||
blockstate == Blocks.GRASS_PATH.defaultBlockState() ||
|
|
||||||
blockstate == Blocks.COARSE_DIRT.defaultBlockState() ||
|
|
||||||
blockstate == Blocks.SNOW_BLOCK.defaultBlockState()) &&
|
|
||||||
blockRTR.getDirection() == Direction.UP;
|
|
||||||
|
|
||||||
if (blockRTR.getDirection() == Direction.UP)
|
|
||||||
{
|
|
||||||
if (this.type.explosive)
|
|
||||||
{
|
|
||||||
for (int r = 0; r < this.type.specs.explosionpower.get(); ++r)
|
|
||||||
{
|
|
||||||
for (float a = 0; a < 2 * Math.PI; a += Math.PI / 4)
|
|
||||||
{
|
|
||||||
BlockPos pos = blockRTR.getBlockPos().offset(r * MathHelper.cos(a), 0, -r * MathHelper.sin(a));
|
|
||||||
if (this.level.getBlockState(pos) == Blocks.GRASS_BLOCK.defaultBlockState())
|
|
||||||
{
|
|
||||||
this.level.setBlockAndUpdate(pos, Blocks.DIRT.defaultBlockState());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.level.isClientSide())
|
|
||||||
{
|
|
||||||
this.remove();
|
|
||||||
if (smoothimpact && this.type.explosive)
|
|
||||||
{
|
|
||||||
this.level.explode(this.getOwner(), blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get(), Explosion.Mode.NONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (smoothimpact)
|
|
||||||
{
|
|
||||||
this.dustExplosion(new BlockParticleData(ParticleTypes.BLOCK, blockstate).setPos(blockpos), blockpos, this.type.specs.explosionpower.get() / 2, 50);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.level.isClientSide() && !smoothimpact && this.type.explosive)
|
|
||||||
{
|
|
||||||
this.level.explode(this.getOwner(), blockpos.getX(), blockpos.getY(), blockpos.getZ(), this.type.specs.explosionpower.get(), Explosion.Mode.BREAK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.getType() == RayTraceResult.Type.MISS)
|
|
||||||
{
|
|
||||||
this.level.playSound((PlayerEntity)this.getOwner(), this.getOnPos(), SoundEvents.ANVIL_BREAK, SoundCategory.AMBIENT, 1.0f, 1.0f);
|
|
||||||
if(!this.level.isClientSide())
|
|
||||||
{
|
|
||||||
this.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.level.isClientSide())
|
|
||||||
{
|
|
||||||
this.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dustExplosion(IParticleData particle, BlockPos blockpos, double speed, int amount)
|
|
||||||
{
|
|
||||||
this.dustExplosion(particle, blockpos.getX(), blockpos.getY(), blockpos.getZ(), speed, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dustExplosion(IParticleData particle, double x, double y, double z, double speed, int amount)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < amount; ++i)
|
|
||||||
{
|
|
||||||
Vector3d movement = this.getDeltaMovement();
|
|
||||||
double d0 = x - 0.05 + this.level.random.nextDouble() * 0.3;
|
|
||||||
double d1 = y + 1.0;
|
|
||||||
double d2 = z - 0.05 + this.level.random.nextDouble() * 0.3;
|
|
||||||
double d3 = movement.x * this.level.random.nextDouble() * speed;
|
|
||||||
double d4 = -movement.y * this.level.random.nextDouble() * speed * 10.0f;
|
|
||||||
double d5 = movement.z * this.level.random.nextDouble() * speed;
|
|
||||||
this.level.addParticle(particle, d0, d1, d2, d3, d4, d5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick()
|
|
||||||
{
|
|
||||||
if (this.type.flighttype == FlightType.SPINNING)
|
|
||||||
{
|
|
||||||
this.xRot += 0.5;
|
|
||||||
this.setRot(this.yRot, this.xRot);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.tick();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.projectile;
|
|
||||||
|
|
||||||
import magistu.siegemachines.entity.EntityTypes;
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.projectile.ArrowEntity;
|
|
||||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
|
|
||||||
|
|
||||||
public class ProjectileBuilder<T extends ProjectileEntity>
|
|
||||||
{
|
|
||||||
public final static ProjectileBuilder<Stone> NONE = new ProjectileBuilder<>(Items.AIR, EntityTypes.STONE.get(), Stone::new);
|
|
||||||
|
|
||||||
public final static ProjectileBuilder[] NO_AMMO = new ProjectileBuilder[]{};
|
|
||||||
public final static ProjectileBuilder[] CANNON_AMMO = new ProjectileBuilder[]{
|
|
||||||
new ProjectileBuilder(ModItems.CANNONBALL.get(), EntityTypes.CANNONBALL.get(), Cannonball::new)};
|
|
||||||
public final static ProjectileBuilder[] GIANT_THROWING_AMMO = new ProjectileBuilder[]{
|
|
||||||
new ProjectileBuilder(Items.COBBLESTONE, ModItems.GIANT_STONE.get(), EntityTypes.GIANT_STONE.get(), GiantStone::new)};
|
|
||||||
public final static ProjectileBuilder[] THROWING_AMMO = new ProjectileBuilder[]{
|
|
||||||
new ProjectileBuilder(Items.COBBLESTONE, ModItems.STONE.get(), EntityTypes.STONE.get(), Stone::new)};
|
|
||||||
public final static ProjectileBuilder[] BALLISTA_AMMO = new ProjectileBuilder[]{
|
|
||||||
new ProjectileBuilder(ModItems.GIANT_ARROW.get(), EntityTypes.GIANT_ARROW.get(), GiantArrow::new),
|
|
||||||
new ProjectileBuilder(Items.ARROW, EntityType.ARROW, (entitytype, level, pos, entity, item) ->
|
|
||||||
{
|
|
||||||
ArrowEntity arrow = new ArrowEntity(level, entity);
|
|
||||||
arrow.setPos(pos.x, pos.y, pos.z);
|
|
||||||
return arrow;
|
|
||||||
})};
|
|
||||||
|
|
||||||
public final Item item;
|
|
||||||
public final Item projectileitem;
|
|
||||||
public final EntityType<T> entitytype;
|
|
||||||
public final IProjectileFactory<T> factory;
|
|
||||||
|
|
||||||
public ProjectileBuilder(Item item, EntityType<T> entitytype, IProjectileFactory<T> factory)
|
|
||||||
{
|
|
||||||
this(item, item, entitytype, factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProjectileBuilder(Item item, Item projectileitem, EntityType<T> entitytype, IProjectileFactory<T> factory)
|
|
||||||
{
|
|
||||||
this.item = item;
|
|
||||||
this.projectileitem = projectileitem;
|
|
||||||
this.entitytype = entitytype;
|
|
||||||
this.factory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package magistu.siegemachines.entity.projectile;
|
|
||||||
|
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class Stone extends Missile
|
|
||||||
{
|
|
||||||
public Stone(EntityType<Stone> entitytype, World level)
|
|
||||||
{
|
|
||||||
super(entitytype, level);
|
|
||||||
this.item = ModItems.STONE.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Stone(EntityType<Stone> entitytype, World level, Vector3d pos, LivingEntity entity, Item item)
|
|
||||||
{
|
|
||||||
super(entitytype, level, pos, entity, MissileType.STONE, item);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
package magistu.siegemachines.event;
|
|
||||||
|
|
||||||
import magistu.siegemachines.client.KeyBindings;
|
|
||||||
import magistu.siegemachines.entity.IReloading;
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
|
||||||
import magistu.siegemachines.gui.Crosshair;
|
|
||||||
import magistu.siegemachines.network.PacketHandler;
|
|
||||||
import magistu.siegemachines.network.PacketOpenMachineInventory;
|
|
||||||
import magistu.siegemachines.network.PacketMachineUse;
|
|
||||||
import net.minecraft.client.GameSettings;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
|
||||||
import net.minecraft.client.settings.PointOfView;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.client.event.InputEvent;
|
|
||||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
public class ClientEvents
|
|
||||||
{
|
|
||||||
public static Crosshair crosshair = null;
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public static void onKeyPressedEvent(InputEvent.KeyInputEvent ev)
|
|
||||||
{
|
|
||||||
if (KeyBindings.MACHINE_USE.isDown())
|
|
||||||
{
|
|
||||||
ClientPlayerEntity player = Minecraft.getInstance().player;
|
|
||||||
if (player != null && player.isPassenger() && player.getVehicle() instanceof Machine)
|
|
||||||
{
|
|
||||||
PacketHandler.sendToServer(new PacketMachineUse(player.getVehicle().getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (KeyBindings.MACHINE_INVENTORY.isDown())
|
|
||||||
{
|
|
||||||
ClientPlayerEntity player = Minecraft.getInstance().player;
|
|
||||||
if (player != null && player.isPassenger() && player.getVehicle() instanceof Machine)
|
|
||||||
{
|
|
||||||
PacketHandler.sendToServer(new PacketOpenMachineInventory());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public static void onRenderOverlayPre(RenderGameOverlayEvent.Pre ev)
|
|
||||||
{
|
|
||||||
if (ev.getType() == RenderGameOverlayEvent.ElementType.CROSSHAIRS)
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
GameSettings settings = mc.options;
|
|
||||||
ClientPlayerEntity player = mc.player;
|
|
||||||
|
|
||||||
if ((settings.renderDebug && !settings.hideGui && !player.isReducedDebugInfo() && !settings.reducedDebugInfo) || settings.getCameraType().compareTo(PointOfView.FIRST_PERSON) != 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.isPassenger())
|
|
||||||
{
|
|
||||||
Entity entity = player.getVehicle();
|
|
||||||
if (entity instanceof IReloading)
|
|
||||||
{
|
|
||||||
if (crosshair == null)
|
|
||||||
{
|
|
||||||
crosshair = ((IReloading) entity).createCrosshair();
|
|
||||||
}
|
|
||||||
crosshair.render(ev.getMatrixStack(), ev.getPartialTicks(), mc, player);
|
|
||||||
ev.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package magistu.siegemachines.gui;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import net.minecraft.inventory.container.ContainerType;
|
|
||||||
import net.minecraftforge.common.extensions.IForgeContainerType;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.fml.RegistryObject;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
|
|
||||||
public class ContainerTypes
|
|
||||||
{
|
|
||||||
public static final DeferredRegister<ContainerType<?>> CONTAINER_TYPES = DeferredRegister.create(ForgeRegistries.CONTAINERS, SiegeMachines.ID);
|
|
||||||
|
|
||||||
public static final RegistryObject<ContainerType<MachineContainer>> MACHINE_CONTAINER = CONTAINER_TYPES.register("machine", () -> IForgeContainerType.create(MachineContainer::new));
|
|
||||||
public static final RegistryObject<ContainerType<SiegeWorkbenchContainer>> SIEGE_WORKBENCH_CONTAINER = CONTAINER_TYPES.register("siege_workbench", () -> IForgeContainerType.create(SiegeWorkbenchContainer::new));
|
|
||||||
|
|
||||||
public static void register(IEventBus eventBus)
|
|
||||||
{
|
|
||||||
CONTAINER_TYPES.register(eventBus);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
package magistu.siegemachines.gui;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public class MachineInventoryScreen extends ContainerScreen<MachineContainer>
|
|
||||||
{
|
|
||||||
private final ResourceLocation displaceCaseGui;
|
|
||||||
|
|
||||||
public MachineInventoryScreen(MachineContainer container, PlayerInventory inv, ITextComponent titleIn)
|
|
||||||
{
|
|
||||||
super(container, inv, titleIn);
|
|
||||||
|
|
||||||
this.leftPos = 0;
|
|
||||||
this.topPos = 0;
|
|
||||||
this.imageWidth = 176;
|
|
||||||
this.imageHeight = 166;
|
|
||||||
switch (container.getContainerSize())
|
|
||||||
{
|
|
||||||
case 18:
|
|
||||||
this.displaceCaseGui = new ResourceLocation(SiegeMachines.ID, "textures/gui/machine_inventory_2.png");
|
|
||||||
break;
|
|
||||||
case 27:
|
|
||||||
this.displaceCaseGui = new ResourceLocation(SiegeMachines.ID, "textures/gui/machine_inventory_3.png");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.displaceCaseGui = new ResourceLocation(SiegeMachines.ID, "textures/gui/machine_inventory_1.png");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks)
|
|
||||||
{
|
|
||||||
this.renderBackground(matrixStack);
|
|
||||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
|
||||||
this.renderTooltip(matrixStack, mouseX, mouseY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderTooltip(@NotNull MatrixStack matrixStack, int x, int y)
|
|
||||||
{
|
|
||||||
if (this.minecraft.player.inventory.getCarried().isEmpty() && this.hoveredSlot != null && this.hoveredSlot.hasItem())
|
|
||||||
{
|
|
||||||
this.renderTooltip(matrixStack, this.hoveredSlot.getItem(), x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
protected void renderBg(@NotNull MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY)
|
|
||||||
{
|
|
||||||
RenderSystem.color4f(1f, 1f, 1f, 1f);
|
|
||||||
assert this.minecraft != null;
|
|
||||||
this.minecraft.textureManager.bind(this.displaceCaseGui);
|
|
||||||
int x = (this.width - this.imageWidth) / 2;
|
|
||||||
int y = (this.height - this.imageHeight) / 2;
|
|
||||||
this.blit(matrixStack, x, y, 0, 0, this.imageWidth, this.imageHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyPressed(int key, int b, int c)
|
|
||||||
{
|
|
||||||
assert this.minecraft != null;
|
|
||||||
if (key == 256)
|
|
||||||
{
|
|
||||||
this.minecraft.player.closeContainer();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.keyPressed(key, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,615 +0,0 @@
|
|||||||
package magistu.siegemachines.gui;
|
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import magistu.siegemachines.block.ModBlocks;
|
|
||||||
import magistu.siegemachines.data.recipes.ModRecipes;
|
|
||||||
import magistu.siegemachines.data.recipes.SiegeWorkbenchRecipe;
|
|
||||||
import net.minecraft.crash.CrashReport;
|
|
||||||
import net.minecraft.crash.CrashReportCategory;
|
|
||||||
import net.minecraft.crash.ReportedException;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.inventory.CraftResultInventory;
|
|
||||||
import net.minecraft.inventory.CraftingInventory;
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.inventory.container.*;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
|
||||||
import net.minecraft.item.crafting.IRecipeType;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.network.play.server.SSetSlotPacket;
|
|
||||||
import net.minecraft.util.IWorldPosCallable;
|
|
||||||
import net.minecraft.util.NonNullList;
|
|
||||||
import net.minecraft.util.Util;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class SiegeWorkbenchContainer extends Container
|
|
||||||
{
|
|
||||||
private final CraftingInventory craftSlots = new CraftingInventory(this, 3, 3);
|
|
||||||
private final CraftResultInventory resultSlots = new CraftResultInventory();
|
|
||||||
private final IWorldPosCallable access;
|
|
||||||
private final PlayerEntity player;
|
|
||||||
|
|
||||||
private int quickcraftType = -1;
|
|
||||||
private int quickcraftStatus;
|
|
||||||
private final Set<Slot> quickcraftSlots = Sets.newHashSet();
|
|
||||||
|
|
||||||
public SiegeWorkbenchContainer(int p_i50089_1_, PlayerInventory p_i50089_2_, PacketBuffer buffer)
|
|
||||||
{
|
|
||||||
this(p_i50089_1_, p_i50089_2_, IWorldPosCallable.NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SiegeWorkbenchContainer(int p_i50090_1_, PlayerInventory p_i50090_2_, IWorldPosCallable p_i50090_3_)
|
|
||||||
{
|
|
||||||
super(ContainerTypes.SIEGE_WORKBENCH_CONTAINER.get(), p_i50090_1_);
|
|
||||||
this.access = p_i50090_3_;
|
|
||||||
this.player = p_i50090_2_.player;
|
|
||||||
this.addSlot(new CraftingResultSlot(p_i50090_2_.player, this.craftSlots, this.resultSlots, 0, 124, 35));
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < 3; ++j)
|
|
||||||
{
|
|
||||||
this.addSlot(new Slot(this.craftSlots, j + i * 3, 30 + j * 18, 17 + i * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int k = 0; k < 3; ++k)
|
|
||||||
{
|
|
||||||
for (int i1 = 0; i1 < 9; ++i1)
|
|
||||||
{
|
|
||||||
this.addSlot(new Slot(p_i50090_2_, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int l = 0; l < 9; ++l)
|
|
||||||
{
|
|
||||||
this.addSlot(new Slot(p_i50090_2_, l, 8 + l * 18, 142));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// to create resulting item
|
|
||||||
protected static void slotChangedCraftingGrid(int p_217066_0_, World p_217066_1_, PlayerEntity p_217066_2_, CraftingInventory p_217066_3_, CraftResultInventory p_217066_4_)
|
|
||||||
{
|
|
||||||
if (!p_217066_1_.isClientSide)
|
|
||||||
{
|
|
||||||
ServerPlayerEntity serverplayerentity = (ServerPlayerEntity) p_217066_2_;
|
|
||||||
ItemStack itemstack = ItemStack.EMPTY;
|
|
||||||
Optional<SiegeWorkbenchRecipe> optional = p_217066_1_.getServer().getRecipeManager().getRecipeFor(ModRecipes.SIEGE_WORKBENCH_RECIPE, p_217066_3_, p_217066_1_);
|
|
||||||
if (optional.isPresent())
|
|
||||||
{
|
|
||||||
SiegeWorkbenchRecipe icraftingrecipe = optional.get();
|
|
||||||
if (p_217066_4_.setRecipeUsed(p_217066_1_, serverplayerentity, icraftingrecipe))
|
|
||||||
{
|
|
||||||
itemstack = icraftingrecipe.assemble(p_217066_3_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p_217066_4_.setItem(0, itemstack);
|
|
||||||
serverplayerentity.connection.send(new SSetSlotPacket(p_217066_0_, 0, itemstack));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void slotsChanged(@NotNull IInventory p_75130_1_)
|
|
||||||
{
|
|
||||||
this.access.execute((p_217069_1_, p_217069_2_) -> slotChangedCraftingGrid(this.containerId, p_217069_1_, this.player, this.craftSlots, this.resultSlots));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removed(@NotNull PlayerEntity p_75134_1_)
|
|
||||||
{
|
|
||||||
super.removed(p_75134_1_);
|
|
||||||
this.access.execute((p_217068_2_, p_217068_3_) -> this.clearContainer(p_75134_1_, p_217068_2_, this.craftSlots));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean stillValid(PlayerEntity p_75145_1_)
|
|
||||||
{
|
|
||||||
return stillValid(this.access, p_75145_1_, ModBlocks.SIEGE_WORKBENCH.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ItemStack onTakeFromSlot(Slot slot, PlayerEntity p_190901_1_, ItemStack p_190901_2_)
|
|
||||||
{
|
|
||||||
if (slot instanceof CraftingResultSlot)
|
|
||||||
{
|
|
||||||
return this.onCraft(p_190901_1_, p_190901_2_);
|
|
||||||
}
|
|
||||||
return slot.onTake(p_190901_1_, p_190901_2_);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <C extends IInventory, T extends IRecipe<C>> NonNullList<ItemStack> getRemainingItemsFor(IRecipeType<T> p_215369_1_, C p_215369_2_, World p_215369_3_)
|
|
||||||
{
|
|
||||||
Optional<T> optional = p_215369_3_.getRecipeManager().getRecipeFor(p_215369_1_, p_215369_2_, p_215369_3_);
|
|
||||||
if (optional.isPresent())
|
|
||||||
{
|
|
||||||
return optional.get().getRemainingItems(p_215369_2_);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NonNullList<ItemStack> nonnulllist = NonNullList.withSize(p_215369_2_.getContainerSize(), ItemStack.EMPTY);
|
|
||||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
|
||||||
{
|
|
||||||
nonnulllist.set(i, p_215369_2_.getItem(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return nonnulllist;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack onCraft(PlayerEntity p_190901_1_, ItemStack p_190901_2_)
|
|
||||||
{
|
|
||||||
//slot.checkTakeAchievements(p_190901_2_);
|
|
||||||
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(p_190901_1_);
|
|
||||||
NonNullList<ItemStack> nonnulllist = this.getRemainingItemsFor(IRecipeType.CRAFTING, this.craftSlots, p_190901_1_.level);
|
|
||||||
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
|
|
||||||
for(int i = 0; i < nonnulllist.size(); ++i)
|
|
||||||
{
|
|
||||||
ItemStack itemstack = this.craftSlots.getItem(i);
|
|
||||||
ItemStack itemstack1 = nonnulllist.get(i);
|
|
||||||
if (!itemstack.isEmpty())
|
|
||||||
{
|
|
||||||
this.craftSlots.removeItem(i, 64);
|
|
||||||
itemstack = this.craftSlots.getItem(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!itemstack1.isEmpty())
|
|
||||||
{
|
|
||||||
if (itemstack.isEmpty())
|
|
||||||
{
|
|
||||||
this.craftSlots.setItem(i, itemstack1);
|
|
||||||
}
|
|
||||||
else if (ItemStack.isSame(itemstack, itemstack1) && ItemStack.tagMatches(itemstack, itemstack1))
|
|
||||||
{
|
|
||||||
itemstack1.grow(itemstack.getCount());
|
|
||||||
this.craftSlots.setItem(i, itemstack1);
|
|
||||||
}
|
|
||||||
else if (!this.player.inventory.add(itemstack1))
|
|
||||||
{
|
|
||||||
this.player.drop(itemstack1, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return p_190901_2_;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ItemStack quickMoveStack(PlayerEntity p_82846_1_, int p_82846_2_)
|
|
||||||
{
|
|
||||||
ItemStack itemstack = ItemStack.EMPTY;
|
|
||||||
Slot slot = this.slots.get(p_82846_2_);
|
|
||||||
if (slot != null && slot.hasItem())
|
|
||||||
{
|
|
||||||
ItemStack itemstack1 = slot.getItem();
|
|
||||||
itemstack = itemstack1.copy();
|
|
||||||
if (p_82846_2_ == 0)
|
|
||||||
{
|
|
||||||
this.access.execute((p_217067_2_, p_217067_3_) -> itemstack1.getItem().onCraftedBy(itemstack1, p_217067_2_, p_82846_1_));
|
|
||||||
if (!this.moveItemStackTo(itemstack1, 10, 46, true))
|
|
||||||
{
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
slot.onQuickCraft(itemstack1, itemstack);
|
|
||||||
}
|
|
||||||
else if (p_82846_2_ >= 10 && p_82846_2_ < 46)
|
|
||||||
{
|
|
||||||
if (!this.moveItemStackTo(itemstack1, 1, 10, false))
|
|
||||||
{
|
|
||||||
if (p_82846_2_ < 37)
|
|
||||||
{
|
|
||||||
if (!this.moveItemStackTo(itemstack1, 37, 46, false))
|
|
||||||
{
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!this.moveItemStackTo(itemstack1, 10, 37, false))
|
|
||||||
{
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!this.moveItemStackTo(itemstack1, 10, 46, false))
|
|
||||||
{
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemstack1.isEmpty())
|
|
||||||
{
|
|
||||||
slot.set(ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
slot.setChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemstack1.getCount() == itemstack.getCount())
|
|
||||||
{
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack itemstack2 = onTakeFromSlot(slot, p_82846_1_, itemstack1);
|
|
||||||
if (p_82846_2_ == 0)
|
|
||||||
{
|
|
||||||
p_82846_1_.drop(itemstack2, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemstack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canTakeItemForPickAll(ItemStack p_94530_1_, Slot p_94530_2_)
|
|
||||||
{
|
|
||||||
return p_94530_2_.container != this.resultSlots && super.canTakeItemForPickAll(p_94530_1_, p_94530_2_);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ItemStack clicked(int p_184996_1_, int p_184996_2_, ClickType p_184996_3_, PlayerEntity p_184996_4_)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ItemStack result = this.doClick(p_184996_1_, p_184996_2_, p_184996_3_, p_184996_4_);
|
|
||||||
this.slotsChanged(this.craftSlots);
|
|
||||||
this.slotsChanged(this.resultSlots);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
CrashReport crashreport = CrashReport.forThrowable(exception, "Container click");
|
|
||||||
CrashReportCategory crashreportcategory = crashreport.addCategory("Click info");
|
|
||||||
crashreportcategory.setDetail("Menu Class", () -> this.getClass().getCanonicalName());
|
|
||||||
crashreportcategory.setDetail("Slot Count", this.slots.size());
|
|
||||||
crashreportcategory.setDetail("Slot", p_184996_1_);
|
|
||||||
crashreportcategory.setDetail("Button", p_184996_2_);
|
|
||||||
crashreportcategory.setDetail("Type", p_184996_3_);
|
|
||||||
throw new ReportedException(crashreport);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void resetQuickCraft()
|
|
||||||
{
|
|
||||||
this.quickcraftStatus = 0;
|
|
||||||
this.quickcraftSlots.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack doClick(int index1, int index2, ClickType clicktype, PlayerEntity player)
|
|
||||||
{
|
|
||||||
ItemStack itemstack = ItemStack.EMPTY;
|
|
||||||
PlayerInventory playerinventory = player.inventory;
|
|
||||||
if (clicktype == ClickType.QUICK_CRAFT)
|
|
||||||
{
|
|
||||||
int i1 = this.quickcraftStatus;
|
|
||||||
this.quickcraftStatus = getQuickcraftHeader(index2);
|
|
||||||
if ((i1 != 1 || this.quickcraftStatus != 2) && i1 != this.quickcraftStatus)
|
|
||||||
{
|
|
||||||
this.resetQuickCraft();
|
|
||||||
}
|
|
||||||
else if (playerinventory.getCarried().isEmpty())
|
|
||||||
{
|
|
||||||
this.resetQuickCraft();
|
|
||||||
}
|
|
||||||
else if (this.quickcraftStatus == 0)
|
|
||||||
{
|
|
||||||
this.quickcraftType = getQuickcraftType(index2);
|
|
||||||
if (isValidQuickcraftType(this.quickcraftType, player))
|
|
||||||
{
|
|
||||||
this.quickcraftStatus = 1;
|
|
||||||
this.quickcraftSlots.clear();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.resetQuickCraft();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.quickcraftStatus == 1)
|
|
||||||
{
|
|
||||||
Slot slot7 = this.slots.get(index1);
|
|
||||||
ItemStack itemstack12 = playerinventory.getCarried();
|
|
||||||
if (slot7 != null && canItemQuickReplace(slot7, itemstack12, true) && slot7.mayPlace(itemstack12) && (this.quickcraftType == 2 || itemstack12.getCount() > this.quickcraftSlots.size()) && this.canDragTo(slot7))
|
|
||||||
{
|
|
||||||
this.quickcraftSlots.add(slot7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.quickcraftStatus == 2)
|
|
||||||
{
|
|
||||||
if (!this.quickcraftSlots.isEmpty())
|
|
||||||
{
|
|
||||||
ItemStack itemstack10 = playerinventory.getCarried().copy();
|
|
||||||
int k1 = playerinventory.getCarried().getCount();
|
|
||||||
|
|
||||||
for(Slot slot8 : this.quickcraftSlots)
|
|
||||||
{
|
|
||||||
ItemStack itemstack13 = playerinventory.getCarried();
|
|
||||||
if (slot8 != null && canItemQuickReplace(slot8, itemstack13, true) && slot8.mayPlace(itemstack13) && (this.quickcraftType == 2 || itemstack13.getCount() >= this.quickcraftSlots.size()) && this.canDragTo(slot8))
|
|
||||||
{
|
|
||||||
ItemStack itemstack14 = itemstack10.copy();
|
|
||||||
int j3 = slot8.hasItem() ? slot8.getItem().getCount() : 0;
|
|
||||||
getQuickCraftSlotCount(this.quickcraftSlots, this.quickcraftType, itemstack14, j3);
|
|
||||||
int k3 = Math.min(itemstack14.getMaxStackSize(), slot8.getMaxStackSize(itemstack14));
|
|
||||||
if (itemstack14.getCount() > k3)
|
|
||||||
{
|
|
||||||
itemstack14.setCount(k3);
|
|
||||||
}
|
|
||||||
|
|
||||||
k1 -= itemstack14.getCount() - j3;
|
|
||||||
slot8.set(itemstack14);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
itemstack10.setCount(k1);
|
|
||||||
playerinventory.setCarried(itemstack10);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.resetQuickCraft();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.resetQuickCraft();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.quickcraftStatus != 0)
|
|
||||||
{
|
|
||||||
this.resetQuickCraft();
|
|
||||||
}
|
|
||||||
else if ((clicktype == ClickType.PICKUP || clicktype == ClickType.QUICK_MOVE) && (index2 == 0 || index2 == 1))
|
|
||||||
{
|
|
||||||
if (index1 == -999)
|
|
||||||
{
|
|
||||||
if (!playerinventory.getCarried().isEmpty())
|
|
||||||
{
|
|
||||||
if (index2 == 0)
|
|
||||||
{
|
|
||||||
player.drop(playerinventory.getCarried(), true);
|
|
||||||
playerinventory.setCarried(ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index2 == 1)
|
|
||||||
{
|
|
||||||
player.drop(playerinventory.getCarried().split(1), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (clicktype == ClickType.QUICK_MOVE)
|
|
||||||
{
|
|
||||||
if (index1 < 0)
|
|
||||||
{
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
Slot slot5 = this.slots.get(index1);
|
|
||||||
if (slot5 == null || !slot5.mayPickup(player))
|
|
||||||
{
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ItemStack itemstack8 = this.quickMoveStack(player, index1); !itemstack8.isEmpty() && ItemStack.isSame(slot5.getItem(), itemstack8); itemstack8 = this.quickMoveStack(player, index1))
|
|
||||||
{
|
|
||||||
itemstack = itemstack8.copy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (index1 < 0)
|
|
||||||
{
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
Slot slot6 = this.slots.get(index1);
|
|
||||||
if (slot6 != null)
|
|
||||||
{
|
|
||||||
ItemStack itemstack9 = slot6.getItem();
|
|
||||||
ItemStack itemstack11 = playerinventory.getCarried();
|
|
||||||
if (!itemstack9.isEmpty())
|
|
||||||
{
|
|
||||||
itemstack = itemstack9.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemstack9.isEmpty())
|
|
||||||
{
|
|
||||||
if (!itemstack11.isEmpty() && slot6.mayPlace(itemstack11))
|
|
||||||
{
|
|
||||||
int j2 = index2 == 0 ? itemstack11.getCount() : 1;
|
|
||||||
if (j2 > slot6.getMaxStackSize(itemstack11))
|
|
||||||
{
|
|
||||||
j2 = slot6.getMaxStackSize(itemstack11);
|
|
||||||
}
|
|
||||||
|
|
||||||
slot6.set(itemstack11.split(j2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (slot6.mayPickup(player))
|
|
||||||
{
|
|
||||||
if (itemstack11.isEmpty())
|
|
||||||
{
|
|
||||||
if (itemstack9.isEmpty())
|
|
||||||
{
|
|
||||||
slot6.set(ItemStack.EMPTY);
|
|
||||||
playerinventory.setCarried(ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int k2 = index2 == 0 ? itemstack9.getCount() : (itemstack9.getCount() + 1) / 2;
|
|
||||||
playerinventory.setCarried(slot6.remove(k2));
|
|
||||||
if (itemstack9.isEmpty())
|
|
||||||
{
|
|
||||||
slot6.set(ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
onTakeFromSlot(slot6, player, playerinventory.getCarried());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (slot6.mayPlace(itemstack11))
|
|
||||||
{
|
|
||||||
if (consideredTheSameItem(itemstack9, itemstack11))
|
|
||||||
{
|
|
||||||
int l2 = index2 == 0 ? itemstack11.getCount() : 1;
|
|
||||||
if (l2 > slot6.getMaxStackSize(itemstack11) - itemstack9.getCount())
|
|
||||||
{
|
|
||||||
l2 = slot6.getMaxStackSize(itemstack11) - itemstack9.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (l2 > itemstack11.getMaxStackSize() - itemstack9.getCount())
|
|
||||||
{
|
|
||||||
l2 = itemstack11.getMaxStackSize() - itemstack9.getCount();
|
|
||||||
}
|
|
||||||
itemstack11.shrink(l2);
|
|
||||||
itemstack9.grow(l2);
|
|
||||||
}
|
|
||||||
else if (itemstack11.getCount() <= slot6.getMaxStackSize(itemstack11))
|
|
||||||
{
|
|
||||||
slot6.set(itemstack11);
|
|
||||||
playerinventory.setCarried(itemstack9);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (itemstack11.getMaxStackSize() > 1 && consideredTheSameItem(itemstack9, itemstack11) && !itemstack9.isEmpty())
|
|
||||||
{
|
|
||||||
int i3 = itemstack9.getCount();
|
|
||||||
if (i3 + itemstack11.getCount() <= itemstack11.getMaxStackSize())
|
|
||||||
{
|
|
||||||
itemstack11.grow(i3);
|
|
||||||
itemstack9 = slot6.remove(i3);
|
|
||||||
if (itemstack9.isEmpty())
|
|
||||||
{
|
|
||||||
slot6.set(ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
onTakeFromSlot(slot6, player, playerinventory.getCarried());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
slot6.setChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (clicktype == ClickType.SWAP)
|
|
||||||
{
|
|
||||||
Slot slot = this.slots.get(index1);
|
|
||||||
ItemStack itemstack1 = playerinventory.getItem(index2);
|
|
||||||
ItemStack itemstack2 = slot.getItem();
|
|
||||||
if (!itemstack1.isEmpty() || !itemstack2.isEmpty())
|
|
||||||
{
|
|
||||||
if (itemstack1.isEmpty())
|
|
||||||
{
|
|
||||||
if (slot.mayPickup(player))
|
|
||||||
{
|
|
||||||
playerinventory.setItem(index2, itemstack2);
|
|
||||||
//slot.onSwapCraft(itemstack2.getCount());
|
|
||||||
slot.set(ItemStack.EMPTY);
|
|
||||||
onTakeFromSlot(slot, player, itemstack2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (itemstack2.isEmpty())
|
|
||||||
{
|
|
||||||
if (slot.mayPlace(itemstack1))
|
|
||||||
{
|
|
||||||
int i = slot.getMaxStackSize(itemstack1);
|
|
||||||
if (itemstack1.getCount() > i)
|
|
||||||
{
|
|
||||||
slot.set(itemstack1.split(i));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
slot.set(itemstack1);
|
|
||||||
playerinventory.setItem(index2, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (slot.mayPickup(player) && slot.mayPlace(itemstack1))
|
|
||||||
{
|
|
||||||
int l1 = slot.getMaxStackSize(itemstack1);
|
|
||||||
if (itemstack1.getCount() > l1)
|
|
||||||
{
|
|
||||||
slot.set(itemstack1.split(l1));
|
|
||||||
onTakeFromSlot(slot, player, itemstack2);
|
|
||||||
if (!playerinventory.add(itemstack2))
|
|
||||||
{
|
|
||||||
player.drop(itemstack2, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
slot.set(itemstack1);
|
|
||||||
playerinventory.setItem(index2, itemstack2);
|
|
||||||
onTakeFromSlot(slot, player, itemstack2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (clicktype == ClickType.CLONE && player.abilities.instabuild && playerinventory.getCarried().isEmpty() && index1 >= 0)
|
|
||||||
{
|
|
||||||
Slot slot4 = this.slots.get(index1);
|
|
||||||
if (slot4 != null && slot4.hasItem())
|
|
||||||
{
|
|
||||||
ItemStack itemstack7 = slot4.getItem().copy();
|
|
||||||
itemstack7.setCount(itemstack7.getMaxStackSize());
|
|
||||||
playerinventory.setCarried(itemstack7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (clicktype == ClickType.THROW && playerinventory.getCarried().isEmpty() && index1 >= 0)
|
|
||||||
{
|
|
||||||
Slot slot3 = this.slots.get(index1);
|
|
||||||
if (slot3 != null && slot3.hasItem() && slot3.mayPickup(player))
|
|
||||||
{
|
|
||||||
ItemStack itemstack6 = slot3.remove(index2 == 0 ? 1 : slot3.getItem().getCount());
|
|
||||||
onTakeFromSlot(slot3, player, itemstack6);
|
|
||||||
player.drop(itemstack6, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (clicktype == ClickType.PICKUP_ALL && index1 >= 0)
|
|
||||||
{
|
|
||||||
Slot slot2 = this.slots.get(index1);
|
|
||||||
ItemStack itemstack5 = playerinventory.getCarried();
|
|
||||||
if (!itemstack5.isEmpty() && (slot2 == null || !slot2.hasItem() || !slot2.mayPickup(player)))
|
|
||||||
{
|
|
||||||
int j1 = index2 == 0 ? 0 : this.slots.size() - 1;
|
|
||||||
int i2 = index2 == 0 ? 1 : -1;
|
|
||||||
|
|
||||||
for(int j = 0; j < 2; ++j)
|
|
||||||
{
|
|
||||||
for(int k = j1; k >= 0 && k < this.slots.size() && itemstack5.getCount() < itemstack5.getMaxStackSize(); k += i2)
|
|
||||||
{
|
|
||||||
Slot slot1 = this.slots.get(k);
|
|
||||||
if (slot1.hasItem() && canItemQuickReplace(slot1, itemstack5, true) && slot1.mayPickup(player) && this.canTakeItemForPickAll(itemstack5, slot1))
|
|
||||||
{
|
|
||||||
ItemStack itemstack3 = slot1.getItem();
|
|
||||||
if (j != 0 || itemstack3.getCount() != itemstack3.getMaxStackSize())
|
|
||||||
{
|
|
||||||
int l = Math.min(itemstack5.getMaxStackSize() - itemstack5.getCount(), itemstack3.getCount());
|
|
||||||
ItemStack itemstack4 = slot1.remove(l);
|
|
||||||
itemstack5.grow(l);
|
|
||||||
if (itemstack4.isEmpty())
|
|
||||||
{
|
|
||||||
slot1.set(ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
onTakeFromSlot(slot1, player, itemstack4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.broadcastChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemstack;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
package magistu.siegemachines.gui;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
|
||||||
import net.minecraft.client.gui.widget.button.ImageButton;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.inventory.container.WorkbenchContainer;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public class SiegeWorkbenchScreen extends ContainerScreen<SiegeWorkbenchContainer>
|
|
||||||
{
|
|
||||||
private static final ResourceLocation DISPLAY_CASE_GUI = new ResourceLocation(SiegeMachines.ID,
|
|
||||||
"textures/gui/siege_workbench.png");
|
|
||||||
|
|
||||||
public SiegeWorkbenchScreen(SiegeWorkbenchContainer screenContainer, PlayerInventory inv, ITextComponent titleIn)
|
|
||||||
{
|
|
||||||
super(screenContainer, inv, titleIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks)
|
|
||||||
{
|
|
||||||
this.renderBackground(matrixStack);
|
|
||||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
|
||||||
this.renderTooltip(matrixStack, mouseX, mouseY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderTooltip(@NotNull MatrixStack matrixStack, int x, int y)
|
|
||||||
{
|
|
||||||
if (this.minecraft.player.inventory.getCarried().isEmpty() && this.hoveredSlot != null && this.hoveredSlot.hasItem())
|
|
||||||
{
|
|
||||||
this.renderTooltip(matrixStack, this.hoveredSlot.getItem(), x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init()
|
|
||||||
{
|
|
||||||
super.init();
|
|
||||||
this.titleLabelX = 29;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
protected void renderBg(@NotNull MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY)
|
|
||||||
{
|
|
||||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
assert this.minecraft != null;
|
|
||||||
this.minecraft.getTextureManager().bind(DISPLAY_CASE_GUI);
|
|
||||||
int i = this.leftPos;
|
|
||||||
int j = (this.height - this.imageHeight) / 2;
|
|
||||||
this.blit(matrixStack, i, j, 0, 0, this.imageWidth, this.imageHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyPressed(int key, int b, int c)
|
|
||||||
{
|
|
||||||
assert this.minecraft != null;
|
|
||||||
if (key == 256)
|
|
||||||
{
|
|
||||||
assert this.minecraft.player != null;
|
|
||||||
this.minecraft.player.closeContainer();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.keyPressed(key, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,272 +0,0 @@
|
|||||||
package magistu.siegemachines.item;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.entity.EntityTypes;
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
|
||||||
import magistu.siegemachines.entity.machine.MachineType;
|
|
||||||
import magistu.siegemachines.entity.projectile.ProjectileBuilder;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.block.FlowingFluidBlock;
|
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
|
||||||
import net.minecraft.entity.*;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.ItemUseContext;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
import net.minecraft.stats.Stats;
|
|
||||||
import net.minecraft.tileentity.MobSpawnerTileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.ActionResultType;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.math.*;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
|
||||||
import net.minecraft.world.IWorldReader;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
import net.minecraft.world.spawner.AbstractSpawner;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import software.bernie.geckolib3.core.IAnimatable;
|
|
||||||
import software.bernie.geckolib3.core.manager.AnimationData;
|
|
||||||
import software.bernie.geckolib3.core.manager.AnimationFactory;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class MachineItem extends Item implements IAnimatable
|
|
||||||
{
|
|
||||||
private final AnimationFactory factory = new AnimationFactory(this);
|
|
||||||
|
|
||||||
private final String entitykey;
|
|
||||||
private final String typekey;
|
|
||||||
|
|
||||||
public MachineItem(Properties prop, String entitykey, String typekey)
|
|
||||||
{
|
|
||||||
super(prop.stacksTo(1));
|
|
||||||
this.entitykey = entitykey;
|
|
||||||
this.typekey = typekey;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void appendHoverText(@NotNull ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn)
|
|
||||||
{
|
|
||||||
ProjectileBuilder[] ammo = MachineType.valueOf(this.typekey).ammo;
|
|
||||||
if (ammo.length > 0)
|
|
||||||
{
|
|
||||||
tooltip.add(new TranslationTextComponent(SiegeMachines.ID + ".ammo").withStyle(TextFormatting.BLUE));
|
|
||||||
for (ProjectileBuilder builder : ammo)
|
|
||||||
{
|
|
||||||
if (MachineType.valueOf(this.typekey).usesgunpowder)
|
|
||||||
{
|
|
||||||
tooltip.add(new StringTextComponent("Uses gunpowder").withStyle(TextFormatting.BLUE));
|
|
||||||
}
|
|
||||||
tooltip.add(new StringTextComponent(" ").append(new TranslationTextComponent(builder.item.getDescriptionId())).withStyle(TextFormatting.BLUE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ActionResultType useOn(ItemUseContext p_195939_1_)
|
|
||||||
{
|
|
||||||
World world = p_195939_1_.getLevel();
|
|
||||||
if (!(world instanceof ServerWorld))
|
|
||||||
{
|
|
||||||
return ActionResultType.SUCCESS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ItemStack itemstack = p_195939_1_.getItemInHand();
|
|
||||||
BlockPos blockpos = p_195939_1_.getClickedPos();
|
|
||||||
Direction direction = p_195939_1_.getClickedFace();
|
|
||||||
BlockState blockstate = world.getBlockState(blockpos);
|
|
||||||
if (blockstate.is(Blocks.SPAWNER))
|
|
||||||
{
|
|
||||||
TileEntity tileentity = world.getBlockEntity(blockpos);
|
|
||||||
if (tileentity instanceof MobSpawnerTileEntity)
|
|
||||||
{
|
|
||||||
AbstractSpawner abstractspawner = ((MobSpawnerTileEntity)tileentity).getSpawner();
|
|
||||||
EntityType<?> entitytype1 = this.getType(itemstack.getTag());
|
|
||||||
abstractspawner.setEntityId(entitytype1);
|
|
||||||
tileentity.setChanged();
|
|
||||||
world.sendBlockUpdated(blockpos, blockstate, blockstate, 3);
|
|
||||||
itemstack.shrink(1);
|
|
||||||
return ActionResultType.CONSUME;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockPos blockpos1;
|
|
||||||
if (blockstate.getCollisionShape(world, blockpos).isEmpty())
|
|
||||||
{
|
|
||||||
blockpos1 = blockpos;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
blockpos1 = blockpos.relative(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityType<?> entitytype = this.getType(itemstack.getTag());
|
|
||||||
Entity entity = this.spawn(entitytype, (ServerWorld)world, itemstack, p_195939_1_.getPlayer(), blockpos1, SpawnReason.SPAWN_EGG, true, !Objects.equals(blockpos, blockpos1) && direction == Direction.UP, p_195939_1_.getRotation());
|
|
||||||
|
|
||||||
if (entity instanceof Machine)
|
|
||||||
{
|
|
||||||
((Machine)entity).deploymentticks = 200;
|
|
||||||
}
|
|
||||||
if (entity != null)
|
|
||||||
{
|
|
||||||
itemstack.shrink(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ActionResultType.CONSUME;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static double getYOffset(IWorldReader p_208051_0_, BlockPos p_208051_1_, boolean p_208051_2_, AxisAlignedBB p_208051_3_) {
|
|
||||||
AxisAlignedBB axisalignedbb = new AxisAlignedBB(p_208051_1_);
|
|
||||||
if (p_208051_2_) {
|
|
||||||
axisalignedbb = axisalignedbb.expandTowards(0.0D, -1.0D, 0.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
Stream<VoxelShape> stream = p_208051_0_.getCollisions((Entity)null, axisalignedbb, (p_233596_0_) -> {
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
return 1.0D + VoxelShapes.collide(Direction.Axis.Y, p_208051_3_, stream, p_208051_2_ ? -2.0D : -1.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Entity spawn(EntityType<?> entitytype, ServerWorld p_220331_1_, @Nullable ItemStack p_220331_2_, @Nullable PlayerEntity p_220331_3_, BlockPos p_220331_4_, SpawnReason p_220331_5_, boolean p_220331_6_, boolean p_220331_7_, float yaw) {
|
|
||||||
return this.spawn(entitytype, p_220331_1_, p_220331_2_ == null ? null : p_220331_2_.getTag(), p_220331_2_ != null && p_220331_2_.hasCustomHoverName() ? p_220331_2_.getHoverName() : null, p_220331_3_, p_220331_4_, p_220331_5_, p_220331_6_, p_220331_7_, yaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Entity spawn(EntityType<?> entitytype, ServerWorld p_220342_1_, @Nullable CompoundNBT p_220342_2_, @Nullable ITextComponent p_220342_3_, @Nullable PlayerEntity p_220342_4_, BlockPos p_220342_5_, SpawnReason p_220342_6_, boolean p_220342_7_, boolean p_220342_8_, float yaw) {
|
|
||||||
Entity t = this.create(entitytype, p_220342_1_, p_220342_2_, p_220342_3_, p_220342_4_, p_220342_5_, p_220342_6_, p_220342_7_, p_220342_8_, yaw);
|
|
||||||
if (t != null) {
|
|
||||||
if (t instanceof MobEntity && net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn((MobEntity) t, p_220342_1_, p_220342_5_.getX(), p_220342_5_.getY(), p_220342_5_.getZ(), null, p_220342_6_)) return null;
|
|
||||||
p_220342_1_.addFreshEntityWithPassengers(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Entity create(EntityType<?> entitytype, ServerWorld p_220349_1_, @Nullable CompoundNBT p_220349_2_, @Nullable ITextComponent p_220349_3_, @Nullable PlayerEntity p_220349_4_, BlockPos p_220349_5_, SpawnReason p_220349_6_, boolean p_220349_7_, boolean p_220349_8_, float yaw) {
|
|
||||||
Entity t = entitytype.create(p_220349_1_);
|
|
||||||
if (t == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
double d0;
|
|
||||||
if (p_220349_7_) {
|
|
||||||
t.setPos((double)p_220349_5_.getX() + 0.5D, (double)(p_220349_5_.getY() + 1), (double)p_220349_5_.getZ() + 0.5D);
|
|
||||||
d0 = getYOffset(p_220349_1_, p_220349_5_, p_220349_8_, t.getBoundingBox());
|
|
||||||
} else {
|
|
||||||
d0 = 0.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityType.updateCustomEntityTag(p_220349_1_, p_220349_4_, t, p_220349_2_);
|
|
||||||
|
|
||||||
if (p_220349_3_ != null && t instanceof LivingEntity) {
|
|
||||||
t.setCustomName(p_220349_3_);
|
|
||||||
}
|
|
||||||
|
|
||||||
t.moveTo((double)p_220349_5_.getX() + 0.5D, (double)p_220349_5_.getY() + d0, (double)p_220349_5_.getZ() + 0.5D, MathHelper.wrapDegrees(yaw), 0.0F);
|
|
||||||
if (t instanceof MobEntity) {
|
|
||||||
MobEntity mobentity = (MobEntity)t;
|
|
||||||
mobentity.yHeadRot = mobentity.yRot;
|
|
||||||
mobentity.yBodyRot = mobentity.yRot;
|
|
||||||
mobentity.finalizeSpawn(p_220349_1_, p_220349_1_.getCurrentDifficultyAt(mobentity.blockPosition()), p_220349_6_, (ILivingEntityData)null, p_220349_2_);
|
|
||||||
mobentity.playAmbientSound();
|
|
||||||
}
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ActionResult<ItemStack> use(@NotNull World level, PlayerEntity player, @NotNull Hand hand)
|
|
||||||
{
|
|
||||||
ItemStack itemstack = player.getItemInHand(hand);
|
|
||||||
BlockRayTraceResult raytraceresult = getPlayerPOVHitResult(level, player, RayTraceContext.FluidMode.SOURCE_ONLY);
|
|
||||||
if (raytraceresult.getType() != RayTraceResult.Type.BLOCK)
|
|
||||||
{
|
|
||||||
return ActionResult.pass(itemstack);
|
|
||||||
}
|
|
||||||
else if (!(level instanceof ServerWorld))
|
|
||||||
{
|
|
||||||
return ActionResult.success(itemstack);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BlockPos blockpos = raytraceresult.getBlockPos();
|
|
||||||
if (!(level.getBlockState(blockpos).getBlock() instanceof FlowingFluidBlock))
|
|
||||||
{
|
|
||||||
return ActionResult.pass(itemstack);
|
|
||||||
}
|
|
||||||
else if (level.mayInteract(player, blockpos) && player.mayUseItemAt(blockpos, raytraceresult.getDirection(), itemstack))
|
|
||||||
{
|
|
||||||
EntityType<?> entitytype = this.getType(itemstack.getTag());
|
|
||||||
Entity entity = this.spawn(entitytype, (ServerWorld) level, itemstack, player, blockpos, SpawnReason.SPAWN_EGG, false, false, player.yRot);
|
|
||||||
if (entity instanceof Machine)
|
|
||||||
{
|
|
||||||
((Machine)entity).deploymentticks = 200;
|
|
||||||
}
|
|
||||||
if (entity != null)
|
|
||||||
{
|
|
||||||
if (!player.isCreative())
|
|
||||||
{
|
|
||||||
itemstack.shrink(1);
|
|
||||||
}
|
|
||||||
player.awardStat(Stats.ITEM_USED.get(this));
|
|
||||||
return ActionResult.consume(itemstack);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ActionResult.pass(itemstack);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ActionResult.fail(itemstack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityType<?> getType(@Nullable CompoundNBT nbt)
|
|
||||||
{
|
|
||||||
EntityType<?> defaulttype = EntityTypes.DEFERRED_REGISTER.getEntries().stream().filter(r -> r.get().getRegistryName().getPath().equals(this.entitykey)).findFirst().get().get();
|
|
||||||
|
|
||||||
if (nbt != null && nbt.contains("EntityTag", 10))
|
|
||||||
{
|
|
||||||
CompoundNBT compoundnbt = nbt.getCompound("EntityTag");
|
|
||||||
if (compoundnbt.contains("id", 8))
|
|
||||||
{
|
|
||||||
return EntityType.byString(compoundnbt.getString("id")).orElse(defaulttype);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaulttype;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerControllers(AnimationData data)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnimationFactory getFactory()
|
|
||||||
{
|
|
||||||
return this.factory;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
package magistu.siegemachines.item;
|
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
|
||||||
import magistu.siegemachines.block.ModBlocks;
|
|
||||||
import magistu.siegemachines.client.renderer.*;
|
|
||||||
import net.minecraft.block.AbstractBlock;
|
|
||||||
import net.minecraft.block.CraftingTableBlock;
|
|
||||||
import net.minecraft.block.SoundType;
|
|
||||||
import net.minecraft.block.material.Material;
|
|
||||||
import net.minecraft.item.BlockItem;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemGroup;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.RegistryObject;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import net.minecraftforge.registries.IForgeRegistry;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
|
||||||
public class ModItems
|
|
||||||
{
|
|
||||||
public static final ItemGroup GROUP_SM = new ItemGroup(SiegeMachines.ID + ".medieval_siege_machines")
|
|
||||||
{
|
|
||||||
public @NotNull ItemStack makeIcon()
|
|
||||||
{
|
|
||||||
return new ItemStack(ModItems.MORTAR.get());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, SiegeMachines.ID);
|
|
||||||
|
|
||||||
public static final RegistryObject<MachineItem> MORTAR = ITEMS.register("mortar", () -> new MachineItem(new Item.Properties().tab(ModItems.GROUP_SM).setISTER(() -> MortarItemGeoRenderer::new), "mortar", "MORTAR"));
|
|
||||||
//public static final RegistryObject<MachineItem> CULVERIN = ITEMS.register("culverin", () -> new MachineItem(new Item.Properties().tab(ModItems.GROUP_SM).setISTER(() -> CulverinItemGeoRenderer::new), "culverin", "CULVERIN"));
|
|
||||||
public static final RegistryObject<MachineItem> CATAPULT = ITEMS.register("catapult", () -> new MachineItem(new Item.Properties().tab(ModItems.GROUP_SM).setISTER(() -> CatapultItemGeoRenderer::new), "catapult", "CATAPULT"));
|
|
||||||
public static final RegistryObject<MachineItem> TREBUCHET = ITEMS.register("trebuchet", () -> new MachineItem(new Item.Properties().tab(ModItems.GROUP_SM).setISTER(() -> TrebuchetItemGeoRenderer::new), "trebuchet", "TREBUCHET"));
|
|
||||||
public static final RegistryObject<MachineItem> BALLISTA = ITEMS.register("ballista", () -> new MachineItem(new Item.Properties().tab(ModItems.GROUP_SM).setISTER(() -> BallistaItemGeoRenderer::new), "ballista", "BALLISTA"));
|
|
||||||
public static final RegistryObject<MachineItem> BATTERING_RAM = ITEMS.register("battering_ram", () -> new MachineItem(new Item.Properties().tab(ModItems.GROUP_SM).setISTER(() -> BatteringRamItemGeoRenderer::new), "battering_ram", "BATTERING_RAM"));
|
|
||||||
|
|
||||||
public static final RegistryObject<Item> CANNONBALL = ITEMS.register("cannonball", () -> new Item(new Item.Properties().stacksTo(16).tab(ModItems.GROUP_SM)));
|
|
||||||
public static final RegistryObject<Item> STONE = ITEMS.register("stone", () -> new Item(new Item.Properties().stacksTo(16)));
|
|
||||||
public static final RegistryObject<Item> GIANT_STONE = ITEMS.register("giant_stone", () -> new Item(new Item.Properties().stacksTo(16)));
|
|
||||||
public static final RegistryObject<Item> GIANT_ARROW = ITEMS.register("giant_arrow", () -> new Item(new Item.Properties().stacksTo(16).tab(ModItems.GROUP_SM)));
|
|
||||||
|
|
||||||
public static final RegistryObject<Item> TURRET_BASE = ITEMS.register("turret_base", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
|
|
||||||
public static final RegistryObject<Item> BEAM = ITEMS.register("beam", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
|
|
||||||
public static final RegistryObject<Item> COUNTERWEIGHT = ITEMS.register("counterweight", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
|
|
||||||
public static final RegistryObject<Item> BARREL = ITEMS.register("barrel", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
|
|
||||||
public static final RegistryObject<Item> WHEEL = ITEMS.register("wheel", () -> new Item(new Item.Properties().tab(ModItems.GROUP_SM)));
|
|
||||||
|
|
||||||
public static void register(IEventBus eventBus)
|
|
||||||
{
|
|
||||||
ITEMS.register(eventBus);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
package magistu.siegemachines.network;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
|
||||||
public class PacketMachine
|
|
||||||
{
|
|
||||||
private final int entityid;
|
|
||||||
private final int delayticks;
|
|
||||||
private final int useticks;
|
|
||||||
private final float turretyaw;
|
|
||||||
private final float turretpitch;
|
|
||||||
|
|
||||||
public PacketMachine(int entityid, int delayticks, int useticks, float turretpitch, float turretyaw)
|
|
||||||
{
|
|
||||||
this.entityid = entityid;
|
|
||||||
this.delayticks = delayticks;
|
|
||||||
this.useticks = useticks;
|
|
||||||
this.turretpitch = turretpitch;
|
|
||||||
this.turretyaw = turretyaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PacketMachine read(PacketBuffer buf)
|
|
||||||
{
|
|
||||||
return new PacketMachine(buf.readInt(), buf.readInt(), buf.readInt(), buf.readFloat(), buf.readFloat());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(PacketMachine message, PacketBuffer buf)
|
|
||||||
{
|
|
||||||
buf.writeInt(message.entityid);
|
|
||||||
buf.writeInt(message.delayticks);
|
|
||||||
buf.writeInt(message.useticks);
|
|
||||||
buf.writeFloat(message.turretpitch);
|
|
||||||
buf.writeFloat(message.turretyaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Handler
|
|
||||||
{
|
|
||||||
public static void handle(PacketMachine packet, Supplier<NetworkEvent.Context> ctx)
|
|
||||||
{
|
|
||||||
NetworkEvent.Context context = ctx.get();
|
|
||||||
if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT)
|
|
||||||
{
|
|
||||||
context.enqueueWork(() -> PacketMachine.handleClientSide(packet));
|
|
||||||
}
|
|
||||||
context.setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public static void handleClientSide(PacketMachine packet)
|
|
||||||
{
|
|
||||||
ClientPlayerEntity player = Minecraft.getInstance().player;
|
|
||||||
if(packet == null || player == null || player.level == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = player.level.getEntity(packet.entityid);
|
|
||||||
if (!(entity instanceof Machine))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Machine machine = (Machine) entity;
|
|
||||||
|
|
||||||
machine.delayticks = packet.delayticks;
|
|
||||||
machine.useticks = packet.useticks;
|
|
||||||
machine.setTurretRotations(packet.turretpitch, packet.turretyaw);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package magistu.siegemachines.network;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
|
||||||
public class PacketMachineControl
|
|
||||||
{
|
|
||||||
public PacketMachineControl() {}
|
|
||||||
|
|
||||||
public static PacketMachineControl read(PacketBuffer buf)
|
|
||||||
{
|
|
||||||
return new PacketMachineControl();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(PacketMachineControl message, PacketBuffer buf) {}
|
|
||||||
|
|
||||||
public static class Handler
|
|
||||||
{
|
|
||||||
public static void handle(PacketMachineControl packet, Supplier<NetworkEvent.Context> ctx)
|
|
||||||
{
|
|
||||||
NetworkEvent.Context context = ctx.get();
|
|
||||||
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER)
|
|
||||||
{
|
|
||||||
context.enqueueWork(() -> PacketMachineControl.handleServerSide(packet, context.getSender()));
|
|
||||||
}
|
|
||||||
context.setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handleServerSide(PacketMachineControl packet, ServerPlayerEntity player)
|
|
||||||
{
|
|
||||||
if(packet == null || player == null || !player.isPassenger())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = player.getVehicle();
|
|
||||||
if (!(entity instanceof Machine))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Machine machine = (Machine) entity;
|
|
||||||
|
|
||||||
machine.setTurretRotations(player.xRot, player.yRot);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
package magistu.siegemachines.network;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
|
||||||
public class PacketMachineUse
|
|
||||||
{
|
|
||||||
private final int entityid;
|
|
||||||
|
|
||||||
public PacketMachineUse(int entityid)
|
|
||||||
{
|
|
||||||
this.entityid = entityid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PacketMachineUse read(PacketBuffer buf)
|
|
||||||
{
|
|
||||||
return new PacketMachineUse(buf.readInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(PacketMachineUse message, PacketBuffer buf)
|
|
||||||
{
|
|
||||||
buf.writeInt(message.entityid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Handler
|
|
||||||
{
|
|
||||||
public static void handle(PacketMachineUse packet, Supplier<NetworkEvent.Context> ctx)
|
|
||||||
{
|
|
||||||
NetworkEvent.Context context = ctx.get();
|
|
||||||
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER)
|
|
||||||
{
|
|
||||||
context.enqueueWork(() -> PacketMachineUse.handleEachSide(packet, context.getSender()));
|
|
||||||
}
|
|
||||||
else if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT)
|
|
||||||
{
|
|
||||||
context.enqueueWork(() -> PacketMachineUse.handleClientSide(packet));
|
|
||||||
}
|
|
||||||
context.setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public static void handleClientSide(PacketMachineUse packet)
|
|
||||||
{
|
|
||||||
handleEachSide(packet, Minecraft.getInstance().player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handleEachSide(PacketMachineUse packet, PlayerEntity player)
|
|
||||||
{
|
|
||||||
if(packet == null || player == null || player.level == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = player.level.getEntity(packet.entityid);
|
|
||||||
if (!(entity instanceof Machine))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Machine machine = (Machine) entity;
|
|
||||||
|
|
||||||
machine.use(player);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
package magistu.siegemachines.network;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
|
||||||
public class PacketMachineUseRealise
|
|
||||||
{
|
|
||||||
private final int entityid;
|
|
||||||
|
|
||||||
public PacketMachineUseRealise(int entityid)
|
|
||||||
{
|
|
||||||
this.entityid = entityid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PacketMachineUseRealise read(PacketBuffer buf)
|
|
||||||
{
|
|
||||||
return new PacketMachineUseRealise(buf.readInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(PacketMachineUseRealise message, PacketBuffer buf)
|
|
||||||
{
|
|
||||||
buf.writeInt(message.entityid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Handler
|
|
||||||
{
|
|
||||||
public static void handle(PacketMachineUseRealise packet, Supplier<NetworkEvent.Context> ctx)
|
|
||||||
{
|
|
||||||
NetworkEvent.Context context = ctx.get();
|
|
||||||
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER)
|
|
||||||
{
|
|
||||||
context.enqueueWork(() -> PacketMachineUseRealise.handleEachSide(packet, context.getSender()));
|
|
||||||
}
|
|
||||||
else if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT)
|
|
||||||
{
|
|
||||||
context.enqueueWork(() -> PacketMachineUseRealise.handleClientSide(packet));
|
|
||||||
}
|
|
||||||
context.setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public static void handleClientSide(PacketMachineUseRealise packet)
|
|
||||||
{
|
|
||||||
handleEachSide(packet, Minecraft.getInstance().player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handleEachSide(PacketMachineUseRealise packet, PlayerEntity player)
|
|
||||||
{
|
|
||||||
if(packet == null || player == null || player.level == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = player.level.getEntity(packet.entityid);
|
|
||||||
if (!(entity instanceof Machine))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Machine machine = (Machine) entity;
|
|
||||||
|
|
||||||
machine.useRealise();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package magistu.siegemachines.network;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
|
||||||
public class PacketOpenMachineInventory
|
|
||||||
{
|
|
||||||
public PacketOpenMachineInventory() {}
|
|
||||||
|
|
||||||
public static PacketOpenMachineInventory read(PacketBuffer buf)
|
|
||||||
{
|
|
||||||
return new PacketOpenMachineInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(PacketOpenMachineInventory message, PacketBuffer buf) {}
|
|
||||||
|
|
||||||
public static class Handler
|
|
||||||
{
|
|
||||||
public static void handle(PacketOpenMachineInventory packet, Supplier<NetworkEvent.Context> ctx)
|
|
||||||
{
|
|
||||||
NetworkEvent.Context context = ctx.get();
|
|
||||||
if (context.getDirection().getReceptionSide() == LogicalSide.SERVER)
|
|
||||||
{
|
|
||||||
context.enqueueWork(() -> PacketOpenMachineInventory.handleServerSide(packet, context.getSender()));
|
|
||||||
}
|
|
||||||
context.setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handleServerSide(PacketOpenMachineInventory packet, ServerPlayerEntity player)
|
|
||||||
{
|
|
||||||
if(packet == null || player == null || !player.isPassenger())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = player.getVehicle();
|
|
||||||
if (!(entity instanceof Machine))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Machine machine = (Machine) entity;
|
|
||||||
|
|
||||||
machine.openInventoryGui();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package magistu.siegemachines.server;
|
|
||||||
|
|
||||||
import magistu.siegemachines.proxy.IProxy;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
||||||
|
|
||||||
public class ServerProxy implements IProxy
|
|
||||||
{
|
|
||||||
public void setup(IEventBus modEventBus, IEventBus forgeEventBus) {}
|
|
||||||
|
|
||||||
public void clientSetup(FMLClientSetupEvent event) {}
|
|
||||||
|
|
||||||
public void onPreInit() {}
|
|
||||||
}
|
|
54
src/main/java/ru/magistu/siegemachines/SiegeMachines.java
Normal file
54
src/main/java/ru/magistu/siegemachines/SiegeMachines.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package ru.magistu.siegemachines;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import ru.magistu.siegemachines.block.ModBlocks;
|
||||||
|
import ru.magistu.siegemachines.client.ClientProxy;
|
||||||
|
import ru.magistu.siegemachines.client.SoundTypes;
|
||||||
|
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
|
||||||
|
import ru.magistu.siegemachines.config.SpecsConfig;
|
||||||
|
import ru.magistu.siegemachines.entity.EntityTypes;
|
||||||
|
import ru.magistu.siegemachines.item.ModItems;
|
||||||
|
import ru.magistu.siegemachines.item.recipes.ModRecipes;
|
||||||
|
import ru.magistu.siegemachines.network.PacketHandler;
|
||||||
|
import ru.magistu.siegemachines.proxy.IProxy;
|
||||||
|
import ru.magistu.siegemachines.server.ServerProxy;
|
||||||
|
|
||||||
|
@Mod(SiegeMachines.ID)
|
||||||
|
public class SiegeMachines {
|
||||||
|
public static final String ID = "siegemachines";
|
||||||
|
|
||||||
|
public static final IProxy PROXY = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> ServerProxy::new);
|
||||||
|
public static final int RENDER_UPDATE_RANGE = 128;
|
||||||
|
public static final int RENDER_UPDATE_TIME = 20;
|
||||||
|
public static final int RENDER_UPDATE_RANGE_SQR = RENDER_UPDATE_RANGE * RENDER_UPDATE_RANGE;
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
|
public SiegeMachines() {
|
||||||
|
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
|
||||||
|
|
||||||
|
EntityTypes.register(eventBus);
|
||||||
|
SoundTypes.register(eventBus);
|
||||||
|
ModMenuTypes.register(eventBus);
|
||||||
|
ModBlocks.register(eventBus);
|
||||||
|
ModItems.register(eventBus);
|
||||||
|
ModRecipes.register(eventBus);
|
||||||
|
SpecsConfig.register();
|
||||||
|
|
||||||
|
PacketHandler.init();
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doClientStuff(final FMLClientSetupEvent event) {
|
||||||
|
PROXY.clientSetup(event);
|
||||||
|
}
|
||||||
|
}
|
49
src/main/java/ru/magistu/siegemachines/block/ModBlocks.java
Normal file
49
src/main/java/ru/magistu/siegemachines/block/ModBlocks.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package ru.magistu.siegemachines.block;
|
||||||
|
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.item.*;
|
||||||
|
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.BlockBehaviour;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
import ru.magistu.siegemachines.item.ModItems;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class ModBlocks {
|
||||||
|
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, SiegeMachines.ID);
|
||||||
|
|
||||||
|
public static final RegistryObject<SiegeWorkbench> SIEGE_WORKBENCH = registerBlock("siege_workbench", () -> new SiegeWorkbench(BlockBehaviour.Properties.copy(Blocks.CRAFTING_TABLE).noOcclusion()), ModItems.GROUP_SM);
|
||||||
|
|
||||||
|
private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, CreativeModeTab tab, String tooltipKey) {
|
||||||
|
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(),
|
||||||
|
new Item.Properties()) {
|
||||||
|
@Override
|
||||||
|
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
|
||||||
|
pTooltip.add(Component.translatable(tooltipKey));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block, CreativeModeTab tab) {
|
||||||
|
RegistryObject<T> toReturn = BLOCKS.register(name, block);
|
||||||
|
registerBlockItem(name, toReturn, tab);
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, CreativeModeTab tab) {
|
||||||
|
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(),
|
||||||
|
new Item.Properties()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(IEventBus eventBus) {
|
||||||
|
BLOCKS.register(eventBus);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package ru.magistu.siegemachines.block;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
|
import net.minecraft.world.MenuProvider;
|
||||||
|
import net.minecraft.world.SimpleMenuProvider;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.CraftingTableBlock;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.magistu.siegemachines.client.gui.workbench.SiegeWorkbenchContainer;
|
||||||
|
|
||||||
|
public class SiegeWorkbench extends CraftingTableBlock {
|
||||||
|
private static final Component CONTAINER_TITLE = Component.translatable("container.crafting");
|
||||||
|
|
||||||
|
public SiegeWorkbench(Properties p_i48422_1_) {
|
||||||
|
super(p_i48422_1_);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull InteractionResult use(@NotNull BlockState blockstate, Level level, @NotNull BlockPos blockpos, @NotNull Player player, @NotNull InteractionHand hand, @NotNull BlockHitResult result) {
|
||||||
|
if (level.isClientSide) {
|
||||||
|
return InteractionResult.SUCCESS;
|
||||||
|
} else {
|
||||||
|
NetworkHooks.openScreen((ServerPlayer) player, this.getMenuProvider(blockstate, level, blockpos));
|
||||||
|
return InteractionResult.CONSUME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MenuProvider getMenuProvider(@NotNull BlockState blockstate, @NotNull Level level, @NotNull BlockPos blockpos) {
|
||||||
|
return new SimpleMenuProvider((p_220270_2_, p_220270_3_, p_220270_4_) ->
|
||||||
|
new SiegeWorkbenchContainer(p_220270_2_, p_220270_3_, ContainerLevelAccess.create(level, blockpos)), CONTAINER_TITLE);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package ru.magistu.siegemachines.client;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.entity.ThrownItemRenderer;
|
||||||
|
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
import ru.magistu.siegemachines.client.renderer.*;
|
||||||
|
import ru.magistu.siegemachines.entity.EntityTypes;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(modid = SiegeMachines.ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||||
|
public class ClientListener {
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) {
|
||||||
|
event.registerEntityRenderer(EntityTypes.MORTAR.get(), MortarGeoRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.CULVERIN.get(), CulverinGeoRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.TREBUCHET.get(), TrebuchetGeoRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.CATAPULT.get(), CatapultGeoRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.BALLISTA.get(), BallistaGeoRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.BATTERING_RAM.get(), BatteringRamGeoRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.SIEGE_LADDER.get(), SiegeLadderGeoRenderer::new);
|
||||||
|
|
||||||
|
event.registerEntityRenderer(EntityTypes.CANNONBALL.get(), ThrownItemRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.GIANT_STONE.get(), ThrownItemRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.STONE.get(), ThrownItemRenderer::new);
|
||||||
|
event.registerEntityRenderer(EntityTypes.GIANT_ARROW.get(), GiantArrowRenderer::new);
|
||||||
|
|
||||||
|
event.registerEntityRenderer(EntityTypes.SEAT.get(), SeatRenderer::new);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package ru.magistu.siegemachines.client;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.screens.MenuScreens;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
|
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
|
||||||
|
import ru.magistu.siegemachines.client.gui.machine.MachineInventoryScreen;
|
||||||
|
import ru.magistu.siegemachines.client.gui.workbench.SiegeWorkbenchScreen;
|
||||||
|
import ru.magistu.siegemachines.proxy.IProxy;
|
||||||
|
|
||||||
|
public class ClientProxy implements IProxy {
|
||||||
|
public void setup(IEventBus modEventBus, IEventBus forgeEventBus) {
|
||||||
|
modEventBus.addListener(this::clientSetup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clientSetup(FMLClientSetupEvent event) {
|
||||||
|
MenuScreens.register(ModMenuTypes.MACHINE_CONTAINER.get(), MachineInventoryScreen::new);
|
||||||
|
MenuScreens.register(ModMenuTypes.SIEGE_WORKBENCH_CONTAINER.get(), SiegeWorkbenchScreen::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPreInit() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package ru.magistu.siegemachines.client;
|
||||||
|
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.MachineType;
|
||||||
|
|
||||||
|
public class KeyBindings {
|
||||||
|
public static KeyMapping MACHINE_USE = new KeyMapping(SiegeMachines.ID + ".machine_use", 70, SiegeMachines.ID + ".category");
|
||||||
|
public static KeyMapping LADDER_CLIMB = new KeyMapping(SiegeMachines.ID + ".ladder_climb", 32, SiegeMachines.ID + ".category");
|
||||||
|
public static KeyMapping MACHINE_INVENTORY = new KeyMapping(SiegeMachines.ID + ".machine_inventory", 73, SiegeMachines.ID + ".category");
|
||||||
|
|
||||||
|
public static KeyMapping getUseKey(MachineType type) {
|
||||||
|
if (type == MachineType.SIEGE_LADDER)
|
||||||
|
return LADDER_CLIMB;
|
||||||
|
return MACHINE_USE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package ru.magistu.siegemachines.client;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
|
||||||
|
public class SoundTypes {
|
||||||
|
public static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS,
|
||||||
|
SiegeMachines.ID);
|
||||||
|
|
||||||
|
public static RegistryObject<SoundEvent> TREBUCHET_SHOOTING = SOUNDS.register("trebuchet_shooting",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "trebuchet_shooting")));
|
||||||
|
public static RegistryObject<SoundEvent> TREBUCHET_RELOADING = SOUNDS.register("trebuchet_reloading",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "trebuchet_reloading")));
|
||||||
|
public static RegistryObject<SoundEvent> CATAPULT_SHOOTING = SOUNDS.register("catapult_shooting",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "catapult_shooting")));
|
||||||
|
public static RegistryObject<SoundEvent> CATAPULT_RELOADING = SOUNDS.register("catapult_reloading",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "catapult_reloading")));
|
||||||
|
public static RegistryObject<SoundEvent> BALLISTA_SHOOTING = SOUNDS.register("ballista_shooting",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "ballista_shooting")));
|
||||||
|
public static RegistryObject<SoundEvent> BALLISTA_RELOADING = SOUNDS.register("ballista_reloading",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "ballista_reloading")));
|
||||||
|
public static RegistryObject<SoundEvent> MORTAR_SHOOTING = SOUNDS.register("mortar_shooting",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "mortar_shooting")));
|
||||||
|
public static RegistryObject<SoundEvent> FUSE = SOUNDS.register("fuse",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "fuse")));
|
||||||
|
public static RegistryObject<SoundEvent> CANNON_WHEELS = SOUNDS.register("cannon_wheels",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "cannon_wheels")));
|
||||||
|
public static RegistryObject<SoundEvent> RAM_WHEELS = SOUNDS.register("ram_wheels",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "ram_wheels")));
|
||||||
|
public static RegistryObject<SoundEvent> RAM_HITTING = SOUNDS.register("ram_hitting",
|
||||||
|
() -> SoundEvent.createVariableRangeEvent(new ResourceLocation(SiegeMachines.ID, "ram_hitting")));
|
||||||
|
|
||||||
|
public static void register(IEventBus eventBus) {
|
||||||
|
SOUNDS.register(eventBus);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui;
|
||||||
|
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
import ru.magistu.siegemachines.client.gui.machine.MachineContainer;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.network.IContainerFactory;
|
||||||
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
import ru.magistu.siegemachines.client.gui.workbench.SiegeWorkbenchContainer;
|
||||||
|
|
||||||
|
public class ModMenuTypes {
|
||||||
|
public static final DeferredRegister<MenuType<?>> MENUS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, SiegeMachines.ID);
|
||||||
|
|
||||||
|
public static final RegistryObject<MenuType<MachineContainer>> MACHINE_CONTAINER = MENUS.register("machine", () -> IForgeMenuType.create(MachineContainer::new));
|
||||||
|
public static final RegistryObject<MenuType<SiegeWorkbenchContainer>> SIEGE_WORKBENCH_CONTAINER = registerMenuType(SiegeWorkbenchContainer::new, "siege_workbench");
|
||||||
|
|
||||||
|
private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> registerMenuType(IContainerFactory<T> factory, String name) {
|
||||||
|
return MENUS.register(name, () -> IForgeMenuType.create(factory));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(IEventBus eventBus) {
|
||||||
|
MENUS.register(eventBus);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,102 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui.machine;
|
||||||
|
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Machine;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class MachineContainer extends AbstractContainerMenu {
|
||||||
|
private Machine machine;
|
||||||
|
|
||||||
|
public MachineContainer(final int id, final Inventory inv, final Machine machine) {
|
||||||
|
super(ModMenuTypes.MACHINE_CONTAINER.get(), id);
|
||||||
|
if (machine == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.machine = machine;
|
||||||
|
|
||||||
|
for (int row = 0; row < 3; row++) {
|
||||||
|
for (int col = 0; col < 9; col++) {
|
||||||
|
this.addSlot(new Slot(inv, col + row * 9 + 9, 8 + col * 18, 166 - (4 - row) * 18 - 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int col = 0; col < 9; col++) {
|
||||||
|
this.addSlot(new Slot(inv, col, 8 + col * 18, 142));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int row = 0; row < 1; row++) {
|
||||||
|
for (int col = 0; col < 9; col++) {
|
||||||
|
this.addSlot(new Slot(machine.inventory, col + row * 9, 8 + col * 18, 18 + row * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MachineContainer(final int id, final Inventory inv, final FriendlyByteBuf data) {
|
||||||
|
this(id, inv, getMachine(inv));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Machine getMachine(final Inventory inv) {
|
||||||
|
Objects.requireNonNull(inv, "Player Inventory Cannot Be Null.");
|
||||||
|
Player player = inv.player;
|
||||||
|
Entity entity;
|
||||||
|
if (player.isPassenger()) {
|
||||||
|
entity = player.getVehicle();
|
||||||
|
if (entity instanceof Machine) {
|
||||||
|
return (Machine) player.getVehicle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalStateException("Entity Is Not Correct.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stillValid(Player player) {
|
||||||
|
return machine.inventory.stillValid(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ItemStack quickMoveStack(@NotNull Player player, int index) {
|
||||||
|
ItemStack itemstack = ItemStack.EMPTY;
|
||||||
|
Slot slot = this.slots.get(index);
|
||||||
|
if (slot != null && slot.hasItem()) {
|
||||||
|
ItemStack itemstack1 = slot.getItem();
|
||||||
|
itemstack = itemstack1.copy();
|
||||||
|
if (index < 9) {
|
||||||
|
if (!this.moveItemStackTo(itemstack1, 9, this.slots.size(), true)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
slot.onQuickCraft(itemstack1, itemstack);
|
||||||
|
} else if (!this.moveItemStackTo(itemstack1, 0, 9, false)) {
|
||||||
|
if (index < 9 + 27) {
|
||||||
|
if (!this.moveItemStackTo(itemstack1, 9 + 27, this.slots.size(), true)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!this.moveItemStackTo(itemstack1, 9, 9 + 27, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
if (itemstack1.getCount() == 0) {
|
||||||
|
slot.set(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
slot.setChanged();
|
||||||
|
}
|
||||||
|
if (itemstack1.getCount() == itemstack.getCount()) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
slot.onTake(player, itemstack1);
|
||||||
|
}
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui.machine;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public class MachineInventoryScreen extends AbstractContainerScreen<MachineContainer> {
|
||||||
|
private static final ResourceLocation DISPLAY_CASE_GUI = new ResourceLocation(SiegeMachines.ID,
|
||||||
|
"textures/gui/machine_inventory.png");
|
||||||
|
|
||||||
|
public MachineInventoryScreen(MachineContainer screenContainer, Inventory inv, Component titleIn) {
|
||||||
|
super(screenContainer, inv, titleIn);
|
||||||
|
|
||||||
|
this.leftPos = 0;
|
||||||
|
this.topPos = 0;
|
||||||
|
this.imageWidth = 176;
|
||||||
|
this.imageHeight = 166;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(GuiGraphics matrixStack, int mouseX, int mouseY, float partialTicks) {
|
||||||
|
this.renderBackground(matrixStack);
|
||||||
|
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||||
|
this.renderTooltip(matrixStack, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderTooltip(@NotNull GuiGraphics matrixStack, int x, int y) {
|
||||||
|
if (this.minecraft.player.getInventory().getSelected().isEmpty() && this.hoveredSlot != null && this.hoveredSlot.hasItem()) {
|
||||||
|
this.renderTooltip(matrixStack, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderBg(@NotNull GuiGraphics matrixStack, float partialTicks, int mouseX, int mouseY) {
|
||||||
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
RenderSystem.setShaderTexture(0, DISPLAY_CASE_GUI);
|
||||||
|
int x = (this.width - this.imageWidth) / 2;
|
||||||
|
int y = (this.height - this.imageHeight) / 2;
|
||||||
|
matrixStack.blit(DISPLAY_CASE_GUI, x, y, 0, 0, this.imageWidth, this.imageHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyPressed(int key, int b, int c) {
|
||||||
|
assert this.minecraft != null;
|
||||||
|
if (key == 256) {
|
||||||
|
assert this.minecraft.player != null;
|
||||||
|
this.minecraft.player.closeContainer();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.keyPressed(key, b, c);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui.machine.crosshair;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AlignmentHelper
|
||||||
|
{
|
||||||
|
public static final List<String> validAlignmentValues = Arrays.asList(new String[] { "top_left", "top_center", "top_right", "center_left", "center", "center_right", "bottom_left", "bottom_center", "bottom_right" });
|
||||||
|
|
||||||
|
public enum Alignment
|
||||||
|
{
|
||||||
|
TOP_LEFT,
|
||||||
|
TOP_CENTER,
|
||||||
|
TOP_RIGHT,
|
||||||
|
CENTER_LEFT,
|
||||||
|
CENTER,
|
||||||
|
CENTER_RIGHT,
|
||||||
|
BOTTOM_LEFT,
|
||||||
|
BOTTOM_CENTER,
|
||||||
|
BOTTOM_RIGHT;
|
||||||
|
|
||||||
|
|
||||||
|
public static Alignment fromString(String align) {
|
||||||
|
int idx = AlignmentHelper.validAlignmentValues.indexOf(align);
|
||||||
|
if (idx != -1) {
|
||||||
|
return values()[idx];
|
||||||
|
}
|
||||||
|
return CENTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui.machine.crosshair;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public abstract class Crosshair extends HudElement
|
||||||
|
{
|
||||||
|
protected static final ResourceLocation CROSSHAIR_TEXTURES = new ResourceLocation(SiegeMachines.ID, "textures/gui/crosshairs.png");
|
||||||
|
|
||||||
|
public Crosshair(int width, int height)
|
||||||
|
{
|
||||||
|
super(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void render(GuiGraphics matrixstack, float partialticks) {}
|
||||||
|
|
||||||
|
public abstract void render(GuiGraphics matrixstack, float ticks, Minecraft mc, Player player);
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package magistu.siegemachines.gui;
|
package ru.magistu.siegemachines.client.gui.machine.crosshair;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
@ -68,6 +68,4 @@ public abstract class HudElement
|
|||||||
{
|
{
|
||||||
return this.height;
|
return this.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void render(MatrixStack paramMatrixStack, float paramFloat);
|
|
||||||
}
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui.machine.crosshair;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Machine;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public class ReloadingCrosshair extends Crosshair
|
||||||
|
{
|
||||||
|
//public static ResourceLocation TYPE = new ResourceLocation(SiegeMachines.ID, "siege_machine");
|
||||||
|
public int x;
|
||||||
|
public int y;
|
||||||
|
|
||||||
|
public ReloadingCrosshair()
|
||||||
|
{
|
||||||
|
super(9, 9);
|
||||||
|
this.x = Minecraft.getInstance().getWindow().getGuiScaledWidth() / 2;
|
||||||
|
this.y = Minecraft.getInstance().getWindow().getGuiScaledHeight() / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(GuiGraphics matrixstack, float ticks, Minecraft mc, Player player)
|
||||||
|
{
|
||||||
|
RenderSystem.assertOnRenderThread();
|
||||||
|
|
||||||
|
if (!player.isPassenger())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Entity entity = player.getVehicle();
|
||||||
|
|
||||||
|
if (entity instanceof Machine)
|
||||||
|
{
|
||||||
|
Machine machine = (Machine) entity;
|
||||||
|
|
||||||
|
int width = 11;
|
||||||
|
int height = 11;
|
||||||
|
int imagex = 0;
|
||||||
|
int imagey = 0;
|
||||||
|
int originx = (mc.getWindow().getGuiScaledWidth() - width) / 2;
|
||||||
|
int originy = (mc.getWindow().getGuiScaledHeight() - height) / 2;
|
||||||
|
int animationsize = 23;
|
||||||
|
if (machine.useticks > 0)
|
||||||
|
{
|
||||||
|
imagey = height;
|
||||||
|
}
|
||||||
|
else if (machine.delayticks > 0)
|
||||||
|
{
|
||||||
|
int number = (int) (((double) animationsize) * ((double) (machine.type.specs.delaytime.get() - machine.delayticks) / (double) machine.type.specs.delaytime.get()));
|
||||||
|
imagex = width;
|
||||||
|
imagey = height * number;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderSystem.applyModelViewMatrix();
|
||||||
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
|
RenderSystem.setShaderTexture(0, CROSSHAIR_TEXTURES);
|
||||||
|
|
||||||
|
matrixstack.blit(CROSSHAIR_TEXTURES, originx, originy, imagex, imagey, width, height);
|
||||||
|
|
||||||
|
RenderSystem.backupProjectionMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,196 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui.workbench;
|
||||||
|
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.player.StackedContents;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.*;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.crafting.Recipe;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import ru.magistu.siegemachines.block.ModBlocks;
|
||||||
|
import ru.magistu.siegemachines.item.recipes.ModRecipes;
|
||||||
|
import ru.magistu.siegemachines.item.recipes.SiegeWorkbenchRecipe;
|
||||||
|
import ru.magistu.siegemachines.client.gui.ModMenuTypes;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class SiegeWorkbenchContainer extends AbstractContainerMenu
|
||||||
|
{
|
||||||
|
private final CraftingContainer craftSlots = new CraftingContainer(this, 3, 3);
|
||||||
|
private final ResultContainer resultSlots = new ResultContainer();
|
||||||
|
private final ContainerLevelAccess access;
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
|
public SiegeWorkbenchContainer(int id, Inventory inventory, FriendlyByteBuf buffer)
|
||||||
|
{
|
||||||
|
this(id, inventory, ContainerLevelAccess.NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SiegeWorkbenchContainer(int id, Inventory inventory, ContainerLevelAccess access)
|
||||||
|
{
|
||||||
|
super(ModMenuTypes.SIEGE_WORKBENCH_CONTAINER.get(), id);
|
||||||
|
this.access = access;
|
||||||
|
this.player = inventory.player;
|
||||||
|
this.addSlot(new SiegeWorkbenchResultSlot(inventory.player, this.craftSlots, this.resultSlots, 0, 124, 35));
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 3; ++j)
|
||||||
|
{
|
||||||
|
this.addSlot(new Slot(this.craftSlots, j + i * 3, 30 + j * 18, 17 + i * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int k = 0; k < 3; ++k)
|
||||||
|
{
|
||||||
|
for (int i1 = 0; i1 < 9; ++i1)
|
||||||
|
{
|
||||||
|
this.addSlot(new Slot(inventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int l = 0; l < 9; ++l)
|
||||||
|
{
|
||||||
|
this.addSlot(new Slot(inventory, l, 8 + l * 18, 142));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// to create resulting item
|
||||||
|
protected static void slotChangedCraftingGrid(AbstractContainerMenu menu, Level level, Player player, CraftingContainer craftingcontainer, ResultContainer resultcontainer) {
|
||||||
|
if (!level.isClientSide) {
|
||||||
|
ServerPlayer serverplayer = (ServerPlayer)player;
|
||||||
|
ItemStack itemstack = ItemStack.EMPTY;
|
||||||
|
Optional<SiegeWorkbenchRecipe> optional = level.getServer().getRecipeManager().getRecipeFor(ModRecipes.SIEGE_WORKBENCH_RECIPE, craftingcontainer, level);
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
SiegeWorkbenchRecipe craftingrecipe = optional.get();
|
||||||
|
if (resultcontainer.setRecipeUsed(level, serverplayer, craftingrecipe)) {
|
||||||
|
itemstack = craftingrecipe.assemble(craftingcontainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resultcontainer.setItem(0, itemstack);
|
||||||
|
//menu.setRemoteSlot(0, itemstack);
|
||||||
|
serverplayer.connection.send(new ClientboundContainerSetSlotPacket(menu.containerId, menu.incrementStateId(), 0, itemstack));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void slotsChanged(Container inventory) {
|
||||||
|
this.access.execute((level, blockpos) -> slotChangedCraftingGrid(this, level, this.player, this.craftSlots, this.resultSlots));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillCraftSlotsStackedContents(StackedContents itemhelper) {
|
||||||
|
this.craftSlots.fillStackedContents(itemhelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearCraftingContent() {
|
||||||
|
this.craftSlots.clearContent();
|
||||||
|
this.resultSlots.clearContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean recipeMatches(Recipe<? super CraftingContainer> recipe) {
|
||||||
|
return recipe.matches(this.craftSlots, this.player.level);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the container is closed.
|
||||||
|
*/
|
||||||
|
public void removed(Player player) {
|
||||||
|
super.removed(player);
|
||||||
|
this.access.execute((p_39371_, p_39372_) -> {
|
||||||
|
this.clearContainer(player, this.craftSlots);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether supplied player can use this container
|
||||||
|
*/
|
||||||
|
public boolean stillValid(Player player) {
|
||||||
|
return stillValid(this.access, player, ModBlocks.SIEGE_WORKBENCH.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
|
||||||
|
* inventory and the other inventory(s).
|
||||||
|
*/
|
||||||
|
public ItemStack quickMoveStack(Player player, int index) {
|
||||||
|
ItemStack itemstack = ItemStack.EMPTY;
|
||||||
|
Slot slot = this.slots.get(index);
|
||||||
|
if (slot != null && slot.hasItem()) {
|
||||||
|
ItemStack itemstack1 = slot.getItem();
|
||||||
|
itemstack = itemstack1.copy();
|
||||||
|
if (index == 0) {
|
||||||
|
this.access.execute((p_39378_, p_39379_) -> {
|
||||||
|
itemstack1.getItem().onCraftedBy(itemstack1, p_39378_, player);
|
||||||
|
});
|
||||||
|
if (!this.moveItemStackTo(itemstack1, 10, 46, true)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot.onQuickCraft(itemstack1, itemstack);
|
||||||
|
} else if (index >= 10 && index < 46) {
|
||||||
|
if (!this.moveItemStackTo(itemstack1, 1, 10, false)) {
|
||||||
|
if (index < 37) {
|
||||||
|
if (!this.moveItemStackTo(itemstack1, 37, 46, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (!this.moveItemStackTo(itemstack1, 10, 37, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!this.moveItemStackTo(itemstack1, 10, 46, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemstack1.isEmpty()) {
|
||||||
|
slot.set(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
slot.setChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemstack1.getCount() == itemstack.getCount()) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot.onTake(player, itemstack1);
|
||||||
|
if (index == 0) {
|
||||||
|
player.drop(itemstack1, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in is
|
||||||
|
* null for the initial slot that was double-clicked.
|
||||||
|
*/
|
||||||
|
public boolean canTakeItemForPickAll(ItemStack stack, Slot slot) {
|
||||||
|
return slot.container != this.resultSlots && super.canTakeItemForPickAll(stack, slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResultSlotIndex() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGridWidth() {
|
||||||
|
return this.craftSlots.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGridHeight() {
|
||||||
|
return this.craftSlots.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldMoveToInventory(int p_150553_) {
|
||||||
|
return p_150553_ != this.getResultSlotIndex();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui.workbench;
|
||||||
|
|
||||||
|
import net.minecraft.core.NonNullList;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.CraftingContainer;
|
||||||
|
import net.minecraft.world.inventory.RecipeHolder;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeManager;
|
||||||
|
import ru.magistu.siegemachines.item.recipes.ModRecipes;
|
||||||
|
|
||||||
|
public class SiegeWorkbenchResultSlot extends Slot {
|
||||||
|
private final CraftingContainer craftSlots;
|
||||||
|
private final Player player;
|
||||||
|
private int removeCount;
|
||||||
|
|
||||||
|
public SiegeWorkbenchResultSlot(Player player, CraftingContainer craftingcontainer, Container container, int index, int x, int y) {
|
||||||
|
super(container, index, x, y);
|
||||||
|
this.player = player;
|
||||||
|
this.craftSlots = craftingcontainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
|
||||||
|
*/
|
||||||
|
public boolean mayPlace(ItemStack stack) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new stack.
|
||||||
|
*/
|
||||||
|
public ItemStack remove(int amount) {
|
||||||
|
if (this.hasItem()) {
|
||||||
|
this.removeCount += Math.min(amount, this.getItem().getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.remove(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
|
||||||
|
* internal count then calls onCrafting(item).
|
||||||
|
*/
|
||||||
|
protected void onQuickCraft(ItemStack stack, int amount) {
|
||||||
|
this.removeCount += amount;
|
||||||
|
this.checkTakeAchievements(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onSwapCraft(int pNumItemsCrafted) {
|
||||||
|
this.removeCount += pNumItemsCrafted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
|
||||||
|
*/
|
||||||
|
protected void checkTakeAchievements(ItemStack stack) {
|
||||||
|
if (this.removeCount > 0) {
|
||||||
|
stack.onCraftedBy(this.player.level(), this.player, this.removeCount);
|
||||||
|
net.minecraftforge.event.ForgeEventFactory.firePlayerCraftingEvent(this.player, stack, this.craftSlots);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.container instanceof RecipeHolder) {
|
||||||
|
((RecipeHolder) this.container).awardUsedRecipes(this.player, this.craftSlots.getItems()); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
this.removeCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onTake(Player player, ItemStack stack) {
|
||||||
|
this.checkTakeAchievements(stack);
|
||||||
|
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(player);
|
||||||
|
RecipeManager manager = player.level().getRecipeManager();
|
||||||
|
NonNullList<ItemStack> nonnulllist = manager.getRemainingItemsFor(ModRecipes.SIEGE_WORKBENCH_RECIPE, craftSlots, player.level());
|
||||||
|
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
|
||||||
|
for (int i = 0; i < nonnulllist.size(); ++i) {
|
||||||
|
ItemStack itemstack = this.craftSlots.getItem(i);
|
||||||
|
ItemStack itemstack1 = nonnulllist.get(i);
|
||||||
|
if (!itemstack.isEmpty()) {
|
||||||
|
this.craftSlots.removeItem(i, itemstack1.getCount());
|
||||||
|
itemstack = this.craftSlots.getItem(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!itemstack1.isEmpty()) {
|
||||||
|
if (itemstack.isEmpty()) {
|
||||||
|
this.craftSlots.setItem(i, itemstack1);
|
||||||
|
} else if (ItemStack.isSameItem(itemstack, itemstack1) && ItemStack.matches(itemstack, itemstack1)) {
|
||||||
|
itemstack1.grow(itemstack.getCount());
|
||||||
|
this.craftSlots.setItem(i, itemstack1);
|
||||||
|
} else if (!this.player.getInventory().add(itemstack1)) {
|
||||||
|
this.player.drop(itemstack1, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package ru.magistu.siegemachines.client.gui.workbench;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public class SiegeWorkbenchScreen extends AbstractContainerScreen<SiegeWorkbenchContainer> {
|
||||||
|
private static final ResourceLocation DISPLAY_CASE_GUI = new ResourceLocation(SiegeMachines.ID, "textures/gui/siege_workbench.png");
|
||||||
|
|
||||||
|
public SiegeWorkbenchScreen(SiegeWorkbenchContainer screenContainer, Inventory inv, Component titleIn) {
|
||||||
|
super(screenContainer, inv, titleIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(GuiGraphics matrixStack, int mouseX, int mouseY, float partialTicks) {
|
||||||
|
this.renderBackground(matrixStack);
|
||||||
|
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||||
|
this.renderTooltip(matrixStack, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderTooltip(@NotNull GuiGraphics matrixStack, int x, int y) {
|
||||||
|
if (this.minecraft.player.getInventory().getSelected().isEmpty() && this.hoveredSlot != null && this.hoveredSlot.hasItem()) {
|
||||||
|
this.renderTooltip(matrixStack, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
this.titleLabelX = 29;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderBg(@NotNull GuiGraphics matrixStack, float partialTicks, int mouseX, int mouseY) {
|
||||||
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
RenderSystem.setShaderTexture(0, DISPLAY_CASE_GUI);
|
||||||
|
int i = this.leftPos;
|
||||||
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
|
matrixStack.blit(DISPLAY_CASE_GUI, i, j, 0, 0, this.imageWidth, this.imageHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyPressed(int key, int b, int c) {
|
||||||
|
assert this.minecraft != null;
|
||||||
|
if (key == 256) {
|
||||||
|
assert this.minecraft.player != null;
|
||||||
|
this.minecraft.player.closeContainer();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.keyPressed(key, b, c);
|
||||||
|
}
|
||||||
|
}
|
@ -1,41 +1,38 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
import magistu.siegemachines.client.renderer.model.MachineModel;
|
import ru.magistu.siegemachines.client.renderer.model.MachineModel;
|
||||||
import magistu.siegemachines.entity.machine.Ballista;
|
import ru.magistu.siegemachines.entity.machine.Ballista;
|
||||||
import magistu.siegemachines.entity.projectile.ProjectileBuilder;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import magistu.siegemachines.item.ModItems;
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
||||||
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class BallistaGeoRenderer extends MachineGeoRenderer<Ballista>
|
public class BallistaGeoRenderer extends MachineGeoRenderer<Ballista> {
|
||||||
{
|
public BallistaGeoRenderer(EntityRendererProvider.Context renderManager)
|
||||||
public BallistaGeoRenderer(EntityRendererManager renderManager)
|
|
||||||
{
|
{
|
||||||
super(renderManager, new MachineModel<>("ballista"));
|
super(renderManager, new MachineModel<>("ballista"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderType getRenderType(Ballista animatable, float partialTicks, MatrixStack stack,
|
public RenderType getRenderType(Ballista animatable, float partialTicks, PoseStack stack,
|
||||||
IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn,
|
MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
|
||||||
ResourceLocation textureLocation)
|
ResourceLocation textureLocation)
|
||||||
{
|
{
|
||||||
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderEarly(Ballista animatable, MatrixStack stackIn, float ticks, IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float partialTicks)
|
public void renderEarly(Ballista animatable, PoseStack stackIn, float ticks, MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float partialTicks)
|
||||||
{
|
{
|
||||||
GeoModelProvider<Ballista> modelProvider = this.getGeoModelProvider();
|
GeoModelProvider<Ballista> modelProvider = this.getGeoModelProvider();
|
||||||
GeoModel model = modelProvider.getModel(modelProvider.getModelLocation(animatable));
|
GeoModel model = modelProvider.getModel(modelProvider.getModelResource(animatable));
|
||||||
|
|
||||||
Optional<GeoBone> turret = model.getBone("Balliste");
|
Optional<GeoBone> turret = model.getBone("Balliste");
|
||||||
turret.ifPresent(bone -> bone.setRotationX(-animatable.getTurretPitch() * (float) Math.PI / 180.0f));
|
turret.ifPresent(bone -> bone.setRotationX(-animatable.getTurretPitch() * (float) Math.PI / 180.0f));
|
@ -0,0 +1,26 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import ru.magistu.siegemachines.client.renderer.model.MachineModel;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.BatteringRam;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
public class BatteringRamGeoRenderer extends MachineGeoRenderer<BatteringRam>
|
||||||
|
{
|
||||||
|
public BatteringRamGeoRenderer(EntityRendererProvider.Context renderManager)
|
||||||
|
{
|
||||||
|
super(renderManager, new MachineModel<>("battering_ram"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderType getRenderType(BatteringRam animatable, float partialTicks, PoseStack stack,
|
||||||
|
MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
|
||||||
|
ResourceLocation textureLocation)
|
||||||
|
{
|
||||||
|
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import ru.magistu.siegemachines.client.renderer.model.MachineModel;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Catapult;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
public class CatapultGeoRenderer extends MachineGeoRenderer<Catapult>
|
||||||
|
{
|
||||||
|
public CatapultGeoRenderer(EntityRendererProvider.Context renderManager)
|
||||||
|
{
|
||||||
|
super(renderManager, new MachineModel<>("catapult"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderType getRenderType(Catapult animatable, float partialTicks, PoseStack stack,
|
||||||
|
MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
|
||||||
|
ResourceLocation textureLocation)
|
||||||
|
{
|
||||||
|
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import ru.magistu.siegemachines.client.renderer.model.MachineModel;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Culverin;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Culverin;
|
||||||
|
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
||||||
|
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
||||||
|
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class CulverinGeoRenderer extends MachineGeoRenderer<Culverin>
|
||||||
|
{
|
||||||
|
public CulverinGeoRenderer(EntityRendererProvider.Context renderManager)
|
||||||
|
{
|
||||||
|
super(renderManager, new MachineModel<>("culverin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderType getRenderType(Culverin animatable, float partialTicks, PoseStack stack,
|
||||||
|
MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
|
||||||
|
ResourceLocation textureLocation)
|
||||||
|
{
|
||||||
|
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderEarly(Culverin animatable, PoseStack stackIn, float ticks, MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float partialTicks)
|
||||||
|
{
|
||||||
|
GeoModelProvider<Culverin> modelProvider = this.getGeoModelProvider();
|
||||||
|
GeoModel model = modelProvider.getModel(modelProvider.getModelResource(animatable));
|
||||||
|
|
||||||
|
Optional<GeoBone> bone0 = model.getBone("Barrel");
|
||||||
|
bone0.ifPresent(bone -> bone.setRotationX(-animatable.getTurretPitch() * (float) Math.PI / 180.0f));
|
||||||
|
bone0.ifPresent(bone -> bone.setRotationY(-animatable.getTurretYaw() * (float) Math.PI / 180.0f));
|
||||||
|
|
||||||
|
super.renderEarly(animatable, stackIn, ticks, renderTypeBuffer, vertexBuilder, packedLightIn, packedOverlayIn, red, green, blue, partialTicks);
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
import magistu.siegemachines.SiegeMachines;
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
import magistu.siegemachines.client.renderer.model.GiantArrowModel;
|
import ru.magistu.siegemachines.client.renderer.model.GiantArrowModel;
|
||||||
import magistu.siegemachines.entity.projectile.GiantArrow;
|
import ru.magistu.siegemachines.entity.projectile.GiantArrow;
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -21,9 +21,9 @@ public class GiantArrowRenderer extends EntityRenderer<GiantArrow>
|
|||||||
public static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation(SiegeMachines.ID, "textures/entity/giant_arrow.png");
|
public static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation(SiegeMachines.ID, "textures/entity/giant_arrow.png");
|
||||||
// public static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("textures/entity/projectiles/arrow.png");
|
// public static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("textures/entity/projectiles/arrow.png");
|
||||||
|
|
||||||
public GiantArrowModel model = new GiantArrowModel();
|
public GiantArrowModel model = new GiantArrowModel(GiantArrowModel.createModel());
|
||||||
|
|
||||||
public GiantArrowRenderer(EntityRendererManager p_i46547_1_)
|
public GiantArrowRenderer(EntityRendererProvider.Context p_i46547_1_)
|
||||||
{
|
{
|
||||||
super(p_i46547_1_);
|
super(p_i46547_1_);
|
||||||
}
|
}
|
||||||
@ -34,18 +34,18 @@ public class GiantArrowRenderer extends EntityRenderer<GiantArrow>
|
|||||||
return TEXTURE_LOCATION;
|
return TEXTURE_LOCATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(@NotNull GiantArrow giantarrow, float p_225623_2_, float p_225623_3_, @NotNull MatrixStack matrixstack, @NotNull IRenderTypeBuffer buffer, int n)
|
public void render(@NotNull GiantArrow giantarrow, float p_225623_2_, float p_225623_3_, @NotNull PoseStack matrixstack, @NotNull MultiBufferSource buffer, int n)
|
||||||
{
|
{
|
||||||
matrixstack.pushPose();
|
matrixstack.pushPose();
|
||||||
matrixstack.scale(-1.0F, -1.0F, -1.0F);
|
matrixstack.scale(-1.0F, -1.0F, -1.0F);
|
||||||
float f = MathHelper.lerp(p_225623_3_, giantarrow.yRotO, giantarrow.yRot);
|
float f = Mth.lerp(p_225623_3_, giantarrow.yRotO, giantarrow.getYRot());
|
||||||
float f1 = -MathHelper.lerp(p_225623_3_, giantarrow.xRotO, giantarrow.xRot);
|
float f1 = -Mth.lerp(p_225623_3_, giantarrow.xRotO, giantarrow.getXRot());
|
||||||
float f2 = (float) giantarrow.shakeTime - p_225623_3_;
|
float f2 = (float) giantarrow.shakeTime - p_225623_3_;
|
||||||
if (f2 > 0.0F)
|
if (f2 > 0.0F)
|
||||||
{
|
{
|
||||||
f1 -= MathHelper.sin(f2 * 3.0F) * f2;
|
f1 -= Mth.sin(f2 * 3.0F) * f2;
|
||||||
}
|
}
|
||||||
IVertexBuilder ivertexbuilder = buffer.getBuffer(this.model.renderType(this.getTextureLocation(giantarrow)));
|
VertexConsumer ivertexbuilder = buffer.getBuffer(this.model.renderType(this.getTextureLocation(giantarrow)));
|
||||||
this.model.setupAnim(0.0F, f, f1);
|
this.model.setupAnim(0.0F, f, f1);
|
||||||
this.model.renderToBuffer(matrixstack, ivertexbuilder, n, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
|
this.model.renderToBuffer(matrixstack, ivertexbuilder, n, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
matrixstack.popPose();
|
matrixstack.popPose();
|
@ -1,14 +1,14 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
import magistu.siegemachines.entity.machine.Machine;
|
import ru.magistu.siegemachines.entity.machine.Machine;
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
import software.bernie.geckolib3.core.IAnimatable;
|
import software.bernie.geckolib3.core.IAnimatable;
|
||||||
import software.bernie.geckolib3.model.AnimatedGeoModel;
|
import software.bernie.geckolib3.model.AnimatedGeoModel;
|
||||||
import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer;
|
import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer;
|
||||||
|
|
||||||
public abstract class MachineGeoRenderer<T extends Machine & IAnimatable> extends GeoEntityRenderer<T>
|
public abstract class MachineGeoRenderer<T extends Machine & IAnimatable> extends GeoEntityRenderer<T>
|
||||||
{
|
{
|
||||||
protected MachineGeoRenderer(EntityRendererManager rendermanager, AnimatedGeoModel<T> model)
|
protected MachineGeoRenderer(EntityRendererProvider.Context rendermanager, AnimatedGeoModel<T> model)
|
||||||
{
|
{
|
||||||
super(rendermanager, model);
|
super(rendermanager, model);
|
||||||
}
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
|
import ru.magistu.siegemachines.client.renderer.model.MachineItemModel;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Machine;
|
||||||
|
import ru.magistu.siegemachines.item.MachineItem;
|
||||||
|
import software.bernie.geckolib3.renderers.geo.GeoItemRenderer;
|
||||||
|
|
||||||
|
public class MachineItemGeoRenderer<T extends Machine> extends GeoItemRenderer<MachineItem<T>> {
|
||||||
|
public MachineItemGeoRenderer(MachineItemModel<MachineItem<T>> model)
|
||||||
|
{
|
||||||
|
super(model);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
package magistu.siegemachines.client.renderer;
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
import magistu.siegemachines.client.renderer.model.MachineModel;
|
import ru.magistu.siegemachines.client.renderer.model.MachineModel;
|
||||||
import magistu.siegemachines.entity.machine.Mortar;
|
import ru.magistu.siegemachines.entity.machine.Mortar;
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
||||||
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
||||||
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
||||||
@ -16,24 +16,24 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class MortarGeoRenderer extends MachineGeoRenderer<Mortar>
|
public class MortarGeoRenderer extends MachineGeoRenderer<Mortar>
|
||||||
{
|
{
|
||||||
public MortarGeoRenderer(EntityRendererManager renderManager)
|
public MortarGeoRenderer(EntityRendererProvider.Context renderManager)
|
||||||
{
|
{
|
||||||
super(renderManager, new MachineModel<>("mortar"));
|
super(renderManager, new MachineModel<>("mortar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderType getRenderType(Mortar animatable, float partialTicks, MatrixStack stack,
|
public RenderType getRenderType(Mortar animatable, float partialTicks, PoseStack stack,
|
||||||
IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn,
|
MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
|
||||||
ResourceLocation textureLocation)
|
ResourceLocation textureLocation)
|
||||||
{
|
{
|
||||||
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderEarly(Mortar animatable, MatrixStack stackIn, float ticks, IRenderTypeBuffer renderTypeBuffer, IVertexBuilder vertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float partialTicks)
|
public void renderEarly(Mortar animatable, PoseStack stackIn, float ticks, MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float partialTicks)
|
||||||
{
|
{
|
||||||
GeoModelProvider<Mortar> modelProvider = this.getGeoModelProvider();
|
GeoModelProvider<Mortar> modelProvider = this.getGeoModelProvider();
|
||||||
GeoModel model = modelProvider.getModel(modelProvider.getModelLocation(animatable));
|
GeoModel model = modelProvider.getModel(modelProvider.getModelResource(animatable));
|
||||||
|
|
||||||
Optional<GeoBone> bone0 = model.getBone("Barrel");
|
Optional<GeoBone> bone0 = model.getBone("Barrel");
|
||||||
bone0.ifPresent(bone -> bone.setRotationX(-animatable.getTurretPitch() * (float) Math.PI / 180.0f));
|
bone0.ifPresent(bone -> bone.setRotationX(-animatable.getTurretPitch() * (float) Math.PI / 180.0f));
|
@ -0,0 +1,25 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.culling.Frustum;
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Seat;
|
||||||
|
|
||||||
|
public class SeatRenderer extends EntityRenderer<Seat>
|
||||||
|
{
|
||||||
|
public SeatRenderer(EntityRendererProvider.Context p_174008_)
|
||||||
|
{
|
||||||
|
super(p_174008_);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldRender(Seat seat, Frustum camera, double camx, double camy, double camz) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getTextureLocation(Seat pEntity)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
import net.minecraft.client.renderer.culling.Frustum;
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.phys.AABB;
|
||||||
|
import ru.magistu.siegemachines.client.renderer.model.MachineModel;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.BatteringRam;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.SiegeLadder;
|
||||||
|
|
||||||
|
public class SiegeLadderGeoRenderer extends MachineGeoRenderer<SiegeLadder>
|
||||||
|
{
|
||||||
|
public SiegeLadderGeoRenderer(EntityRendererProvider.Context renderManager)
|
||||||
|
{
|
||||||
|
super(renderManager, new MachineModel<>("siege_ladder"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderType getRenderType(SiegeLadder animatable, float partialTicks, PoseStack stack,
|
||||||
|
MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
|
||||||
|
ResourceLocation textureLocation)
|
||||||
|
{
|
||||||
|
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldRender(SiegeLadder animatable, Frustum camera, double camx, double camy, double camz)
|
||||||
|
{
|
||||||
|
if (!animatable.shouldRender(camx, camy, camz)) {
|
||||||
|
return false;
|
||||||
|
} else if (animatable.noCulling) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
AABB aabb = animatable.getBoundingBoxForCulling().inflate(5.0D);
|
||||||
|
if (aabb.hasNaN() || aabb.getSize() == 0.0D) {
|
||||||
|
aabb = new AABB(animatable.getX() - 2.0D, animatable.getY() - 2.0D, animatable.getZ() - 2.0D, animatable.getX() + 2.0D, animatable.getY() + 2.0D, animatable.getZ() + 2.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return camera.isVisible(aabb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import net.minecraft.client.renderer.culling.Frustum;
|
||||||
|
import net.minecraft.world.phys.AABB;
|
||||||
|
import ru.magistu.siegemachines.client.renderer.model.MachineModel;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.SiegeLadder;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Trebuchet;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
||||||
|
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
||||||
|
import software.bernie.geckolib3.model.provider.GeoModelProvider;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class TrebuchetGeoRenderer extends MachineGeoRenderer<Trebuchet>
|
||||||
|
{
|
||||||
|
public TrebuchetGeoRenderer(EntityRendererProvider.Context renderManager)
|
||||||
|
{
|
||||||
|
super(renderManager, new MachineModel<>("trebuchet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderType getRenderType(Trebuchet animatable, float partialTicks, PoseStack stack,
|
||||||
|
MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
|
||||||
|
ResourceLocation textureLocation)
|
||||||
|
{
|
||||||
|
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderEarly(Trebuchet animatable, PoseStack stackIn, float ticks, MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float partialTicks)
|
||||||
|
{
|
||||||
|
GeoModelProvider<Trebuchet> modelProvider = this.getGeoModelProvider();
|
||||||
|
GeoModel model = modelProvider.getModel(modelProvider.getModelResource(animatable));
|
||||||
|
|
||||||
|
Optional<GeoBone> projectile = model.getBone("Cobblestone");
|
||||||
|
int projectilesize = (animatable.state == Trebuchet.State.IDLE_RELOADED || animatable.shootingticks > 0) && animatable.hasAmmo() ? 1 : 0;
|
||||||
|
projectile.ifPresent(bone -> bone.setScaleX(projectilesize));
|
||||||
|
projectile.ifPresent(bone -> bone.setScaleY(projectilesize));
|
||||||
|
projectile.ifPresent(bone -> bone.setScaleZ(projectilesize));
|
||||||
|
|
||||||
|
super.renderEarly(animatable, stackIn, ticks, renderTypeBuffer, vertexBuilder, packedLightIn, packedOverlayIn, red, green, blue, partialTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldRender(Trebuchet animatable, Frustum camera, double camx, double camy, double camz)
|
||||||
|
{
|
||||||
|
if (!animatable.shouldRender(camx, camy, camz)) {
|
||||||
|
return false;
|
||||||
|
} else if (animatable.noCulling) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
AABB aabb = animatable.getBoundingBoxForCulling().inflate(10.0D);
|
||||||
|
if (aabb.hasNaN() || aabb.getSize() == 0.0D) {
|
||||||
|
aabb = new AABB(animatable.getX() - 2.0D, animatable.getY() - 2.0D, animatable.getZ() - 2.0D, animatable.getX() + 2.0D, animatable.getY() + 2.0D, animatable.getZ() + 2.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return camera.isVisible(aabb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer.model;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import net.minecraft.client.model.Model;
|
||||||
|
import net.minecraft.client.model.geom.ModelPart;
|
||||||
|
import net.minecraft.client.model.geom.PartPose;
|
||||||
|
import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
||||||
|
import net.minecraft.client.model.geom.builders.MeshDefinition;
|
||||||
|
import net.minecraft.client.model.geom.builders.PartDefinition;
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
|
||||||
|
public class GiantArrowModel extends Model {
|
||||||
|
protected final ModelPart cube_r0;
|
||||||
|
protected final ModelPart cube_r1;
|
||||||
|
protected final ModelPart cube_r2;
|
||||||
|
|
||||||
|
public GiantArrowModel(ModelPart p_170945_) {
|
||||||
|
super(RenderType::entityTranslucent);
|
||||||
|
this.cube_r0 = p_170945_;
|
||||||
|
this.cube_r1 = p_170945_.getChild("cube_r1");
|
||||||
|
this.cube_r2 = p_170945_.getChild("cube_r2");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModelPart createModel() {
|
||||||
|
MeshDefinition meshdefinition = new MeshDefinition();
|
||||||
|
PartDefinition partdefinition = meshdefinition.getRoot();
|
||||||
|
partdefinition.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(15, 0).addBox(-2.0F, 0.0F, -10.0F, 4.0F, 0.0F, 4.0F).texOffs(-34, 0).addBox(-2.5F, 0.0F, -7.0F, 5.0F, 0.0F, 34.0F), PartPose.rotation(0.0F, 0.0F, -0.7854F));
|
||||||
|
partdefinition.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(7, 0).addBox(-2.0F, 0.0F, -10.0F, 4.0F, 0.0F, 4.0F).texOffs(-34, 0).addBox(-2.5F, 0.0F, -7.0F, 5.0F, 0.0F, 34.0F), PartPose.rotation(0.0F, 0.0F, 0.7854F));
|
||||||
|
|
||||||
|
return meshdefinition.getRoot().bake(64, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setupAnim(float p_103811_, float p_103812_, float p_103813_) {
|
||||||
|
this.cube_r0.yRot = p_103812_ * ((float) Math.PI / 180F);
|
||||||
|
this.cube_r0.xRot = p_103813_ * ((float) Math.PI / 180F);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renderToBuffer(PoseStack p_103815_, VertexConsumer p_103816_, int p_103817_, int p_103818_, float p_103819_, float p_103820_, float p_103821_, float p_103822_) {
|
||||||
|
this.cube_r0.render(p_103815_, p_103816_, p_103817_, p_103818_, p_103819_, p_103820_, p_103821_, p_103822_);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer.model;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
import ru.magistu.siegemachines.item.MachineItem;
|
||||||
|
import software.bernie.geckolib.core.animatable.GeoAnimatable;
|
||||||
|
import software.bernie.geckolib.model.GeoModel;
|
||||||
|
|
||||||
|
public class MachineItemModel<T extends MachineItem & GeoAnimatable> extends GeoModel<T> {
|
||||||
|
public final String name;
|
||||||
|
public final ResourceLocation animationlocation;
|
||||||
|
public final ResourceLocation modellocation;
|
||||||
|
public final ResourceLocation texturelocation;
|
||||||
|
|
||||||
|
public MachineItemModel(String name) {
|
||||||
|
this.name = name;
|
||||||
|
this.animationlocation = new ResourceLocation(SiegeMachines.ID, "animations/none.animation.json");
|
||||||
|
this.modellocation = new ResourceLocation(SiegeMachines.ID, "geo/" + this.name + "_item.geo.json");
|
||||||
|
this.texturelocation = new ResourceLocation(SiegeMachines.ID, "textures/entity/" + this.name + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getAnimationResource(T entity) {
|
||||||
|
return this.animationlocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getModelResource(T entity) {
|
||||||
|
return this.modellocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getTextureResource(T entity) {
|
||||||
|
return this.texturelocation;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package ru.magistu.siegemachines.client.renderer.model;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.Machine;
|
||||||
|
import software.bernie.geckolib.core.animatable.GeoAnimatable;
|
||||||
|
import software.bernie.geckolib.model.GeoModel;
|
||||||
|
|
||||||
|
public class MachineModel<T extends Machine & GeoAnimatable> extends GeoModel<T> {
|
||||||
|
public final String name;
|
||||||
|
public final ResourceLocation animationlocation;
|
||||||
|
public final ResourceLocation modellocation;
|
||||||
|
public final ResourceLocation texturelocation;
|
||||||
|
|
||||||
|
public MachineModel(String name) {
|
||||||
|
this.name = name;
|
||||||
|
this.animationlocation = new ResourceLocation(SiegeMachines.ID, "animations/" + this.name + ".animation.json");
|
||||||
|
this.modellocation = new ResourceLocation(SiegeMachines.ID, "geo/" + this.name + ".geo.json");
|
||||||
|
this.texturelocation = new ResourceLocation(SiegeMachines.ID, "textures/entity/" + this.name + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getAnimationResource(T entity) {
|
||||||
|
return this.animationlocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getModelResource(T entity) {
|
||||||
|
return this.modellocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getTextureResource(T entity) {
|
||||||
|
return this.texturelocation;
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,13 @@
|
|||||||
package magistu.siegemachines.config;
|
package ru.magistu.siegemachines.config;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
|
||||||
public class MissileSpecs
|
public class MissileSpecs {
|
||||||
{
|
|
||||||
public final ForgeConfigSpec.ConfigValue<Float> mass;
|
public final ForgeConfigSpec.ConfigValue<Float> mass;
|
||||||
public final ForgeConfigSpec.ConfigValue<Float> explosionpower;
|
public final ForgeConfigSpec.ConfigValue<Float> explosionpower;
|
||||||
public final ForgeConfigSpec.ConfigValue<Boolean> destroysground;
|
public final ForgeConfigSpec.ConfigValue<Boolean> destroysground;
|
||||||
|
|
||||||
public MissileSpecs(ForgeConfigSpec.Builder builder, String name, float mass, float explosionpower, boolean destroysground)
|
public MissileSpecs(ForgeConfigSpec.Builder builder, String name, float mass, float explosionpower, boolean destroysground) {
|
||||||
{
|
|
||||||
builder.push(name);
|
builder.push(name);
|
||||||
|
|
||||||
this.mass = builder.define("mass", mass);
|
this.mass = builder.define("mass", mass);
|
@ -1,18 +1,17 @@
|
|||||||
package magistu.siegemachines.config;
|
package ru.magistu.siegemachines.config;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
|
||||||
public final class SiegeMachineSpecs
|
public final class SiegeMachineSpecs {
|
||||||
{
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public final ForgeConfigSpec.ConfigValue<Integer> durability;
|
public final ForgeConfigSpec.ConfigValue<Integer> durability;
|
||||||
public final ForgeConfigSpec.ConfigValue<Integer> delaytime;
|
public final ForgeConfigSpec.ConfigValue<Integer> delaytime;
|
||||||
public final ForgeConfigSpec.ConfigValue<Float> projectilespeed;
|
public final ForgeConfigSpec.ConfigValue<Float> projectilespeed;
|
||||||
public final ForgeConfigSpec.ConfigValue<Float> inaccuracy;
|
public final ForgeConfigSpec.ConfigValue<Float> inaccuracy;
|
||||||
|
public final ForgeConfigSpec.ConfigValue<Float> damagemultiplier;
|
||||||
|
|
||||||
public SiegeMachineSpecs(ForgeConfigSpec.Builder builder, String name, int durability, int delaytime, float projectilespeed, float inaccuracy)
|
public SiegeMachineSpecs(ForgeConfigSpec.Builder builder, String name, int durability, int delaytime, float projectilespeed, float inaccuracy, float damagemultiplier) {
|
||||||
{
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
builder.push(name);
|
builder.push(name);
|
||||||
@ -21,6 +20,7 @@ public final class SiegeMachineSpecs
|
|||||||
this.delaytime = builder.define("reloadTime", delaytime);
|
this.delaytime = builder.define("reloadTime", delaytime);
|
||||||
this.projectilespeed = builder.define("projectileSpeed", projectilespeed);
|
this.projectilespeed = builder.define("projectileSpeed", projectilespeed);
|
||||||
this.inaccuracy = builder.define("inaccuracy", inaccuracy);
|
this.inaccuracy = builder.define("inaccuracy", inaccuracy);
|
||||||
|
this.damagemultiplier = builder.define("damageMultiplier", damagemultiplier);
|
||||||
|
|
||||||
builder.pop();
|
builder.pop();
|
||||||
}
|
}
|
@ -1,11 +1,10 @@
|
|||||||
package magistu.siegemachines.config;
|
package ru.magistu.siegemachines.config;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
import net.minecraftforge.fml.config.ModConfig;
|
||||||
|
|
||||||
public final class SpecsConfig
|
public final class SpecsConfig {
|
||||||
{
|
|
||||||
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
|
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
|
||||||
public static final ForgeConfigSpec SPEC;
|
public static final ForgeConfigSpec SPEC;
|
||||||
|
|
||||||
@ -15,21 +14,22 @@ public final class SpecsConfig
|
|||||||
public static final SiegeMachineSpecs CATAPULT;
|
public static final SiegeMachineSpecs CATAPULT;
|
||||||
public static final SiegeMachineSpecs BALLISTA;
|
public static final SiegeMachineSpecs BALLISTA;
|
||||||
public static final SiegeMachineSpecs BATTERING_RAM;
|
public static final SiegeMachineSpecs BATTERING_RAM;
|
||||||
|
public static final SiegeMachineSpecs SIEGE_LADDER;
|
||||||
|
|
||||||
public static final MissileSpecs CANNONBALL;
|
public static final MissileSpecs CANNONBALL;
|
||||||
public static final MissileSpecs STONE;
|
public static final MissileSpecs STONE;
|
||||||
public static final MissileSpecs GIANT_STONE;
|
public static final MissileSpecs GIANT_STONE;
|
||||||
|
|
||||||
static
|
static {
|
||||||
{
|
|
||||||
BUILDER.push("siege_machines");
|
BUILDER.push("siege_machines");
|
||||||
|
|
||||||
MORTAR = new SiegeMachineSpecs(BUILDER, "mortar", 80, 200, 2.5f, 0.2f);
|
MORTAR = new SiegeMachineSpecs(BUILDER, "mortar", 80, 200, 2.5f, 0.2f, 1.5f);
|
||||||
CULVERIN = new SiegeMachineSpecs(BUILDER, "culverin", 80, 200, 3.0f, 0.2f);
|
CULVERIN = new SiegeMachineSpecs(BUILDER, "culverin", 150, 260, 3.5f, 0.03f, 3.0f);
|
||||||
TREBUCHET = new SiegeMachineSpecs(BUILDER, "trebuchet", 300, 400, 2.8f, 0.2f);
|
TREBUCHET = new SiegeMachineSpecs(BUILDER, "trebuchet", 350, 400, 2.8f, 0.2f, 2.0f);
|
||||||
CATAPULT = new SiegeMachineSpecs(BUILDER, "catapult", 100, 200, 2.0f, 0.2f);
|
CATAPULT = new SiegeMachineSpecs(BUILDER, "catapult", 150, 200, 2.0f, 0.2f, 1.0f);
|
||||||
BALLISTA = new SiegeMachineSpecs(BUILDER, "ballista", 50, 120, 4.5f, 0.04f);
|
BALLISTA = new SiegeMachineSpecs(BUILDER, "ballista", 70, 120, 4.5f, 0.04f, 1.2f);
|
||||||
BATTERING_RAM = new SiegeMachineSpecs(BUILDER, "battering_ram", 250, 100, 0.0f, 0.5f);
|
BATTERING_RAM = new SiegeMachineSpecs(BUILDER, "battering_ram", 500, 100, 0.0f, 0.5f, 0.0f);
|
||||||
|
SIEGE_LADDER = new SiegeMachineSpecs(BUILDER, "siege_ladder", 400, 0, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
BUILDER.pop();
|
BUILDER.pop();
|
||||||
|
|
||||||
@ -40,13 +40,11 @@ public final class SpecsConfig
|
|||||||
GIANT_STONE = new MissileSpecs(BUILDER, "giant_stone", 70.0f, 5.0f, false);
|
GIANT_STONE = new MissileSpecs(BUILDER, "giant_stone", 70.0f, 5.0f, false);
|
||||||
|
|
||||||
BUILDER.pop();
|
BUILDER.pop();
|
||||||
|
|
||||||
SPEC = BUILDER.build();
|
SPEC = BUILDER.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
public static void register()
|
|
||||||
{
|
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, SPEC, "siege-machines-specs.toml");
|
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, SPEC, "siege-machines-specs.toml");
|
||||||
}
|
}
|
||||||
}
|
}
|
287
src/main/java/ru/magistu/siegemachines/entity/Breakdown.java
Normal file
287
src/main/java/ru/magistu/siegemachines/entity/Breakdown.java
Normal file
@ -0,0 +1,287 @@
|
|||||||
|
package ru.magistu.siegemachines.entity;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import com.mojang.datafixers.util.Pair;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import net.minecraft.Util;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
|
import net.minecraft.world.entity.item.PrimedTnt;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.enchantment.ProtectionEnchantment;
|
||||||
|
import net.minecraft.world.level.*;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
import net.minecraft.world.level.block.FireBlock;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.material.FluidState;
|
||||||
|
import net.minecraft.world.level.storage.loot.LootParams;
|
||||||
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
|
import net.minecraft.world.phys.AABB;
|
||||||
|
import net.minecraft.world.phys.HitResult;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Breakdown {
|
||||||
|
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
|
||||||
|
private final boolean fire;
|
||||||
|
private final Explosion.BlockInteraction blockInteraction;
|
||||||
|
private final RandomSource random = RandomSource.create();
|
||||||
|
private final Level level;
|
||||||
|
private final double x;
|
||||||
|
private final double y;
|
||||||
|
private final double z;
|
||||||
|
@Nullable
|
||||||
|
private final Entity source;
|
||||||
|
private final float radius;
|
||||||
|
private final DamageSource damageSource;
|
||||||
|
private final ExplosionDamageCalculator damageCalculator;
|
||||||
|
private final ObjectArrayList<BlockPos> toBlow = new ObjectArrayList<>();
|
||||||
|
private final Map<Player, Vec3> hitPlayers = Maps.newHashMap();
|
||||||
|
private final Vec3 position;
|
||||||
|
private final Explosion explosion;
|
||||||
|
private final Entity machine;
|
||||||
|
private final float power;
|
||||||
|
|
||||||
|
public Breakdown(Level p_i50007_1_, @Nullable Entity machine, @Nullable Entity p_i50007_2_, double p_i50007_3_, double p_i50007_5_, double p_i50007_7_, float p_i50007_9_, boolean p_i50007_10_, float power, Explosion.BlockInteraction p_i50007_11_) {
|
||||||
|
this(p_i50007_1_, p_i50007_2_, machine, (DamageSource) null, (ExplosionDamageCalculator) null, p_i50007_3_, p_i50007_5_, p_i50007_7_, p_i50007_9_, p_i50007_10_, power, p_i50007_11_);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Breakdown(Level p_i231610_1_, @Nullable Entity machine, @Nullable Entity p_i231610_2_, @Nullable DamageSource p_i231610_3_, @Nullable ExplosionDamageCalculator p_i231610_4_, double p_i231610_5_, double p_i231610_7_, double p_i231610_9_, float p_i231610_11_, boolean p_i231610_12_, float power, Explosion.BlockInteraction p_i231610_13_) {
|
||||||
|
this.explosion = new Explosion(p_i231610_1_, p_i231610_2_, p_i231610_3_, p_i231610_4_, p_i231610_5_, p_i231610_7_, p_i231610_9_, p_i231610_11_, p_i231610_12_, p_i231610_13_);
|
||||||
|
this.level = p_i231610_1_;
|
||||||
|
this.machine = machine;
|
||||||
|
this.source = p_i231610_2_;
|
||||||
|
this.radius = p_i231610_11_;
|
||||||
|
this.x = p_i231610_5_;
|
||||||
|
this.y = p_i231610_7_;
|
||||||
|
this.z = p_i231610_9_;
|
||||||
|
this.fire = p_i231610_12_;
|
||||||
|
this.power = power;
|
||||||
|
this.blockInteraction = p_i231610_13_;
|
||||||
|
// this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? DamageSource.explosion((LivingEntity) p_i231610_2_) : p_i231610_3_;
|
||||||
|
this.damageSource = p_i231610_3_ == null && p_i231610_2_ instanceof LivingEntity ? level.damageSources().explosion(p_i231610_2_, p_i231610_2_) : p_i231610_3_; //TODO Возможно неправильно
|
||||||
|
this.damageCalculator = p_i231610_4_ == null ? this.makeDamageCalculator(p_i231610_2_) : p_i231610_4_;
|
||||||
|
this.position = new Vec3(this.x, this.y, this.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity p_234894_1_) {
|
||||||
|
return (p_234894_1_ == null ? EXPLOSION_DAMAGE_CALCULATOR : new EntityBasedExplosionDamageCalculator(p_234894_1_));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getSeenPercent(Vec3 p_222259_0_, Entity p_222259_1_) {
|
||||||
|
AABB axisalignedbb = p_222259_1_.getBoundingBox();
|
||||||
|
double d0 = 1.0D / ((axisalignedbb.maxX - axisalignedbb.minX) * 2.0D + 1.0D);
|
||||||
|
double d1 = 1.0D / ((axisalignedbb.maxY - axisalignedbb.minY) * 2.0D + 1.0D);
|
||||||
|
double d2 = 1.0D / ((axisalignedbb.maxZ - axisalignedbb.minZ) * 2.0D + 1.0D);
|
||||||
|
double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
|
||||||
|
double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
|
||||||
|
if (!(d0 < 0.0D) && !(d1 < 0.0D) && !(d2 < 0.0D)) {
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
|
||||||
|
for (float f = 0.0F; f <= 1.0F; f = (float) ((double) f + d0)) {
|
||||||
|
for (float f1 = 0.0F; f1 <= 1.0F; f1 = (float) ((double) f1 + d1)) {
|
||||||
|
for (float f2 = 0.0F; f2 <= 1.0F; f2 = (float) ((double) f2 + d2)) {
|
||||||
|
double d5 = Mth.lerp((double) f, axisalignedbb.minX, axisalignedbb.maxX);
|
||||||
|
double d6 = Mth.lerp((double) f1, axisalignedbb.minY, axisalignedbb.maxY);
|
||||||
|
double d7 = Mth.lerp((double) f2, axisalignedbb.minZ, axisalignedbb.maxZ);
|
||||||
|
Vec3 vector3d = new Vec3(d5 + d3, d6, d7 + d4);
|
||||||
|
if (p_222259_1_.level().clip(new ClipContext(vector3d, p_222259_0_, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, p_222259_1_)).getType() == HitResult.Type.MISS) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (float) i / (float) j;
|
||||||
|
} else {
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void explode() {
|
||||||
|
Set<BlockPos> set = Sets.newHashSet();
|
||||||
|
int i = 16;
|
||||||
|
|
||||||
|
for (int j = 0; j < 16; ++j) {
|
||||||
|
for (int k = 0; k < 16; ++k) {
|
||||||
|
for (int l = 0; l < 16; ++l) {
|
||||||
|
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
|
||||||
|
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
|
||||||
|
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
|
||||||
|
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
|
||||||
|
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
|
||||||
|
d0 = d0 / d3;
|
||||||
|
d1 = d1 / d3;
|
||||||
|
d2 = d2 / d3;
|
||||||
|
float f = this.power * this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
|
||||||
|
double d4 = this.x;
|
||||||
|
double d6 = this.y;
|
||||||
|
double d8 = this.z;
|
||||||
|
|
||||||
|
for (float f1 = 0.3F; f > 0.0F; f -= this.power * 0.5F) {
|
||||||
|
BlockPos blockpos = new BlockPos((int) d4, (int) d6, (int) d8); //TODO ранее был double
|
||||||
|
BlockState blockstate = this.level.getBlockState(blockpos);
|
||||||
|
FluidState fluidstate = this.level.getFluidState(blockpos);
|
||||||
|
Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(this.explosion, this.level, blockpos, blockstate, fluidstate);
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
f -= (optional.get() + 0.3F) * 0.3F;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(this.explosion, this.level, blockpos, blockstate, f)) {
|
||||||
|
set.add(blockpos);
|
||||||
|
}
|
||||||
|
|
||||||
|
d4 += d0 * (double) 0.3F;
|
||||||
|
d6 += d1 * (double) 0.3F;
|
||||||
|
d8 += d2 * (double) 0.3F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.toBlow.addAll(set);
|
||||||
|
float f2 = 1.5f * this.radius;
|
||||||
|
int k1 = Mth.floor(this.x - (double) f2 - 1.0D);
|
||||||
|
int l1 = Mth.floor(this.x + (double) f2 + 1.0D);
|
||||||
|
int i2 = Mth.floor(this.y - (double) f2 - 1.0D);
|
||||||
|
int i1 = Mth.floor(this.y + (double) f2 + 1.0D);
|
||||||
|
int j2 = Mth.floor(this.z - (double) f2 - 1.0D);
|
||||||
|
int j1 = Mth.floor(this.z + (double) f2 + 1.0D);
|
||||||
|
List<Entity> list = this.level.getEntities(this.source, new AABB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
|
||||||
|
Vec3 vector3d = new Vec3(this.x, this.y, this.z);
|
||||||
|
|
||||||
|
for (int k2 = 0; k2 < list.size(); ++k2) {
|
||||||
|
Entity entity = list.get(k2);
|
||||||
|
if (!entity.ignoreExplosion() && !entity.equals(this.machine) && !entity.equals(this.source)) {
|
||||||
|
double d12 = (Mth.sqrt((float) entity.distanceToSqr(vector3d)) / f2);
|
||||||
|
if (d12 <= 1.0D) {
|
||||||
|
double d5 = entity.getX() - this.x;
|
||||||
|
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - this.y;
|
||||||
|
double d9 = entity.getZ() - this.z;
|
||||||
|
double d13 = Mth.sqrt((float) (d5 * d5 + d7 * d7 + d9 * d9));
|
||||||
|
if (d13 != 0.0D) {
|
||||||
|
d5 = d5 / d13;
|
||||||
|
d7 = d7 / d13;
|
||||||
|
d9 = d9 / d13;
|
||||||
|
double d14 = getSeenPercent(vector3d, entity);
|
||||||
|
double d10 = (1.0D - d12) * d14;
|
||||||
|
if (!(entity instanceof ItemEntity)) {
|
||||||
|
entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f2 + 1.0D)));
|
||||||
|
}
|
||||||
|
double d11 = d10;
|
||||||
|
if (entity instanceof LivingEntity) {
|
||||||
|
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10);
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
|
||||||
|
if (entity instanceof Player) {
|
||||||
|
Player playerentity = (Player) entity;
|
||||||
|
if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.getAbilities().flying)) {
|
||||||
|
this.hitPlayers.put(playerentity, new Vec3(d5 * d10, d7 * d10, d9 * d10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finalizeExplosion(boolean p_77279_1_) {
|
||||||
|
boolean flag = this.blockInteraction != Explosion.BlockInteraction.KEEP; //TODO Стоял NONE, поставил KEEP, возможно неверно
|
||||||
|
if (p_77279_1_) {
|
||||||
|
if (!(this.radius < 2.0F) && flag) {
|
||||||
|
this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
|
||||||
|
} else {
|
||||||
|
this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
|
||||||
|
Util.shuffle(this.toBlow, random);
|
||||||
|
|
||||||
|
for (BlockPos blockpos : this.toBlow) {
|
||||||
|
BlockState blockstate = this.level.getBlockState(blockpos);
|
||||||
|
Block block = blockstate.getBlock();
|
||||||
|
if (!blockstate.isAir()) {
|
||||||
|
BlockPos blockpos1 = blockpos.immutable();
|
||||||
|
this.level.getProfiler().push("explosion_blocks");
|
||||||
|
if (this.level instanceof ServerLevel) {
|
||||||
|
BlockEntity tileentity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
|
||||||
|
LootParams.Builder lootcontext$builder = (new LootParams.Builder((ServerLevel) this.level)).withLuck(this.level.random.nextFloat()).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
|
||||||
|
if (this.blockInteraction == Explosion.BlockInteraction.DESTROY) {
|
||||||
|
lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, this.radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
blockstate.getDrops(lootcontext$builder).forEach((p_229977_2_) -> {
|
||||||
|
addBlockDrops(objectarraylist, p_229977_2_, blockpos1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.level.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
|
||||||
|
this.level.getProfiler().pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Pair<ItemStack, BlockPos> pair : objectarraylist) {
|
||||||
|
Block.popResource(this.level, pair.getSecond(), pair.getFirst());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.fire) {
|
||||||
|
for (BlockPos blockpos2 : this.toBlow) {
|
||||||
|
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
|
||||||
|
this.level.setBlockAndUpdate(blockpos2, FireBlock.getState(this.level, blockpos2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> p_46068_, ItemStack p_46069_, BlockPos p_46070_) {
|
||||||
|
int i = p_46068_.size();
|
||||||
|
|
||||||
|
for (int j = 0; j < i; ++j) {
|
||||||
|
Pair<ItemStack, BlockPos> pair = p_46068_.get(j);
|
||||||
|
ItemStack itemstack = pair.getFirst();
|
||||||
|
if (ItemEntity.areMergable(itemstack, p_46069_)) {
|
||||||
|
ItemStack itemstack1 = ItemEntity.merge(itemstack, p_46069_, 16);
|
||||||
|
p_46068_.set(j, Pair.of(itemstack1, pair.getSecond()));
|
||||||
|
if (p_46069_.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p_46068_.add(Pair.of(p_46069_, p_46070_));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DamageSource getDamageSource() {
|
||||||
|
return this.damageSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3 getPosition() {
|
||||||
|
return this.position;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package ru.magistu.siegemachines.entity;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
import net.minecraft.world.entity.MobCategory;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
|
import ru.magistu.siegemachines.entity.machine.*;
|
||||||
|
import ru.magistu.siegemachines.entity.projectile.Cannonball;
|
||||||
|
import ru.magistu.siegemachines.entity.projectile.GiantArrow;
|
||||||
|
import ru.magistu.siegemachines.entity.projectile.GiantStone;
|
||||||
|
import ru.magistu.siegemachines.entity.projectile.Stone;
|
||||||
|
|
||||||
|
public class EntityTypes {
|
||||||
|
public static final DeferredRegister<EntityType<?>> DEFERRED_REGISTER = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, SiegeMachines.ID);
|
||||||
|
|
||||||
|
public static final RegistryObject<EntityType<Cannonball>> CANNONBALL = addRegistry("cannonball", Cannonball::new, 0.5f, 0.5f);
|
||||||
|
public static final RegistryObject<EntityType<Stone>> STONE = addRegistry("stone", Stone::new, 0.6f, 0.6f);
|
||||||
|
public static final RegistryObject<EntityType<GiantStone>> GIANT_STONE = addRegistry("giant_stone", GiantStone::new, 1.1f, 1.1f);
|
||||||
|
public static final RegistryObject<EntityType<GiantArrow>> GIANT_ARROW = DEFERRED_REGISTER.register("giant_arrow", () -> EntityType.Builder.<GiantArrow>of(GiantArrow::new, MobCategory.MISC).clientTrackingRange(4).updateInterval(20).sized(0.5f, 0.5f).build(new ResourceLocation(SiegeMachines.ID, "giant_arrow").toString()));
|
||||||
|
|
||||||
|
public static final RegistryObject<EntityType<Mortar>> MORTAR = addRegistry("mortar", Mortar::new, 2.0f, 1.0f, 10);
|
||||||
|
public static final RegistryObject<EntityType<Culverin>> CULVERIN = addRegistry("culverin", Culverin::new, 2.5f, 1.8f, 10);
|
||||||
|
public static final RegistryObject<EntityType<Trebuchet>> TREBUCHET = addRegistry("trebuchet", Trebuchet::new, 5.0f, 9.0f, 10);
|
||||||
|
public static final RegistryObject<EntityType<Catapult>> CATAPULT = addRegistry("catapult", Catapult::new, 3.0f, 3.0f, 10);
|
||||||
|
public static final RegistryObject<EntityType<Ballista>> BALLISTA = addRegistry("ballista", Ballista::new, 1.5f, 1.5f, 10);
|
||||||
|
public static final RegistryObject<EntityType<BatteringRam>> BATTERING_RAM = addRegistry("battering_ram", BatteringRam::new, 4.0f, 3.0f, 10);
|
||||||
|
public static final RegistryObject<EntityType<SiegeLadder>> SIEGE_LADDER = addRegistry("siege_ladder", SiegeLadder::new, 3.0f, 3.0f, 10);
|
||||||
|
|
||||||
|
public static final RegistryObject<EntityType<Seat>> SEAT = addRegistry("seat", Seat::new, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey) {
|
||||||
|
return addRegistry(name, constructor, sizex, sizey, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Entity> RegistryObject<EntityType<T>> addRegistry(String name, EntityType.EntityFactory<T> constructor, float sizex, float sizey, int trackingrange) {
|
||||||
|
return DEFERRED_REGISTER.register(name, () -> EntityType.Builder.of(constructor, MobCategory.MISC).clientTrackingRange(trackingrange).sized(sizex, sizey).build(new ResourceLocation(SiegeMachines.ID, name).toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(IEventBus eventBus) {
|
||||||
|
DEFERRED_REGISTER.register(eventBus);
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,10 @@
|
|||||||
package magistu.siegemachines.entity;
|
package ru.magistu.siegemachines.entity;
|
||||||
|
|
||||||
import magistu.siegemachines.gui.Crosshair;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
import ru.magistu.siegemachines.client.gui.machine.crosshair.Crosshair;
|
||||||
|
|
||||||
public interface IReloading
|
public interface IReloading {
|
||||||
{
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
Crosshair createCrosshair();
|
Crosshair createCrosshair();
|
||||||
}
|
}
|
@ -1,27 +1,26 @@
|
|||||||
package magistu.siegemachines.entity.machine;
|
package ru.magistu.siegemachines.entity.machine;
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
import magistu.siegemachines.client.SoundTypes;
|
import ru.magistu.siegemachines.client.SoundTypes;
|
||||||
import magistu.siegemachines.gui.Crosshair;
|
import ru.magistu.siegemachines.client.gui.machine.crosshair.Crosshair;
|
||||||
import magistu.siegemachines.gui.ReloadingCrosshair;
|
import ru.magistu.siegemachines.client.gui.machine.crosshair.ReloadingCrosshair;
|
||||||
import magistu.siegemachines.item.ModItems;
|
import ru.magistu.siegemachines.item.ModItems;
|
||||||
import net.minecraft.entity.*;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.world.entity.Mob;
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import software.bernie.geckolib3.core.IAnimatable;
|
import software.bernie.geckolib3.core.IAnimatable;
|
||||||
import software.bernie.geckolib3.core.PlayState;
|
import software.bernie.geckolib3.core.PlayState;
|
||||||
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
||||||
|
import software.bernie.geckolib3.core.builder.ILoopType;
|
||||||
import software.bernie.geckolib3.core.controller.AnimationController;
|
import software.bernie.geckolib3.core.controller.AnimationController;
|
||||||
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
|
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
|
||||||
import software.bernie.geckolib3.core.manager.AnimationData;
|
import software.bernie.geckolib3.core.manager.AnimationData;
|
||||||
@ -32,8 +31,8 @@ public class Ballista extends ShootingMachine implements IAnimatable
|
|||||||
{
|
{
|
||||||
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
|
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
|
||||||
|
|
||||||
static AnimationBuilder SHOOTING_ANIM = new AnimationBuilder().addAnimation("Shooting", true);
|
static AnimationBuilder SHOOTING_ANIM = new AnimationBuilder().addAnimation("Shooting", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
static AnimationBuilder RELOADING_ANIM = new AnimationBuilder().addAnimation("Reloading", true);
|
static AnimationBuilder RELOADING_ANIM = new AnimationBuilder().addAnimation("Reloading", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
|
|
||||||
public enum State
|
public enum State
|
||||||
{
|
{
|
||||||
@ -42,27 +41,28 @@ public class Ballista extends ShootingMachine implements IAnimatable
|
|||||||
}
|
}
|
||||||
public State state = State.RELOADING;
|
public State state = State.RELOADING;
|
||||||
|
|
||||||
public Ballista(EntityType<? extends MobEntity> entitytype, World level)
|
public Ballista(EntityType<? extends Mob> entitytype, Level level)
|
||||||
{
|
{
|
||||||
super(entitytype, level, MachineType.BALLISTA);
|
super(entitytype, level, MachineType.BALLISTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event)
|
private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state) {
|
||||||
{
|
case SHOOTING -> {
|
||||||
case SHOOTING:
|
|
||||||
event.getController().setAnimation(SHOOTING_ANIM);
|
event.getController().setAnimation(SHOOTING_ANIM);
|
||||||
return PlayState.CONTINUE;
|
return PlayState.CONTINUE;
|
||||||
case RELOADING:
|
}
|
||||||
|
case RELOADING -> {
|
||||||
event.getController().setAnimation(RELOADING_ANIM);
|
event.getController().setAnimation(RELOADING_ANIM);
|
||||||
return PlayState.CONTINUE;
|
return PlayState.CONTINUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return PlayState.CONTINUE;
|
return PlayState.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerControllers(AnimationData data)
|
public void registerControllers(AnimationData data)
|
||||||
{
|
{
|
||||||
AnimationController<?> controller = new AnimationController<>(this, "controller", 1, (t) ->
|
AnimationController<?> controller = new AnimationController<>(this, "controller", 1, (t) ->
|
||||||
{
|
{
|
||||||
@ -72,8 +72,8 @@ public class Ballista extends ShootingMachine implements IAnimatable
|
|||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}, this::predicate);
|
}, this::predicate);
|
||||||
data.addAnimationController(controller);
|
data.addAnimationController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnimationFactory getFactory()
|
public AnimationFactory getFactory()
|
||||||
@ -82,22 +82,22 @@ public class Ballista extends ShootingMachine implements IAnimatable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ActionResultType mobInteract(PlayerEntity player, Hand hand)
|
protected InteractionResult mobInteract(Player player, InteractionHand hand)
|
||||||
{
|
{
|
||||||
if (super.mobInteract(player, hand) == ActionResultType.SUCCESS)
|
if (super.mobInteract(player, hand) == InteractionResult.SUCCESS)
|
||||||
{
|
{
|
||||||
return ActionResultType.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
if (!this.level.isClientSide() && !this.isVehicle())
|
if (!this.level.isClientSide() && !this.isVehicle())
|
||||||
{
|
{
|
||||||
player.startRiding(this);
|
player.startRiding(this);
|
||||||
return ActionResultType.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResultType.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startShooting(PlayerEntity player)
|
public void startShooting(Player player)
|
||||||
{
|
{
|
||||||
if (this.delayticks <= 0 && this.useticks <= 0 && this.shootingticks <= 0)
|
if (this.delayticks <= 0 && this.useticks <= 0 && this.shootingticks <= 0)
|
||||||
{
|
{
|
||||||
@ -105,8 +105,8 @@ public class Ballista extends ShootingMachine implements IAnimatable
|
|||||||
this.useticks = this.type.usetime;
|
this.useticks = this.type.usetime;
|
||||||
this.shootingticks = this.type.userealisetime;
|
this.shootingticks = this.type.userealisetime;
|
||||||
|
|
||||||
Vector3d pos = this.position();
|
Vec3 pos = this.position();
|
||||||
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.BALLISTA_SHOOTING.get(), SoundCategory.BLOCKS, 1.4f, 1.0f, false);
|
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.BALLISTA_SHOOTING.get(), this.getSoundSource(), 1.4f, 1.0f, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,22 +119,42 @@ public class Ballista extends ShootingMachine implements IAnimatable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void travel(Vec3 pos)
|
||||||
|
// {
|
||||||
|
// if (this.isAlive())
|
||||||
|
// {
|
||||||
|
// if (this.isVehicle())
|
||||||
|
// {
|
||||||
|
// LivingEntity livingentity = (LivingEntity) this.getControllingPassenger();
|
||||||
|
//
|
||||||
|
// this.setTurretRotationsDest(livingentity.getXRot(), livingentity.getYRot() - this.getYaw());
|
||||||
|
// this.updateTurretRotations();
|
||||||
|
// }
|
||||||
|
// super.travel(pos);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void travel(Vector3d pos)
|
public void travel(Vec3 pos)
|
||||||
{
|
{
|
||||||
if (this.isAlive())
|
if (this.isAlive())
|
||||||
{
|
{
|
||||||
if (this.isVehicle())
|
if (this.isVehicle() && this.useticks <= 0 && this.delayticks <= 0)
|
||||||
{
|
{
|
||||||
LivingEntity livingentity = (LivingEntity) this.getControllingPassenger();
|
LivingEntity livingentity = (LivingEntity) this.getControllingPassenger();
|
||||||
|
|
||||||
this.setTurretRotationsDest(livingentity.xRot, livingentity.yRot - this.getYaw());
|
this.setTurretRotations(livingentity.getXRot(), this.getTurretYaw());
|
||||||
this.updateTurretRotations();
|
this.updateTurretRotations();
|
||||||
}
|
|
||||||
super.travel(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
this.setYawDest(livingentity.getYRot());
|
||||||
|
this.updateYaw();
|
||||||
|
|
||||||
|
}
|
||||||
|
super.travel(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void tick()
|
||||||
@ -152,7 +172,7 @@ public class Ballista extends ShootingMachine implements IAnimatable
|
|||||||
this.shootingticks = 0;
|
this.shootingticks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!level.isClientSide() && (this.isOnGround() || this.isInWater()))
|
if (!level.isClientSide() && this.isOnGround())
|
||||||
{
|
{
|
||||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.0, 1.0, 0.0));
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.0, 1.0, 0.0));
|
||||||
}
|
}
|
||||||
@ -161,8 +181,8 @@ public class Ballista extends ShootingMachine implements IAnimatable
|
|||||||
{
|
{
|
||||||
if (this.delayticks % 21 == 0)
|
if (this.delayticks % 21 == 0)
|
||||||
{
|
{
|
||||||
Vector3d pos = this.position();
|
Vec3 pos = this.position();
|
||||||
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.BALLISTA_RELOADING.get(), SoundCategory.BLOCKS, 1.0f, 1.0f, false);
|
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.BALLISTA_RELOADING.get(), this.getSoundSource(), 1.0f, 1.0f, false);
|
||||||
}
|
}
|
||||||
--this.delayticks;
|
--this.delayticks;
|
||||||
}
|
}
|
@ -1,27 +1,33 @@
|
|||||||
package magistu.siegemachines.entity.machine;
|
package ru.magistu.siegemachines.entity.machine;
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
import net.minecraft.ChatFormatting;
|
||||||
import magistu.siegemachines.client.SoundTypes;
|
import net.minecraft.client.Minecraft;
|
||||||
import magistu.siegemachines.entity.Breakdown;
|
import net.minecraft.network.chat.Component;
|
||||||
import magistu.siegemachines.item.ModItems;
|
import net.minecraft.world.entity.Entity;
|
||||||
import magistu.siegemachines.network.PacketHandler;
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
import magistu.siegemachines.network.PacketMachineUse;
|
import ru.magistu.siegemachines.client.SoundTypes;
|
||||||
import magistu.siegemachines.network.PacketMachineUseRealise;
|
import ru.magistu.siegemachines.entity.Breakdown;
|
||||||
import net.minecraft.entity.EntityType;
|
import ru.magistu.siegemachines.item.ModItems;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import ru.magistu.siegemachines.network.PacketHandler;
|
||||||
import net.minecraft.entity.MobEntity;
|
import ru.magistu.siegemachines.network.PacketMachineUse;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import ru.magistu.siegemachines.network.PacketMachineUseRealise;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.Explosion;
|
import net.minecraft.world.entity.Mob;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.level.Explosion;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import ru.magistu.siegemachines.util.CartesianGeometry;
|
||||||
import software.bernie.geckolib3.core.IAnimatable;
|
import software.bernie.geckolib3.core.IAnimatable;
|
||||||
import software.bernie.geckolib3.core.PlayState;
|
import software.bernie.geckolib3.core.PlayState;
|
||||||
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
||||||
|
import software.bernie.geckolib3.core.builder.ILoopType;
|
||||||
import software.bernie.geckolib3.core.controller.AnimationController;
|
import software.bernie.geckolib3.core.controller.AnimationController;
|
||||||
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
|
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
|
||||||
import software.bernie.geckolib3.core.manager.AnimationData;
|
import software.bernie.geckolib3.core.manager.AnimationData;
|
||||||
@ -33,9 +39,9 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
{
|
{
|
||||||
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
|
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
|
||||||
|
|
||||||
static AnimationBuilder MOVING_ANIM = new AnimationBuilder().addAnimation("Moving", true);
|
static AnimationBuilder MOVING_ANIM = new AnimationBuilder().addAnimation("Moving", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
static AnimationBuilder HITTING_ANIM = new AnimationBuilder().addAnimation("Hitting", true);
|
static AnimationBuilder HITTING_ANIM = new AnimationBuilder().addAnimation("Hitting", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
static AnimationBuilder RELOADING_ANIM = new AnimationBuilder().addAnimation("Reloading", true);
|
static AnimationBuilder RELOADING_ANIM = new AnimationBuilder().addAnimation("Reloading", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
|
|
||||||
public int hittingticks = 0;
|
public int hittingticks = 0;
|
||||||
private int wheelssoundticks = 10;
|
private int wheelssoundticks = 10;
|
||||||
@ -50,7 +56,7 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
private double wheelspitch = 0.0;
|
private double wheelspitch = 0.0;
|
||||||
private double wheelsspeed = 0.0;
|
private double wheelsspeed = 0.0;
|
||||||
|
|
||||||
public BatteringRam(EntityType<? extends MobEntity> entitytype, World level)
|
public BatteringRam(EntityType<? extends Mob> entitytype, Level level)
|
||||||
{
|
{
|
||||||
super(entitytype, level, MachineType.BATTERING_RAM);
|
super(entitytype, level, MachineType.BATTERING_RAM);
|
||||||
}
|
}
|
||||||
@ -104,19 +110,19 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ActionResultType mobInteract(PlayerEntity player, Hand hand)
|
protected InteractionResult mobInteract(Player player, InteractionHand hand)
|
||||||
{
|
{
|
||||||
if (!this.level.isClientSide() && !this.isVehicle())
|
if (!this.level.isClientSide() && !this.isVehicle())
|
||||||
{
|
{
|
||||||
player.startRiding(this);
|
player.startRiding(this);
|
||||||
return ActionResultType.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResultType.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void travel(Vector3d pos)
|
public void travel(Vec3 pos)
|
||||||
{
|
{
|
||||||
if (this.isAlive())
|
if (this.isAlive())
|
||||||
{
|
{
|
||||||
@ -124,7 +130,7 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
{
|
{
|
||||||
LivingEntity livingentity = (LivingEntity) this.getControllingPassenger();
|
LivingEntity livingentity = (LivingEntity) this.getControllingPassenger();
|
||||||
|
|
||||||
this.setYawDest(livingentity.yRot);
|
this.setYawDest(livingentity.getYRot());
|
||||||
|
|
||||||
this.updateYaw();
|
this.updateYaw();
|
||||||
|
|
||||||
@ -135,7 +141,7 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
}
|
}
|
||||||
this.setSpeed(0.04f);
|
this.setSpeed(0.04f);
|
||||||
|
|
||||||
pos = new Vector3d(0.0f, pos.y, f1);
|
pos = new Vec3(0.0f, pos.y, f1);
|
||||||
}
|
}
|
||||||
super.travel(pos);
|
super.travel(pos);
|
||||||
}
|
}
|
||||||
@ -157,7 +163,7 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
this.hittingticks = 0;
|
this.hittingticks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!level.isClientSide() && (this.isOnGround() || this.isInWater()))
|
if (!level.isClientSide() && this.isOnGround())
|
||||||
{
|
{
|
||||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.0, 1.0, 0.0));
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.0, 1.0, 0.0));
|
||||||
}
|
}
|
||||||
@ -172,23 +178,32 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
this.updateMachineRender();
|
this.updateMachineRender();
|
||||||
this.renderupdateticks = SiegeMachines.RENDER_UPDATE_TIME;
|
this.renderupdateticks = SiegeMachines.RENDER_UPDATE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (this.getWheelsSpeed() > 0.0081 && this.wheelssoundticks-- <= 0)
|
if (this.level.isClientSide() && this.hasControllingPassenger() && this.getWheelsSpeed() > 0.0081 && this.wheelssoundticks-- <= 0)
|
||||||
// {
|
{
|
||||||
// this.level.playLocalSound(this.getX(), this.getY(), this.getZ(), SoundTypes.RAM_WHEELS.get(), SoundCategory.NEUTRAL, 0.6f, 1.0f, true);
|
Entity passenger = this.getControllingPassenger();
|
||||||
// this.wheelssoundticks = 20;
|
if (Minecraft.getInstance().player == passenger)
|
||||||
// }
|
{
|
||||||
|
Vec3 pos = this.position();
|
||||||
|
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.RAM_WHEELS.get(), this.getSoundSource(), 1.5f, 0.85f + this.level.random.nextFloat() * 0.3f, false);
|
||||||
|
this.wheelssoundticks = 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.tick();
|
super.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void use(PlayerEntity player)
|
public void use(Player player)
|
||||||
{
|
{
|
||||||
if (!this.level.isClientSide())
|
if (this.deploymentticks > 0)
|
||||||
{
|
{
|
||||||
PacketHandler.sendPacketToAllInArea(new PacketMachineUse(this.getId()), this.blockPosition(), SiegeMachines.RENDER_UPDATE_RANGE_SQR);
|
player.sendSystemMessage(Component.translatable(SiegeMachines.ID + ".wait", this.deploymentticks / 20.0f).withStyle(ChatFormatting.RED));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.level.isClientSide())
|
||||||
|
PacketHandler.sendPacketToAllInArea(new PacketMachineUse(this.getId()), this.blockPosition(), SiegeMachines.RENDER_UPDATE_RANGE_SQR);
|
||||||
|
|
||||||
if (this.delayticks <= 0 && this.useticks <= 0 && this.hittingticks <= 0)
|
if (this.delayticks <= 0 && this.useticks <= 0 && this.hittingticks <= 0)
|
||||||
{
|
{
|
||||||
@ -196,8 +211,8 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
this.useticks = this.type.usetime;
|
this.useticks = this.type.usetime;
|
||||||
this.hittingticks = this.type.userealisetime;
|
this.hittingticks = this.type.userealisetime;
|
||||||
|
|
||||||
Vector3d pos = this.position();
|
Vec3 pos = this.position();
|
||||||
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.RAM_HITTING.get(), SoundCategory.BLOCKS, 0.5f, 0.9f, false);
|
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.RAM_HITTING.get(), this.getSoundSource(), 0.5f, 0.9f, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +220,7 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
{
|
{
|
||||||
if (!this.level.isClientSide())
|
if (!this.level.isClientSide())
|
||||||
{
|
{
|
||||||
Breakdown breakdown = new Breakdown(this.level, this, this.getControllingPassenger(), blockpos.getX(), blockpos.getY(), blockpos.getZ(), 2, false, 3.0f, Explosion.Mode.BREAK);
|
Breakdown breakdown = new Breakdown(this.level, this, this.getControllingPassenger(), blockpos.getX(), blockpos.getY(), blockpos.getZ(), 2, false, 3.0f, Explosion.BlockInteraction.BREAK);
|
||||||
breakdown.explode();
|
breakdown.explode();
|
||||||
breakdown.finalizeExplosion(true);
|
breakdown.finalizeExplosion(true);
|
||||||
}
|
}
|
||||||
@ -214,6 +229,9 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
@Override
|
@Override
|
||||||
public void useRealise()
|
public void useRealise()
|
||||||
{
|
{
|
||||||
|
if (this.deploymentticks > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!this.level.isClientSide())
|
if (!this.level.isClientSide())
|
||||||
{
|
{
|
||||||
PacketHandler.sendPacketToAllInArea(new PacketMachineUseRealise(this.getId()), this.blockPosition(), SiegeMachines.RENDER_UPDATE_RANGE_SQR);
|
PacketHandler.sendPacketToAllInArea(new PacketMachineUseRealise(this.getId()), this.blockPosition(), SiegeMachines.RENDER_UPDATE_RANGE_SQR);
|
||||||
@ -245,11 +263,11 @@ public class BatteringRam extends Machine implements IAnimatable
|
|||||||
return ModItems.BATTERING_RAM.get();
|
return ModItems.BATTERING_RAM.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Vector3d getHitPos()
|
protected Vec3 getHitPos()
|
||||||
{
|
{
|
||||||
double pitch = this.getTurretPitch() * Math.PI / 180.0;
|
double pitch = this.getTurretPitch() * Math.PI / 180.0;
|
||||||
double yaw = (this.getViewYRot(0.5f) + this.getTurretYaw()) * Math.PI / 180.0;
|
double yaw = (this.getViewYRot(0.5f) + this.getTurretYaw()) * Math.PI / 180.0;
|
||||||
|
|
||||||
return this.position().add(applyRotations(this.type.turretpivot, 0.0, yaw).add(applyRotations(this.type.turretvector, pitch, yaw)));
|
return this.position().add(CartesianGeometry.applyRotations(this.type.turretpivot, 0.0, yaw).add(CartesianGeometry.applyRotations(this.type.turretvector, pitch, yaw)));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,26 +1,27 @@
|
|||||||
package magistu.siegemachines.entity.machine;
|
package ru.magistu.siegemachines.entity.machine;
|
||||||
|
|
||||||
import magistu.siegemachines.SiegeMachines;
|
import ru.magistu.siegemachines.SiegeMachines;
|
||||||
import magistu.siegemachines.client.SoundTypes;
|
import ru.magistu.siegemachines.client.SoundTypes;
|
||||||
import magistu.siegemachines.gui.Crosshair;
|
import ru.magistu.siegemachines.client.gui.machine.crosshair.Crosshair;
|
||||||
import magistu.siegemachines.gui.ReloadingCrosshair;
|
import ru.magistu.siegemachines.client.gui.machine.crosshair.ReloadingCrosshair;
|
||||||
import magistu.siegemachines.item.ModItems;
|
import ru.magistu.siegemachines.item.ModItems;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.entity.MobEntity;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.world.entity.Mob;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import software.bernie.geckolib3.core.IAnimatable;
|
import software.bernie.geckolib3.core.IAnimatable;
|
||||||
import software.bernie.geckolib3.core.PlayState;
|
import software.bernie.geckolib3.core.PlayState;
|
||||||
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
||||||
|
import software.bernie.geckolib3.core.builder.ILoopType;
|
||||||
import software.bernie.geckolib3.core.controller.AnimationController;
|
import software.bernie.geckolib3.core.controller.AnimationController;
|
||||||
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
|
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
|
||||||
import software.bernie.geckolib3.core.manager.AnimationData;
|
import software.bernie.geckolib3.core.manager.AnimationData;
|
||||||
@ -31,10 +32,10 @@ public class Catapult extends ShootingMachine implements IAnimatable
|
|||||||
{
|
{
|
||||||
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
|
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
|
||||||
|
|
||||||
static AnimationBuilder SHOOTING_ANIM = new AnimationBuilder().addAnimation("Shooting", true);
|
static AnimationBuilder SHOOTING_ANIM = new AnimationBuilder().addAnimation("Shooting", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
static AnimationBuilder RELOADING_ANIM = new AnimationBuilder().addAnimation("Reloading", true);
|
static AnimationBuilder RELOADING_ANIM = new AnimationBuilder().addAnimation("Reloading", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
static AnimationBuilder IDLE_RELOADED_ANIM = new AnimationBuilder().addAnimation("IdleReloaded", true);
|
static AnimationBuilder IDLE_RELOADED_ANIM = new AnimationBuilder().addAnimation("IdleReloaded", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
static AnimationBuilder IDLE_NOT_RELOADED_ANIM = new AnimationBuilder().addAnimation("IdleNotReloaded", true);
|
static AnimationBuilder IDLE_NOT_RELOADED_ANIM = new AnimationBuilder().addAnimation("IdleNotReloaded", ILoopType.EDefaultLoopTypes.LOOP);
|
||||||
|
|
||||||
public enum State
|
public enum State
|
||||||
{
|
{
|
||||||
@ -45,34 +46,37 @@ public class Catapult extends ShootingMachine implements IAnimatable
|
|||||||
}
|
}
|
||||||
public State state = State.RELOADING;
|
public State state = State.RELOADING;
|
||||||
|
|
||||||
public Catapult(EntityType<? extends MobEntity> entitytype, World level)
|
public Catapult(EntityType<? extends Mob> entitytype, Level level)
|
||||||
{
|
{
|
||||||
super(entitytype, level, MachineType.CATAPULT);
|
super(entitytype, level, MachineType.CATAPULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event)
|
private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state) {
|
||||||
{
|
case SHOOTING -> {
|
||||||
case SHOOTING:
|
|
||||||
event.getController().setAnimation(SHOOTING_ANIM);
|
event.getController().setAnimation(SHOOTING_ANIM);
|
||||||
return PlayState.CONTINUE;
|
return PlayState.CONTINUE;
|
||||||
case IDLE_RELOADED:
|
}
|
||||||
|
case IDLE_RELOADED -> {
|
||||||
event.getController().setAnimation(IDLE_RELOADED_ANIM);
|
event.getController().setAnimation(IDLE_RELOADED_ANIM);
|
||||||
return PlayState.CONTINUE;
|
return PlayState.CONTINUE;
|
||||||
case RELOADING:
|
}
|
||||||
|
case RELOADING -> {
|
||||||
event.getController().setAnimation(RELOADING_ANIM);
|
event.getController().setAnimation(RELOADING_ANIM);
|
||||||
return PlayState.CONTINUE;
|
return PlayState.CONTINUE;
|
||||||
case IDLE_NOT_RELOADED:
|
}
|
||||||
|
case IDLE_NOT_RELOADED -> {
|
||||||
event.getController().setAnimation(IDLE_NOT_RELOADED_ANIM);
|
event.getController().setAnimation(IDLE_NOT_RELOADED_ANIM);
|
||||||
return PlayState.CONTINUE;
|
return PlayState.CONTINUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PlayState.CONTINUE;
|
return PlayState.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerControllers(AnimationData data)
|
public void registerControllers(AnimationData data)
|
||||||
{
|
{
|
||||||
AnimationController<?> controller = new AnimationController<>(this, "controller", 1, (t) ->
|
AnimationController<?> controller = new AnimationController<>(this, "controller", 1, (t) ->
|
||||||
{
|
{
|
||||||
@ -82,8 +86,8 @@ public class Catapult extends ShootingMachine implements IAnimatable
|
|||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}, this::predicate);
|
}, this::predicate);
|
||||||
data.addAnimationController(controller);
|
data.addAnimationController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnimationFactory getFactory()
|
public AnimationFactory getFactory()
|
||||||
@ -92,24 +96,24 @@ public class Catapult extends ShootingMachine implements IAnimatable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ActionResultType mobInteract(PlayerEntity player, Hand hand)
|
protected InteractionResult mobInteract(Player player, InteractionHand hand)
|
||||||
{
|
{
|
||||||
ItemStack stack = player.getItemInHand(hand);
|
ItemStack stack = player.getItemInHand(hand);
|
||||||
|
|
||||||
if (super.mobInteract(player, hand) == ActionResultType.SUCCESS)
|
if (super.mobInteract(player, hand) == InteractionResult.SUCCESS)
|
||||||
{
|
{
|
||||||
return ActionResultType.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
if (!this.level.isClientSide() && !this.isVehicle())
|
if (!this.level.isClientSide() && !this.isVehicle())
|
||||||
{
|
{
|
||||||
player.startRiding(this);
|
player.startRiding(this);
|
||||||
return ActionResultType.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResultType.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startShooting(PlayerEntity player)
|
public void startShooting(Player player)
|
||||||
{
|
{
|
||||||
if (this.delayticks <= 0 && this.useticks <= 0 && this.shootingticks <= 0)
|
if (this.delayticks <= 0 && this.useticks <= 0 && this.shootingticks <= 0)
|
||||||
{
|
{
|
||||||
@ -117,8 +121,8 @@ public class Catapult extends ShootingMachine implements IAnimatable
|
|||||||
this.useticks = this.type.usetime;
|
this.useticks = this.type.usetime;
|
||||||
this.shootingticks = this.type.userealisetime;
|
this.shootingticks = this.type.userealisetime;
|
||||||
|
|
||||||
Vector3d pos = this.position();
|
Vec3 pos = this.position();
|
||||||
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.CATAPULT_SHOOTING.get(), SoundCategory.BLOCKS, 1.5f, 1.0f, false);
|
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.CATAPULT_SHOOTING.get(), this.getSoundSource(), 1.5f, 1.0f, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,23 +136,23 @@ public class Catapult extends ShootingMachine implements IAnimatable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void travel(Vector3d pos)
|
public void travel(Vec3 pos)
|
||||||
{
|
{
|
||||||
if (this.isAlive())
|
if (this.isAlive())
|
||||||
{
|
{
|
||||||
if (this.isVehicle() && this.useticks <= 0 && this.delayticks <= 0)
|
if (this.isVehicle() && this.useticks <= 0 && this.delayticks <= 0)
|
||||||
{
|
{
|
||||||
LivingEntity livingentity = (LivingEntity) this.getControllingPassenger();
|
LivingEntity livingentity = (LivingEntity) this.getControllingPassenger();
|
||||||
|
|
||||||
this.setTurretRotations(livingentity.xRot, this.getTurretYaw());
|
this.setTurretRotations(livingentity.getXRot(), this.getTurretYaw());
|
||||||
this.updateTurretRotations();
|
this.updateTurretRotations();
|
||||||
|
|
||||||
this.setYawDest(livingentity.yRot);
|
this.setYawDest(livingentity.getYRot());
|
||||||
this.updateYaw();
|
this.updateYaw();
|
||||||
}
|
}
|
||||||
super.travel(pos);
|
super.travel(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void tick()
|
||||||
@ -166,7 +170,7 @@ public class Catapult extends ShootingMachine implements IAnimatable
|
|||||||
this.shootingticks = 0;
|
this.shootingticks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!level.isClientSide() && (this.isOnGround() || this.isInWater()))
|
if (!level.isClientSide() && this.isOnGround())
|
||||||
{
|
{
|
||||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.0, 1.0, 0.0));
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.0, 1.0, 0.0));
|
||||||
}
|
}
|
||||||
@ -175,8 +179,8 @@ public class Catapult extends ShootingMachine implements IAnimatable
|
|||||||
{
|
{
|
||||||
if (this.delayticks % 20 == 0)
|
if (this.delayticks % 20 == 0)
|
||||||
{
|
{
|
||||||
Vector3d pos = this.position();
|
Vec3 pos = this.position();
|
||||||
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.CATAPULT_RELOADING.get(), SoundCategory.BLOCKS, 1.0f, 1.0f, false);
|
this.level.playLocalSound(pos.x, pos.y, pos.z, SoundTypes.CATAPULT_RELOADING.get(), this.getSoundSource(), 1.0f, 1.0f, false);
|
||||||
}
|
}
|
||||||
if (--this.delayticks <= 0)
|
if (--this.delayticks <= 0)
|
||||||
{
|
{
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user