|
| 1 | +package io.github.optijava.opt_carpet_addition.mixins.disabledEnderManPickupGoal; |
| 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.entity.mob.EndermanEntity; |
| 7 | +import net.minecraft.tag.BlockTags; |
| 8 | +import net.minecraft.util.hit.BlockHitResult; |
| 9 | +import net.minecraft.util.math.BlockPos; |
| 10 | +import net.minecraft.util.math.MathHelper; |
| 11 | +import net.minecraft.util.math.Vec3d; |
| 12 | +import net.minecraft.world.RaycastContext; |
| 13 | +import net.minecraft.world.World; |
| 14 | +import org.spongepowered.asm.mixin.Mixin; |
| 15 | +import org.spongepowered.asm.mixin.Overwrite; |
| 16 | +import org.spongepowered.asm.mixin.Shadow; |
| 17 | + |
| 18 | +import java.util.Random; |
| 19 | + |
| 20 | +@Mixin(EndermanEntity.PickUpBlockGoal.class) |
| 21 | +public class EnderManEntity_Mixin { |
| 22 | + @Shadow |
| 23 | + EndermanEntity enderman; |
| 24 | + |
| 25 | + @Overwrite |
| 26 | + public void tick() { |
| 27 | + if (!OptCarpetSettings.disabledEnderManPickupGoal) { |
| 28 | + Random random = this.enderman.getRandom(); |
| 29 | + World world = this.enderman.world; |
| 30 | + int i = MathHelper.floor(this.enderman.getX() - 2.0 + random.nextDouble() * 4.0); |
| 31 | + int j = MathHelper.floor(this.enderman.getY() + random.nextDouble() * 3.0); |
| 32 | + int k = MathHelper.floor(this.enderman.getZ() - 2.0 + random.nextDouble() * 4.0); |
| 33 | + BlockPos blockPos = new BlockPos(i, j, k); |
| 34 | + BlockState blockState = world.getBlockState(blockPos); |
| 35 | + Block block = blockState.getBlock(); |
| 36 | + Vec3d vec3d = new Vec3d((double) MathHelper.floor(this.enderman.getX()) + 0.5, (double) j + 0.5, (double) MathHelper.floor(this.enderman.getZ()) + 0.5); |
| 37 | + Vec3d vec3d2 = new Vec3d((double) i + 0.5, (double) j + 0.5, (double) k + 0.5); |
| 38 | + BlockHitResult blockHitResult = world.raycast(new RaycastContext(vec3d, vec3d2, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, this.enderman)); |
| 39 | + boolean bl = blockHitResult.getBlockPos().equals(blockPos); |
| 40 | + if (block.isIn(BlockTags.ENDERMAN_HOLDABLE) && bl) { |
| 41 | + world.removeBlock(blockPos, false); |
| 42 | + this.enderman.setCarriedBlock(blockState.getBlock().getDefaultState()); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments