Skip to content

Commit 1c09001

Browse files
committed
add rule: disabledEnderManPlaceBlockGoal
1 parent fe074f5 commit 1c09001

File tree

6 files changed

+82
-3
lines changed

6 files changed

+82
-3
lines changed

src/main/java/io/github/optijava/opt_carpet_addition/OptCarpetSettings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,10 @@ public class OptCarpetSettings {
9898
)
9999
public static boolean disabledEnderManPickupGoal = false;
100100

101+
@Rule(
102+
desc = "Disable Enderman place block goal",
103+
category = RuleCategory.FEATURE
104+
)
105+
public static boolean disabledEnderManPlaceBlockGoal = false;
106+
101107
}

src/main/java/io/github/optijava/opt_carpet_addition/mixins/disabledEnderManPickupGoal/EnderManEntity_Mixin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public class EnderManEntity_Mixin {
2222
@Shadow
2323
EndermanEntity enderman;
2424

25+
/**
26+
* Mixin EndermanEntity.PickUpBlockGoal.tick()V
27+
*
28+
* @author OptiJava
29+
* @reason rule: disabledEnderManPickupGoal
30+
*/
2531
@Overwrite
2632
public void tick() {
2733
if (!OptCarpetSettings.disabledEnderManPickupGoal) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.github.optijava.opt_carpet_addition.mixins.disabledEnderManPlaceBlockGoal;
2+
3+
import io.github.optijava.opt_carpet_addition.OptCarpetSettings;
4+
import net.minecraft.block.Block;
5+
import net.minecraft.block.BlockState;
6+
import net.minecraft.block.Blocks;
7+
import net.minecraft.entity.mob.EndermanEntity;
8+
import net.minecraft.util.math.BlockPos;
9+
import net.minecraft.util.math.Box;
10+
import net.minecraft.util.math.MathHelper;
11+
import net.minecraft.util.math.Vec3d;
12+
import net.minecraft.world.World;
13+
import org.spongepowered.asm.mixin.Mixin;
14+
import org.spongepowered.asm.mixin.Overwrite;
15+
import org.spongepowered.asm.mixin.Shadow;
16+
17+
import java.util.Random;
18+
19+
@Mixin(EndermanEntity.PlaceBlockGoal.class)
20+
public class EndermanEntity_Mixin {
21+
22+
private boolean canPlaceOn(World world, BlockPos posAbove, BlockState carriedState, BlockState stateAbove, BlockState state, BlockPos pos) {
23+
return stateAbove.isAir() && !state.isAir() && !state.isOf(Blocks.BEDROCK) && state.isFullCube(world, pos) && carriedState.canPlaceAt(world, posAbove) && world.getOtherEntities(this.enderman, Box.method_29968(Vec3d.of(posAbove))).isEmpty();
24+
}
25+
26+
@Shadow
27+
EndermanEntity enderman;
28+
29+
/**
30+
* Mixin EndermanEntity.PlaceBlockGoal.tick()V
31+
*
32+
* @author OptiJava
33+
* @reason rule: disabledEnderManPlaceBlockGoal
34+
*/
35+
@Overwrite
36+
public void tick() {
37+
if (!OptCarpetSettings.disabledEnderManPlaceBlockGoal) {
38+
Random random = this.enderman.getRandom();
39+
World world = this.enderman.world;
40+
int i = MathHelper.floor(this.enderman.getX() - 1.0 + random.nextDouble() * 2.0);
41+
int j = MathHelper.floor(this.enderman.getY() + random.nextDouble() * 2.0);
42+
int k = MathHelper.floor(this.enderman.getZ() - 1.0 + random.nextDouble() * 2.0);
43+
BlockPos blockPos = new BlockPos(i, j, k);
44+
BlockState blockState = world.getBlockState(blockPos);
45+
BlockPos blockPos2 = blockPos.down();
46+
BlockState blockState2 = world.getBlockState(blockPos2);
47+
BlockState blockState3 = this.enderman.getCarriedBlock();
48+
if (blockState3 != null) {
49+
blockState3 = Block.postProcessState(blockState3, this.enderman.world, blockPos);
50+
if (this.canPlaceOn(world, blockPos, blockState3, blockState, blockState2, blockPos2)) {
51+
world.setBlockState(blockPos, blockState3, 3);
52+
this.enderman.setCarriedBlock((BlockState) null);
53+
}
54+
}
55+
}
56+
}
57+
}

src/main/java/io/github/optijava/opt_carpet_addition/mixins/disabledLayEggs/ChickenEntity_Mixin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88

99
@Mixin(ChickenEntity.class)
1010
public class ChickenEntity_Mixin {
11+
12+
/**
13+
* Mixin ChickenEntity.tickMovement()V
14+
*
15+
* @author OptiJava
16+
* @reason rule: disabledLayEggs
17+
*/
1118
@Inject(at = @At("HEAD"), method = "tickMovement()V")
1219
public void injectTickMovement() {
1320
if (OptCarpetSettings.disabledLayEggs) {
14-
((ChickenEntity) (Object) this).eggLayTime = 100;
21+
((ChickenEntity) (Object) this).eggLayTime = 50;
1522
}
1623
}
1724
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
accessWidener v1 named
2-
accessible class net/minecraft/entity/mob/EndermanEntity$PickUpBlockGoal
2+
accessible class net/minecraft/entity/mob/EndermanEntity$PickUpBlockGoal
3+
accessible class net/minecraft/entity/mob/EndermanEntity$PlaceBlockGoal

src/main/resources/opt-carpet-addition.mixins.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"package": "io.github.optijava.opt_carpet_addition.mixins",
55
"compatibilityLevel": "JAVA_8",
66
"mixins": [
7-
"disabledLayEggs.ChickenEntity_Mixin"
7+
"disabledLayEggs.ChickenEntity_Mixin",
8+
"disabledEnderManPickupGoal.EnderManEntity_Mixin",
9+
"disabledEnderManPlaceBlockGoal.EndermanEntity_Mixin"
810
],
911
"client": [
1012
],

0 commit comments

Comments
 (0)