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

Commit 6f8800d

Browse files
committed
Dispatch from patchwork-god-classes to EntityEvents
1 parent f62f7d4 commit 6f8800d

File tree

5 files changed

+107
-2
lines changed

5 files changed

+107
-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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,83 @@
1919

2020
package net.minecraftforge.common;
2121

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

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)