Skip to content

Commit e69e1d5

Browse files
Add doEndermanPlace gamerule
1 parent ad7f19e commit e69e1d5

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

src/main/java/com/thepinkhacker/commandsplus/mixin/entity/mob/EndermanEntityPickUpBlockGoalMixin.java

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.thepinkhacker.commandsplus.world.GameRuleManager;
44
import net.minecraft.entity.mob.EndermanEntity;
55
import net.minecraft.server.world.ServerWorld;
6-
import net.minecraft.world.GameRules;
76
import org.spongepowered.asm.mixin.Final;
87
import org.spongepowered.asm.mixin.Mixin;
98
import org.spongepowered.asm.mixin.Shadow;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.thepinkhacker.commandsplus.mixin.entity.mob;
2+
3+
import com.thepinkhacker.commandsplus.world.GameRuleManager;
4+
import net.minecraft.entity.mob.EndermanEntity;
5+
import net.minecraft.server.world.ServerWorld;
6+
import org.spongepowered.asm.mixin.Final;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
12+
13+
@Mixin(EndermanEntity.PlaceBlockGoal.class)
14+
public class EndermanEntityPlaceBlockGoalMixin {
15+
@Shadow
16+
@Final
17+
private EndermanEntity enderman;
18+
19+
@Inject(
20+
method = "canStart()Z",
21+
at = @At("RETURN"),
22+
cancellable = true
23+
)
24+
private void commandsplus_gamerule_check(CallbackInfoReturnable<Boolean> cir) {
25+
if (this.enderman.getWorld() instanceof ServerWorld world) {
26+
if (!world.getGameRules().getBoolean(GameRuleManager.DO_ENDERMAN_PLACE)) {
27+
cir.setReturnValue(false);
28+
}
29+
}
30+
}
31+
}

src/main/java/com/thepinkhacker/commandsplus/world/GameRuleManager.java

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public class GameRuleManager {
1616
GameRules.BooleanRule.create(true)
1717
);
1818

19+
public static final GameRules.Key<GameRules.BooleanRule> DO_ENDERMAN_PLACE = GameRuleRegistry.register(
20+
"doEndermanPlace",
21+
GameRules.Category.MOBS,
22+
GameRules.BooleanRule.create(true)
23+
);
24+
1925
// Java is weird and won't init the variables unless this runs
2026
// Otherwise it would try to init after the registry is frozen
2127
public static void register() {}

src/main/resources/assets/commandsplus/lang/en_us.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@
6060
"gamerule.itemDespawnAge": "Item Despawn Age",
6161
"gamerule.itemDespawnAge.description": "Controls how long it takes for an item to despawn.",
6262
"gamerule.doEndermanPickup": "Do Enderman Pickup",
63-
"gamerule.doEndermanPickup.description": "Allow Endermen to pick up blocks."
63+
"gamerule.doEndermanPickup.description": "Allow Endermen to pick up blocks.",
64+
"gamerule.doEndermanPlace": "Do Enderman Place",
65+
"gamerule.doEndermanPlace.description": "Allow Endermen to place blocks."
6466
}

src/main/resources/commandsplus.accesswidener

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ accessible method net/minecraft/block/entity/SignBlockEntity updateListeners ()V
1111
accessible field net/minecraft/entity/player/HungerManager exhaustion F
1212

1313
accessible class net/minecraft/entity/mob/EndermanEntity$PickUpBlockGoal
14+
accessible class net/minecraft/entity/mob/EndermanEntity$PlaceBlockGoal

src/main/resources/commandsplus.mixins.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"compatibilityLevel": "JAVA_17",
66
"mixins": [
77
"entity.ItemEntityMixin",
8-
"entity.mob.EndermanEntityPickUpBlockGoalMixin"
8+
"entity.mob.EndermanEntityPickUpBlockGoalMixin",
9+
"entity.mob.EndermanEntityPlaceBlockGoalMixin"
910
],
1011
"client": [],
1112
"injectors": {

0 commit comments

Comments
 (0)