Transfer from local Git
This commit is contained in:
commit
8c15e4011d
20 changed files with 723 additions and 0 deletions
11
.editorconfig
Normal file
11
.editorconfig
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
.gradle
|
||||||
|
.settings
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
gradle
|
||||||
|
gradlew
|
||||||
|
gradlew*
|
||||||
|
bin
|
||||||
|
run
|
||||||
|
build
|
121
LICENSE
Normal file
121
LICENSE
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
Creative Commons Legal Code
|
||||||
|
|
||||||
|
CC0 1.0 Universal
|
||||||
|
|
||||||
|
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||||
|
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||||
|
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||||
|
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||||
|
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||||
|
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||||
|
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||||
|
HEREUNDER.
|
||||||
|
|
||||||
|
Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer
|
||||||
|
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||||
|
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||||
|
authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for
|
||||||
|
the purpose of contributing to a commons of creative, cultural and
|
||||||
|
scientific works ("Commons") that the public can reliably and without fear
|
||||||
|
of later claims of infringement build upon, modify, incorporate in other
|
||||||
|
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||||
|
and for any purposes, including without limitation commercial purposes.
|
||||||
|
These owners may contribute to the Commons to promote the ideal of a free
|
||||||
|
culture and the further production of creative, cultural and scientific
|
||||||
|
works, or to gain reputation or greater distribution for their Work in
|
||||||
|
part through the use and efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any
|
||||||
|
expectation of additional consideration or compensation, the person
|
||||||
|
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||||
|
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||||
|
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||||
|
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||||
|
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||||
|
|
||||||
|
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||||
|
protected by copyright and related or neighboring rights ("Copyright and
|
||||||
|
Related Rights"). Copyright and Related Rights include, but are not
|
||||||
|
limited to, the following:
|
||||||
|
|
||||||
|
i. the right to reproduce, adapt, distribute, perform, display,
|
||||||
|
communicate, and translate a Work;
|
||||||
|
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||||
|
iii. publicity and privacy rights pertaining to a person's image or
|
||||||
|
likeness depicted in a Work;
|
||||||
|
iv. rights protecting against unfair competition in regards to a Work,
|
||||||
|
subject to the limitations in paragraph 4(a), below;
|
||||||
|
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||||
|
in a Work;
|
||||||
|
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||||
|
European Parliament and of the Council of 11 March 1996 on the legal
|
||||||
|
protection of databases, and under any national implementation
|
||||||
|
thereof, including any amended or successor version of such
|
||||||
|
directive); and
|
||||||
|
vii. other similar, equivalent or corresponding rights throughout the
|
||||||
|
world based on applicable law or treaty, and any national
|
||||||
|
implementations thereof.
|
||||||
|
|
||||||
|
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||||
|
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||||
|
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||||
|
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||||
|
of action, whether now known or unknown (including existing as well as
|
||||||
|
future claims and causes of action), in the Work (i) in all territories
|
||||||
|
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||||
|
treaty (including future time extensions), (iii) in any current or future
|
||||||
|
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||||
|
including without limitation commercial, advertising or promotional
|
||||||
|
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||||
|
member of the public at large and to the detriment of Affirmer's heirs and
|
||||||
|
successors, fully intending that such Waiver shall not be subject to
|
||||||
|
revocation, rescission, cancellation, termination, or any other legal or
|
||||||
|
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||||
|
as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||||
|
be judged legally invalid or ineffective under applicable law, then the
|
||||||
|
Waiver shall be preserved to the maximum extent permitted taking into
|
||||||
|
account Affirmer's express Statement of Purpose. In addition, to the
|
||||||
|
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||||
|
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||||
|
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||||
|
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||||
|
maximum duration provided by applicable law or treaty (including future
|
||||||
|
time extensions), (iii) in any current or future medium and for any number
|
||||||
|
of copies, and (iv) for any purpose whatsoever, including without
|
||||||
|
limitation commercial, advertising or promotional purposes (the
|
||||||
|
"License"). The License shall be deemed effective as of the date CC0 was
|
||||||
|
applied by Affirmer to the Work. Should any part of the License for any
|
||||||
|
reason be judged legally invalid or ineffective under applicable law, such
|
||||||
|
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||||
|
of the License, and in such case Affirmer hereby affirms that he or she
|
||||||
|
will not (i) exercise any of his or her remaining Copyright and Related
|
||||||
|
Rights in the Work or (ii) assert any associated claims and causes of
|
||||||
|
action with respect to the Work, in either case contrary to Affirmer's
|
||||||
|
express Statement of Purpose.
|
||||||
|
|
||||||
|
4. Limitations and Disclaimers.
|
||||||
|
|
||||||
|
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||||
|
surrendered, licensed or otherwise affected by this document.
|
||||||
|
b. Affirmer offers the Work as-is and makes no representations or
|
||||||
|
warranties of any kind concerning the Work, express, implied,
|
||||||
|
statutory or otherwise, including without limitation warranties of
|
||||||
|
title, merchantability, fitness for a particular purpose, non
|
||||||
|
infringement, or the absence of latent or other defects, accuracy, or
|
||||||
|
the present or absence of errors, whether or not discoverable, all to
|
||||||
|
the greatest extent permissible under applicable law.
|
||||||
|
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||||
|
that may apply to the Work or any use thereof, including without
|
||||||
|
limitation any person's Copyright and Related Rights in the Work.
|
||||||
|
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||||
|
consents, permissions or other rights required for any use of the
|
||||||
|
Work.
|
||||||
|
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||||
|
party to this document and has no duty or obligation with respect to
|
||||||
|
this CC0 or use of the Work.
|
9
README.md
Normal file
9
README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Fabric Example Mod
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects.
|
77
build.gradle
Normal file
77
build.gradle
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
plugins {
|
||||||
|
id 'fabric-loom' version '1.1-SNAPSHOT'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
|
archivesBaseName = project.archives_base_name
|
||||||
|
version = project.mod_version
|
||||||
|
group = project.maven_group
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
// Add repositories to retrieve artifacts from in here.
|
||||||
|
// You should only use this when depending on other mods because
|
||||||
|
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||||
|
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||||
|
// for more information about repositories.
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// To change the versions see the gradle.properties file
|
||||||
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
|
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||||
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
|
||||||
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
|
// Uncomment the following line to enable the deprecated Fabric API modules.
|
||||||
|
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
|
||||||
|
|
||||||
|
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
inputs.property "version", project.version
|
||||||
|
|
||||||
|
filesMatching("fabric.mod.json") {
|
||||||
|
expand "version": project.version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
|
||||||
|
it.options.release = 17
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||||
|
// if it is present.
|
||||||
|
// If you remove this line, sources will not be generated.
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from("LICENSE") {
|
||||||
|
rename { "${it}_${project.archivesBaseName}"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure the maven publication
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
mavenJava(MavenPublication) {
|
||||||
|
from components.java
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
||||||
|
repositories {
|
||||||
|
// Add repositories to publish to here.
|
||||||
|
// Notice: This block does NOT have the same function as the block in the top level.
|
||||||
|
// The repositories here will be used for publishing your artifact, not for
|
||||||
|
// retrieving dependencies.
|
||||||
|
}
|
||||||
|
}
|
17
gradle.properties
Normal file
17
gradle.properties
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Done to increase the memory available to gradle.
|
||||||
|
org.gradle.jvmargs=-Xmx1G
|
||||||
|
org.gradle.parallel=true
|
||||||
|
|
||||||
|
# Fabric Properties
|
||||||
|
# check these on https://fabricmc.net/develop
|
||||||
|
minecraft_version=1.19.3
|
||||||
|
yarn_mappings=1.19.3+build.5
|
||||||
|
loader_version=0.14.14
|
||||||
|
|
||||||
|
# Mod Properties
|
||||||
|
mod_version = 1.0.0
|
||||||
|
maven_group = com.example
|
||||||
|
archives_base_name = fabric-example-mod
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
fabric_version=0.74.0+1.19.3
|
10
settings.gradle
Normal file
10
settings.gradle
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = 'Fabric'
|
||||||
|
url = 'https://maven.fabricmc.net/'
|
||||||
|
}
|
||||||
|
mavenCentral()
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
9
src/main/java/me/pog5/leashmod/LeashImpl.java
Normal file
9
src/main/java/me/pog5/leashmod/LeashImpl.java
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package me.pog5.leashmod;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
|
||||||
|
public interface LeashImpl {
|
||||||
|
ActionResult leashplayers$interact(PlayerEntity player, Hand hand);
|
||||||
|
}
|
44
src/main/java/me/pog5/leashmod/LeashPlayers.java
Normal file
44
src/main/java/me/pog5/leashmod/LeashPlayers.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package me.pog5.leashmod;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
|
||||||
|
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
|
||||||
|
import net.fabricmc.fabric.api.gamerule.v1.rule.DoubleRule;
|
||||||
|
import net.minecraft.world.GameRules;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public final class LeashPlayers implements ModInitializer {
|
||||||
|
private static GameRules.Key<GameRules.BooleanRule> ruleEnabled;
|
||||||
|
private static GameRules.Key<DoubleRule> ruleDistanceMin;
|
||||||
|
private static GameRules.Key<DoubleRule> ruleDistanceMax;
|
||||||
|
|
||||||
|
public static LeashSettings getSettings(World world) {
|
||||||
|
return new LeashSettings() {
|
||||||
|
private GameRules getGameRules() {
|
||||||
|
return world.getGameRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return getGameRules().getBoolean(ruleEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDistanceMin() {
|
||||||
|
return getGameRules().get(ruleDistanceMin).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDistanceMax() {
|
||||||
|
return getGameRules().get(ruleDistanceMax).get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
ruleEnabled = GameRuleRegistry.register("leashPlayersEnabled", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true));
|
||||||
|
ruleDistanceMin = GameRuleRegistry.register("leashPlayersDistanceMin", GameRules.Category.PLAYER, GameRuleFactory.createDoubleRule(4.0D));
|
||||||
|
ruleDistanceMax = GameRuleRegistry.register("leashPlayersDistanceMax", GameRules.Category.PLAYER, GameRuleFactory.createDoubleRule(10.0D));
|
||||||
|
}
|
||||||
|
}
|
116
src/main/java/me/pog5/leashmod/LeashProxyEntity.java
Normal file
116
src/main/java/me/pog5/leashmod/LeashProxyEntity.java
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
package me.pog5.leashmod;
|
||||||
|
|
||||||
|
import net.minecraft.entity.*;
|
||||||
|
import net.minecraft.entity.passive.TurtleEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.scoreboard.AbstractTeam;
|
||||||
|
import net.minecraft.scoreboard.ServerScoreboard;
|
||||||
|
import net.minecraft.scoreboard.Team;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public final class LeashProxyEntity extends TurtleEntity {
|
||||||
|
private final LivingEntity target;
|
||||||
|
|
||||||
|
private boolean proxyUpdate() {
|
||||||
|
if (proxyIsRemoved()) return false;
|
||||||
|
|
||||||
|
if (target == null) return true;
|
||||||
|
if (target.world != world || !target.isAlive()) return true;
|
||||||
|
|
||||||
|
Vec3d posActual = getPos();
|
||||||
|
Vec3d posTarget = target.getPos().add(0.0D, 1.3D, -0.15D);
|
||||||
|
|
||||||
|
if (!Objects.equals(posActual, posTarget)) {
|
||||||
|
setRotation(0.0F, 0.0F);
|
||||||
|
setPos(posTarget.getX(), posTarget.getY(), posTarget.getZ());
|
||||||
|
setBoundingBox(getDimensions(EntityPose.DYING).getBoxAt(posTarget));
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLeash();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (world.isClient) return;
|
||||||
|
if (proxyUpdate() && !proxyIsRemoved()) {
|
||||||
|
proxyRemove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean proxyIsRemoved() {
|
||||||
|
return this.isRemoved();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void proxyRemove() {
|
||||||
|
super.remove(RemovalReason.DISCARDED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(RemovalReason reason) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String TEAM_NAME = "leashplayersimpl";
|
||||||
|
|
||||||
|
public LeashProxyEntity(LivingEntity target) {
|
||||||
|
super(EntityType.TURTLE, target.world);
|
||||||
|
|
||||||
|
this.target = target;
|
||||||
|
|
||||||
|
setHealth(1.0F);
|
||||||
|
setInvulnerable(true);
|
||||||
|
|
||||||
|
setBaby(true);
|
||||||
|
setInvisible(true);
|
||||||
|
noClip = true;
|
||||||
|
|
||||||
|
MinecraftServer server = getServer();
|
||||||
|
if (server != null) {
|
||||||
|
ServerScoreboard scoreboard = server.getScoreboard();
|
||||||
|
|
||||||
|
Team team = scoreboard.getTeam(TEAM_NAME);
|
||||||
|
if (team == null) {
|
||||||
|
team = scoreboard.addTeam(TEAM_NAME);
|
||||||
|
}
|
||||||
|
if (team.getCollisionRule() != AbstractTeam.CollisionRule.NEVER) {
|
||||||
|
team.setCollisionRule(AbstractTeam.CollisionRule.NEVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
scoreboard.addPlayerToTeam(getEntityName(), team);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getHealth() {
|
||||||
|
return 1.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detachLeash(boolean sendPacket, boolean dropItem) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeLeashedBy(PlayerEntity player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initGoals() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void pushAway(Entity entity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushAwayFrom(Entity entity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerCollision(PlayerEntity player) {
|
||||||
|
}
|
||||||
|
}
|
7
src/main/java/me/pog5/leashmod/LeashSettings.java
Normal file
7
src/main/java/me/pog5/leashmod/LeashSettings.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package me.pog5.leashmod;
|
||||||
|
|
||||||
|
public interface LeashSettings {
|
||||||
|
boolean isEnabled();
|
||||||
|
double getDistanceMin();
|
||||||
|
double getDistanceMax();
|
||||||
|
}
|
26
src/main/java/me/pog5/leashmod/mixin/MixinPlayerEntity.java
Normal file
26
src/main/java/me/pog5/leashmod/mixin/MixinPlayerEntity.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package me.pog5.leashmod.mixin;
|
||||||
|
|
||||||
|
import me.pog5.leashmod.LeashImpl;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(PlayerEntity.class)
|
||||||
|
public abstract class MixinPlayerEntity {
|
||||||
|
@Inject(method = "interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;", at = @At("RETURN"), cancellable = true)
|
||||||
|
private void leashplayers$onInteract(Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> info) {
|
||||||
|
if (info.getReturnValue() != ActionResult.PASS) return;
|
||||||
|
if ((Object) this instanceof ServerPlayerEntity && entity instanceof LeashImpl) {
|
||||||
|
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
|
||||||
|
LeashImpl impl = (LeashImpl) entity;
|
||||||
|
info.setReturnValue(impl.leashplayers$interact(player, hand));
|
||||||
|
info.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,157 @@
|
||||||
|
package me.pog5.leashmod.mixin;
|
||||||
|
|
||||||
|
import me.pog5.leashmod.LeashImpl;
|
||||||
|
import me.pog5.leashmod.LeashPlayers;
|
||||||
|
import me.pog5.leashmod.LeashProxyEntity;
|
||||||
|
import me.pog5.leashmod.LeashSettings;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(ServerPlayerEntity.class)
|
||||||
|
public abstract class MixinServerPlayerEntity implements LeashImpl {
|
||||||
|
private final ServerPlayerEntity leashplayers$self = (ServerPlayerEntity) (Object) this;
|
||||||
|
private final LeashSettings leashplayers$settings = LeashPlayers.getSettings(leashplayers$self.world);
|
||||||
|
|
||||||
|
private LeashProxyEntity leashplayers$proxy;
|
||||||
|
private Entity leashplayers$holder;
|
||||||
|
|
||||||
|
private int leashplayers$lastage;
|
||||||
|
|
||||||
|
private boolean leashplayers$disabled() {
|
||||||
|
return !leashplayers$settings.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void leashplayers$update() {
|
||||||
|
if (
|
||||||
|
leashplayers$holder != null && (
|
||||||
|
leashplayers$disabled()
|
||||||
|
|| !leashplayers$holder.isAlive()
|
||||||
|
|| !leashplayers$self.isAlive()
|
||||||
|
|| leashplayers$self.hasVehicle()
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
leashplayers$detach();
|
||||||
|
leashplayers$drop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leashplayers$proxy != null) {
|
||||||
|
if (leashplayers$proxy.proxyIsRemoved()) {
|
||||||
|
leashplayers$proxy = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Entity holderActual = leashplayers$holder;
|
||||||
|
Entity holderTarget = leashplayers$proxy.getHoldingEntity();
|
||||||
|
|
||||||
|
if (holderTarget == null && holderActual != null) {
|
||||||
|
leashplayers$detach();
|
||||||
|
leashplayers$drop();
|
||||||
|
}
|
||||||
|
else if (holderTarget != holderActual) {
|
||||||
|
leashplayers$attach(holderTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
leashplayers$apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void leashplayers$apply() {
|
||||||
|
ServerPlayerEntity player = leashplayers$self;
|
||||||
|
Entity holder = leashplayers$holder;
|
||||||
|
if (holder == null) return;
|
||||||
|
if (holder.world != player.world) return;
|
||||||
|
|
||||||
|
float distance = player.distanceTo(holder);
|
||||||
|
if (distance < leashplayers$settings.getDistanceMin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (distance > leashplayers$settings.getDistanceMax()) {
|
||||||
|
leashplayers$detach();
|
||||||
|
leashplayers$drop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double dx = (holder.getX() - player.getX()) / (double) distance;
|
||||||
|
double dy = (holder.getY() - player.getY()) / (double) distance;
|
||||||
|
double dz = (holder.getZ() - player.getZ()) / (double) distance;
|
||||||
|
|
||||||
|
player.addVelocity(
|
||||||
|
Math.copySign(dx * dx * 0.4D, dx),
|
||||||
|
Math.copySign(dy * dy * 0.4D, dy),
|
||||||
|
Math.copySign(dz * dz * 0.4D, dz)
|
||||||
|
);
|
||||||
|
|
||||||
|
player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(player));
|
||||||
|
player.velocityDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void leashplayers$attach(Entity entity) {
|
||||||
|
leashplayers$holder = entity;
|
||||||
|
|
||||||
|
if (leashplayers$proxy == null) {
|
||||||
|
leashplayers$proxy = new LeashProxyEntity(leashplayers$self);
|
||||||
|
leashplayers$self.world.spawnEntity(leashplayers$proxy);
|
||||||
|
}
|
||||||
|
leashplayers$proxy.attachLeash(leashplayers$holder, true);
|
||||||
|
|
||||||
|
if (leashplayers$self.hasVehicle()) {
|
||||||
|
leashplayers$self.stopRiding();
|
||||||
|
}
|
||||||
|
|
||||||
|
leashplayers$lastage = leashplayers$self.age;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void leashplayers$detach() {
|
||||||
|
leashplayers$holder = null;
|
||||||
|
|
||||||
|
if (leashplayers$proxy != null) {
|
||||||
|
if (leashplayers$proxy.isAlive() || !leashplayers$proxy.proxyIsRemoved()) {
|
||||||
|
leashplayers$proxy.proxyRemove();
|
||||||
|
}
|
||||||
|
leashplayers$proxy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void leashplayers$drop() {
|
||||||
|
leashplayers$self.dropItem(Items.LEAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "tick()V", at = @At("TAIL"))
|
||||||
|
private void leashplayers$tick(CallbackInfo info) {
|
||||||
|
leashplayers$update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult leashplayers$interact(PlayerEntity player, Hand hand) {
|
||||||
|
if (leashplayers$disabled()) return ActionResult.PASS;
|
||||||
|
|
||||||
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
if (stack.getItem() == Items.LEAD && leashplayers$holder == null) {
|
||||||
|
if (!player.isCreative()) {
|
||||||
|
stack.decrement(1);
|
||||||
|
}
|
||||||
|
leashplayers$attach(player);
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leashplayers$holder == player && leashplayers$lastage + 20 < leashplayers$self.age) {
|
||||||
|
if (!player.isCreative()) {
|
||||||
|
leashplayers$drop();
|
||||||
|
}
|
||||||
|
leashplayers$detach();
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActionResult.PASS;
|
||||||
|
}
|
||||||
|
}
|
20
src/main/java/me/pog5/leashmod/mixin/MixinServerWorld.java
Normal file
20
src/main/java/me/pog5/leashmod/mixin/MixinServerWorld.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package me.pog5.leashmod.mixin;
|
||||||
|
|
||||||
|
import me.pog5.leashmod.LeashProxyEntity;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(ServerWorld.class)
|
||||||
|
public abstract class MixinServerWorld {
|
||||||
|
@Inject(method = "shouldCancelSpawn(Lnet/minecraft/entity/Entity;)Z", at = @At("HEAD"), cancellable = true, require = 0)
|
||||||
|
private void leashplayers$onShouldCancelSpawn(Entity entity, CallbackInfoReturnable<Boolean> info) {
|
||||||
|
if (entity instanceof LeashProxyEntity) {
|
||||||
|
info.setReturnValue(false);
|
||||||
|
info.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
src/main/java/me/pog5/leashmod/mixin/MixinTurtleEntity.java
Normal file
29
src/main/java/me/pog5/leashmod/mixin/MixinTurtleEntity.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package me.pog5.leashmod.mixin;
|
||||||
|
|
||||||
|
import me.pog5.leashmod.LeashProxyEntity;
|
||||||
|
import net.minecraft.entity.passive.TurtleEntity;
|
||||||
|
import net.minecraft.scoreboard.Team;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Mixin(TurtleEntity.class)
|
||||||
|
public abstract class MixinTurtleEntity {
|
||||||
|
@Inject(method = "readCustomDataFromNbt(Lnet/minecraft/nbt/NbtCompound;)V", at = @At("RETURN"))
|
||||||
|
private void leashplayers$onReadCustomDataFromNbt(CallbackInfo info) {
|
||||||
|
TurtleEntity self = (TurtleEntity) (Object) this;
|
||||||
|
|
||||||
|
MinecraftServer server = self.getServer();
|
||||||
|
if (server == null) return;
|
||||||
|
|
||||||
|
Team team = server.getScoreboard().getPlayerTeam(self.getEntityName());
|
||||||
|
if (team != null && Objects.equals(team.getName(), LeashProxyEntity.TEAM_NAME)) {
|
||||||
|
self.setInvulnerable(false);
|
||||||
|
self.setHealth(0.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
src/main/resources/assets/leashplayers/icon.png
Normal file
BIN
src/main/resources/assets/leashplayers/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3 KiB |
5
src/main/resources/assets/leashplayers/lang/en_us.json
Normal file
5
src/main/resources/assets/leashplayers/lang/en_us.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"gamerule.leashPlayersEnabled": "Enable players leading other players",
|
||||||
|
"gamerule.leashPlayersDistanceMin": "Minimum player lead length before applying knockback",
|
||||||
|
"gamerule.leashPlayersDistanceMax": "Maximum player lead length before breaking"
|
||||||
|
}
|
BIN
src/main/resources/assets/modid/icon.png
Normal file
BIN
src/main/resources/assets/modid/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 453 B |
38
src/main/resources/fabric.mod.json
Normal file
38
src/main/resources/fabric.mod.json
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "leashmod",
|
||||||
|
"version": "${version}",
|
||||||
|
|
||||||
|
"name": "Pog5's Leashable Players",
|
||||||
|
"description": "A simple mod that let's you leash players.",
|
||||||
|
"authors": [
|
||||||
|
"Me!"
|
||||||
|
],
|
||||||
|
"contact": {
|
||||||
|
"homepage": "https://fabricmc.net/",
|
||||||
|
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||||
|
},
|
||||||
|
|
||||||
|
"license": "CC0-1.0",
|
||||||
|
"icon": "assets/modid/icon.png",
|
||||||
|
|
||||||
|
"environment": "*",
|
||||||
|
"entrypoints": {
|
||||||
|
"main": [
|
||||||
|
"me.pog5.leashmod.LeashPlayers"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mixins": [
|
||||||
|
"leashplayers.mixins.json"
|
||||||
|
],
|
||||||
|
|
||||||
|
"depends": {
|
||||||
|
"fabricloader": ">=0.14.14",
|
||||||
|
"fabric-api": "*",
|
||||||
|
"minecraft": "~1.19.3",
|
||||||
|
"java": ">=17"
|
||||||
|
},
|
||||||
|
"suggests": {
|
||||||
|
"another-mod": "*"
|
||||||
|
}
|
||||||
|
}
|
15
src/main/resources/leashplayers.mixins.json
Normal file
15
src/main/resources/leashplayers.mixins.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"compatibilityLevel": "JAVA_17",
|
||||||
|
"package": "me.pog5.leashmod.mixin",
|
||||||
|
"required": true,
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
},
|
||||||
|
"mixins": [
|
||||||
|
"MixinPlayerEntity",
|
||||||
|
"MixinServerPlayerEntity",
|
||||||
|
"MixinServerWorld",
|
||||||
|
"MixinTurtleEntity"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue