|
1 | | -package com.patchworkmc.mixin.event.entity; |
2 | | - |
3 | | -import org.spongepowered.asm.mixin.Mixin; |
4 | | -import org.spongepowered.asm.mixin.Unique; |
5 | | -import org.spongepowered.asm.mixin.injection.At; |
6 | | -import org.spongepowered.asm.mixin.injection.Redirect; |
7 | | - |
8 | | -import net.minecraft.entity.EntityData; |
9 | | -import net.minecraft.entity.SpawnType; |
10 | | -import net.minecraft.entity.mob.MobEntity; |
11 | | -import net.minecraft.nbt.CompoundTag; |
12 | | -import net.minecraft.world.IWorld; |
13 | | -import net.minecraft.world.LocalDifficulty; |
14 | | -import net.minecraft.world.SpawnHelper; |
15 | | -import net.minecraft.world.ViewableWorld; |
16 | | - |
17 | | -import com.patchworkmc.impl.event.entity.EntityEvents; |
18 | | - |
19 | | -@Mixin(SpawnHelper.class) |
20 | | -public class MixinSpawnHelper { |
21 | | - @Unique |
22 | | - private static double playerDistanceStore; |
23 | | - |
24 | | - //We re-implement the vanilla logic in the event, disable it here. Also capture the player distance. |
25 | | - @Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canImmediatelyDespawn(D)Z")) |
26 | | - private static boolean disableVanillaLogicAndCaptureDistance(MobEntity entity, double distFromPlayer) { |
27 | | - playerDistanceStore = distFromPlayer; |
28 | | - return false; |
29 | | - } |
30 | | - |
31 | | - @Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/IWorld;Lnet/minecraft/entity/SpawnType;)Z")) |
32 | | - private static boolean hookCheckSpawn(MobEntity entity, IWorld world, SpawnType spawnType) { |
33 | | - return EntityEvents.canEntitySpawnNaturally(entity, entity.world, entity.x, entity.y, entity.x, null, spawnType, playerDistanceStore); |
34 | | - } |
35 | | - |
36 | | - @Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/ViewableWorld;)Z")) |
37 | | - private static boolean disableVanillaLogic(MobEntity entity, ViewableWorld world) { |
38 | | - return true; |
39 | | - } |
40 | | - |
41 | | - @Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;")) |
42 | | - private static EntityData hookSpecialSpawn(MobEntity entity, IWorld world, LocalDifficulty localDifficulty, SpawnType spawnType, EntityData data, CompoundTag tag) { |
43 | | - if (!EntityEvents.doSpecialSpawn(entity, world, entity.x, entity.y, entity.z, null, spawnType)) { |
44 | | - return entity.initialize(world, localDifficulty, spawnType, data, tag); |
45 | | - } else { |
46 | | - return data; |
47 | | - } |
48 | | - } |
49 | | -} |
| 1 | +/* |
| 2 | + * Minecraft Forge, Patchwork Project |
| 3 | + * Copyright (c) 2016-2019, 2019 |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation version 2.1 |
| 8 | + * of the License. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this library; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + */ |
| 19 | + |
| 20 | +package com.patchworkmc.mixin.event.entity; |
| 21 | + |
| 22 | +import org.spongepowered.asm.mixin.Mixin; |
| 23 | +import org.spongepowered.asm.mixin.Unique; |
| 24 | +import org.spongepowered.asm.mixin.injection.At; |
| 25 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 26 | + |
| 27 | +import net.minecraft.entity.EntityData; |
| 28 | +import net.minecraft.entity.SpawnType; |
| 29 | +import net.minecraft.entity.mob.MobEntity; |
| 30 | +import net.minecraft.nbt.CompoundTag; |
| 31 | +import net.minecraft.world.IWorld; |
| 32 | +import net.minecraft.world.LocalDifficulty; |
| 33 | +import net.minecraft.world.SpawnHelper; |
| 34 | +import net.minecraft.world.ViewableWorld; |
| 35 | + |
| 36 | +import com.patchworkmc.impl.event.entity.EntityEvents; |
| 37 | + |
| 38 | +@Mixin(SpawnHelper.class) |
| 39 | +public class MixinSpawnHelper { |
| 40 | + @Unique |
| 41 | + private static double playerDistanceStore; |
| 42 | + |
| 43 | + //We re-implement the vanilla logic in the event, disable it here. Also capture the player distance. |
| 44 | + @Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canImmediatelyDespawn(D)Z")) |
| 45 | + private static boolean disableVanillaLogicAndCaptureDistance(MobEntity entity, double distFromPlayer) { |
| 46 | + playerDistanceStore = distFromPlayer; |
| 47 | + return false; |
| 48 | + } |
| 49 | + |
| 50 | + @Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/IWorld;Lnet/minecraft/entity/SpawnType;)Z")) |
| 51 | + private static boolean hookCheckSpawn(MobEntity entity, IWorld world, SpawnType spawnType) { |
| 52 | + return EntityEvents.canEntitySpawnNaturally(entity, entity.world, entity.x, entity.y, entity.x, null, spawnType, playerDistanceStore); |
| 53 | + } |
| 54 | + |
| 55 | + @Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/ViewableWorld;)Z")) |
| 56 | + private static boolean disableVanillaLogic(MobEntity entity, ViewableWorld world) { |
| 57 | + return true; |
| 58 | + } |
| 59 | + |
| 60 | + @Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;")) |
| 61 | + private static EntityData hookSpecialSpawn(MobEntity entity, IWorld world, LocalDifficulty localDifficulty, SpawnType spawnType, EntityData data, CompoundTag tag) { |
| 62 | + if (!EntityEvents.doSpecialSpawn(entity, world, entity.x, entity.y, entity.z, null, spawnType)) { |
| 63 | + return entity.initialize(world, localDifficulty, spawnType, data, tag); |
| 64 | + } else { |
| 65 | + return data; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments