Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 7aeb1e8

Browse files
committed
License headers entity events mixins
1 parent de46403 commit 7aeb1e8

3 files changed

Lines changed: 135 additions & 78 deletions

File tree

patchwork-events-entity/src/main/java/com/patchworkmc/mixin/event/entity/MixinEntityType.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
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+
120
package com.patchworkmc.mixin.event.entity;
221

322
import javax.annotation.Nullable;
Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
1-
package com.patchworkmc.mixin.event.entity;
2-
3-
import org.spongepowered.asm.mixin.Mixin;
4-
import org.spongepowered.asm.mixin.injection.At;
5-
import org.spongepowered.asm.mixin.injection.Redirect;
6-
7-
import net.minecraft.entity.SpawnType;
8-
import net.minecraft.entity.mob.MobEntity;
9-
import net.minecraft.world.IWorld;
10-
import net.minecraft.world.MobSpawnerLogic;
11-
import net.minecraft.world.ViewableWorld;
12-
import net.minecraft.world.World;
13-
14-
import com.patchworkmc.impl.event.entity.EntityEvents;
15-
16-
@Mixin(MobSpawnerLogic.class)
17-
public class MixinMobSpawnerLogic {
18-
@Redirect(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/IWorld;Lnet/minecraft/entity/SpawnType;)Z"))
19-
private boolean spawnTestRedirect(MobEntity on, IWorld world, SpawnType type) {
20-
MobSpawnerLogic spawner = (MobSpawnerLogic) (Object) this;
21-
22-
return EntityEvents.canEntitySpawnFromSpawner(on, (World) world, on.x, on.y, on.z, spawner);
23-
}
24-
25-
@Redirect(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/ViewableWorld;)Z"))
26-
private boolean makeTheOtherMethodNotMessItUp(MobEntity on, ViewableWorld world) {
27-
return true;
28-
}
29-
}
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.injection.At;
24+
import org.spongepowered.asm.mixin.injection.Redirect;
25+
26+
import net.minecraft.entity.SpawnType;
27+
import net.minecraft.entity.mob.MobEntity;
28+
import net.minecraft.world.IWorld;
29+
import net.minecraft.world.MobSpawnerLogic;
30+
import net.minecraft.world.ViewableWorld;
31+
import net.minecraft.world.World;
32+
33+
import com.patchworkmc.impl.event.entity.EntityEvents;
34+
35+
@Mixin(MobSpawnerLogic.class)
36+
public class MixinMobSpawnerLogic {
37+
@Redirect(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/IWorld;Lnet/minecraft/entity/SpawnType;)Z"))
38+
private boolean spawnTestRedirect(MobEntity on, IWorld world, SpawnType type) {
39+
MobSpawnerLogic spawner = (MobSpawnerLogic) (Object) this;
40+
41+
return EntityEvents.canEntitySpawnFromSpawner(on, (World) world, on.x, on.y, on.z, spawner);
42+
}
43+
44+
@Redirect(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/ViewableWorld;)Z"))
45+
private boolean makeTheOtherMethodNotMessItUp(MobEntity on, ViewableWorld world) {
46+
return true;
47+
}
48+
}
Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,68 @@
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

Comments
 (0)