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

Commit 7b45a70

Browse files
committed
Dispatch from patchwork-god-classes to EntityEvents
1 parent f62f7d4 commit 7b45a70

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed

patchwork-events-entity/src/main/java/net/patchworkmc/impl/event/entity/EntityEvents.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import net.minecraft.entity.mob.MobEntity;
5454
import net.minecraft.entity.player.PlayerEntity;
5555
import net.minecraft.item.ItemStack;
56-
import net.minecraft.server.network.ServerPlayerEntity;
5756
import net.minecraft.util.ActionResult;
5857
import net.minecraft.util.Hand;
5958
import net.minecraft.world.IWorld;
@@ -96,7 +95,7 @@ public static void onEnteringChunk(Entity entity, int newChunkX, int newChunkZ,
9695
}
9796

9897
// PlayerEvents
99-
public static void onPlayerLoggedIn(ServerPlayerEntity playerEntity) {
98+
public static void onPlayerLoggedIn(PlayerEntity playerEntity) {
10099
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedInEvent(playerEntity));
101100
}
102101

patchwork-god-classes/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ version = getSubprojectVersion(project, "0.1.0")
33

44
dependencies {
55
compile project(path: ':patchwork-fml', configuration: 'dev')
6+
compile project(path: ':patchwork-events-entity', configuration: 'dev')
67
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
78
}

patchwork-god-classes/src/main/java/net/minecraftforge/common/ForgeHooks.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,82 @@
1919

2020
package net.minecraftforge.common;
2121

22+
import java.util.Collection;
23+
import javax.annotation.Nullable;
24+
25+
import net.minecraftforge.event.ForgeEventFactory;
26+
import net.minecraftforge.eventbus.api.Event;
27+
28+
import net.minecraft.entity.Entity;
29+
import net.minecraft.entity.ItemEntity;
30+
import net.minecraft.entity.LivingEntity;
31+
import net.minecraft.entity.SpawnType;
32+
import net.minecraft.entity.damage.DamageSource;
33+
import net.minecraft.entity.mob.MobEntity;
34+
import net.minecraft.entity.player.PlayerEntity;
35+
import net.minecraft.util.ActionResult;
36+
import net.minecraft.util.Hand;
37+
import net.minecraft.world.IWorld;
38+
import net.minecraft.world.MobSpawnerLogic;
39+
40+
import net.patchworkmc.impl.event.entity.EntityEvents;
41+
2242
/*
2343
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
2444
* Do not keep implementation details here, methods should be thin wrappers around methods in other modules.
2545
*/
2646
public class ForgeHooks {
47+
public static int canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) {
48+
Event.Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null, spawnReason);
49+
return res == Event.Result.DEFAULT ? 0 : res == Event.Result.DENY ? -1 : 1;
50+
}
51+
52+
// TODO: onInteractEntityAt
53+
54+
public static ActionResult onInteractEntity(PlayerEntity player, Entity entity, Hand hand) {
55+
return EntityEvents.onInteractEntity(player, entity, hand);
56+
}
57+
58+
public static boolean onLivingDeath(LivingEntity entity, DamageSource src) {
59+
return EntityEvents.onLivingDeath(entity, src);
60+
}
61+
62+
public static boolean onLivingUpdate(LivingEntity entity) {
63+
return EntityEvents.onLivingUpdateEvent(entity);
64+
}
65+
66+
// TODO: forge calls the equivilant to this in LivingEntity, but patchwork only calls the equivilant to onPlayerAttack
67+
public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float amount) {
68+
return entity instanceof PlayerEntity || onPlayerAttack(entity, src, amount);
69+
}
70+
71+
public static boolean onPlayerAttack(LivingEntity entity, DamageSource src, float amount) {
72+
return !EntityEvents.onLivingAttack(entity, src, amount);
73+
}
74+
75+
// optifine wants this? O.o
76+
public static void onLivingSetAttackTarget(LivingEntity entity, LivingEntity target) {
77+
EntityEvents.onLivingSetAttackTarget(entity, target);
78+
}
79+
80+
public static float onLivingHurt(LivingEntity entity, DamageSource src, float amount) {
81+
return EntityEvents.onLivingHurt(entity, src, amount);
82+
}
83+
84+
@Nullable
85+
public static float[] onLivingFall(LivingEntity entity, float distance, float damageMultiplier) {
86+
return EntityEvents.onLivingFall(entity, distance, damageMultiplier);
87+
}
88+
89+
public static float onLivingDamage(LivingEntity entity, DamageSource src, float amount) {
90+
return EntityEvents.onLivingDamage(entity, src, amount);
91+
}
92+
93+
public static boolean onLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) {
94+
return EntityEvents.onLivingDrops(entity, source, drops, lootingLevel, recentlyHit);
95+
}
96+
97+
public static boolean onPlayerAttackTarget(PlayerEntity player, Entity target) {
98+
return EntityEvents.attackEntity(player, target);
99+
}
27100
}

patchwork-god-classes/src/main/java/net/minecraftforge/event/ForgeEventFactory.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,35 @@
1919

2020
package net.minecraftforge.event;
2121

22+
import net.minecraftforge.eventbus.api.Event;
23+
24+
import net.minecraft.entity.SpawnType;
25+
import net.minecraft.entity.mob.MobEntity;
26+
import net.minecraft.entity.player.PlayerEntity;
27+
import net.minecraft.world.IWorld;
28+
import net.minecraft.world.MobSpawnerLogic;
29+
import net.minecraft.world.World;
30+
31+
import net.patchworkmc.impl.event.entity.EntityEvents;
32+
2233
/*
2334
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
2435
* Do not keep implementation details here, methods should be thin wrappers around methods in other modules.
2536
*/
2637
public class ForgeEventFactory {
38+
public static Event.Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) {
39+
return EntityEvents.canEntitySpawn(entity, world, x, y, z, spawner, spawnReason);
40+
}
41+
42+
public static boolean canEntitySpawnSpawner(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner) {
43+
return EntityEvents.canEntitySpawnFromSpawner(entity, world, x, y, z, spawner);
44+
}
45+
46+
public static void onPlayerFall(PlayerEntity player, float distance, float multiplier) {
47+
EntityEvents.onFlyablePlayerFall(player, distance, multiplier);
48+
}
49+
50+
public static boolean doSpecialSpawn(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner, SpawnType spawnReason) {
51+
return EntityEvents.doSpecialSpawn(entity, world, x, y, z, spawner, spawnReason);
52+
}
2753
}

patchwork-god-classes/src/main/java/net/minecraftforge/fml/hooks/BasicEventHooks.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@
2424
import net.minecraft.entity.player.PlayerEntity;
2525
import net.minecraft.world.World;
2626

27+
import net.patchworkmc.impl.event.entity.EntityEvents;
2728
import net.patchworkmc.impl.event.lifecycle.LifecycleEvents;
2829

2930
/*
3031
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
3132
* Do not keep implementation details here, methods should be thin wrappers around methods in other modules.
3233
*/
3334
public class BasicEventHooks {
35+
public static void firePlayerLoggedIn(PlayerEntity player) {
36+
EntityEvents.onPlayerLoggedIn(player);
37+
}
38+
3439
public static void onPlayerPreTick(PlayerEntity player) {
3540
LifecycleEvents.firePlayerTickEvent(TickEvent.Phase.START, player);
3641
}

0 commit comments

Comments
 (0)