Skip to content

Commit

Permalink
Create gamerule to control whether Endermen holding blocks are persis…
Browse files Browse the repository at this point in the history
…tent
  • Loading branch information
Samadi van Koten committed Feb 3, 2021
1 parent 95ab87b commit f8bb8ad
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 66 deletions.
7 changes: 1 addition & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ dependencies {
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}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
modImplementation fabricApi.module("fabric-game-rule-api-v1", project.fabric_version)
}

processResources {
Expand Down
20 changes: 8 additions & 12 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.4
yarn_mappings=1.16.4+build.6
loader_version=0.10.6+build.214
# check these on https://fabricmc.net/use
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.2
loader_version=0.11.1
fabric_version=0.30.0+1.16

# Mod Properties
mod_version = 1.0.0
maven_group = net.fabricmc
archives_base_name = fabric-example-mod

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.25.1+build.416-1.16
mod_version = 1.0.0
maven_group = vktec
archives_base_name = unpersist-endermen
14 changes: 0 additions & 14 deletions src/main/java/net/fabricmc/example/ExampleMod.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/net/fabricmc/example/mixin/ExampleMixin.java

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/java/vktec/unpersistendermen/UnpersistEndermenMod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package vktec.unpersistendermen;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.minecraft.world.GameRules;

public class UnpersistEndermenMod implements ModInitializer {
public static GameRules.Key<GameRules.BooleanRule> ENDERMEN_PERSIST = GameRuleRegistry.register("endermenPersist", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true));

@Override
public void onInitialize() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package vktec.unpersistendermen.mixin;

import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.EndermanEntity;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import vktec.unpersistendermen.UnpersistEndermenMod;

@Mixin(EndermanEntity.class)
public abstract class EndermanEntityMixin extends HostileEntity {
public EndermanEntityMixin(EntityType<? extends EndermanEntity> arg, World arg2) {
super(arg, arg2);
}

@Redirect(method = "cannotDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/EndermanEntity;getCarriedBlock()Lnet/minecraft/block/BlockState;"))
public BlockState redirectCarriedBlock(EndermanEntity self) {
if (self.world.isClient || self.world.getGameRules().getBoolean(UnpersistEndermenMod.ENDERMEN_PERSIST)) {
return self.getCarriedBlock();
} else {
return null;
}
}
}
Binary file removed src/main/resources/assets/modid/icon.png
Binary file not shown.
26 changes: 11 additions & 15 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
{
"schemaVersion": 1,
"id": "modid",
"id": "unpersist-endermen",
"version": "${version}",

"name": "Example Mod",
"description": "This is an example description! Tell everyone what your mod is about!",
"name": "Unpersist Endermen",
"description": "Make Endermen holding blocks non-persistent",
"authors": [
"Me!"
"vktec"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://github.com/FabricMC/fabric-example-mod"
"homepage": "https://github.com/vktec/unpersist-endermen",
"sources": "https://github.com/vktec/unpersist-endermen"
},

"license": "CC0-1.0",
"icon": "assets/modid/icon.png",
"license": "Unlicense",

"environment": "*",
"entrypoints": {
"main": [
"net.fabricmc.example.ExampleMod"
"vktec.unpersistendermen.UnpersistEndermenMod"
]
},
"environment": "*",
"mixins": [
"modid.mixins.json"
"unpersist-endermen.mixins.json"
],

"depends": {
"fabricloader": ">=0.7.4",
"fabric": "*",
"fabric-game-rule-api-v1": "*",
"minecraft": "1.16.x"
},
"suggests": {
"another-mod": "*"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.fabricmc.example.mixin",
"package": "vktec.unpersistendermen.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
"ExampleMixin"
"EndermanEntityMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit f8bb8ad

Please sign in to comment.