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

Commit 51baa33

Browse files
committed
Dispatch from patchwork-god-classes to EntityEvents
1 parent 67053d8 commit 51baa33

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
@@ -56,7 +56,6 @@
5656
import net.minecraft.entity.mob.MobEntity;
5757
import net.minecraft.entity.player.PlayerEntity;
5858
import net.minecraft.item.ItemStack;
59-
import net.minecraft.server.network.ServerPlayerEntity;
6059
import net.minecraft.text.Text;
6160
import net.minecraft.util.ActionResult;
6261
import net.minecraft.util.Hand;
@@ -100,7 +99,7 @@ public static void onEnteringChunk(Entity entity, int newChunkX, int newChunkZ,
10099
}
101100

102101
// PlayerEvents
103-
public static void onPlayerLoggedIn(ServerPlayerEntity playerEntity) {
102+
public static void onPlayerLoggedIn(PlayerEntity playerEntity) {
104103
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedInEvent(playerEntity));
105104
}
106105

patchwork-god-classes/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ version = getSubprojectVersion(project, "0.1.0")
44
dependencies {
55
compile project(path: ':patchwork-fml', configuration: 'dev')
66
compile project(path: ':patchwork-capabilities', configuration: 'dev')
7+
compile project(path: ':patchwork-events-entity', configuration: 'dev')
78
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
89
}

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@
2323

2424
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
2525
import net.minecraftforge.common.capabilities.ICapabilityProvider;
26+
import net.minecraftforge.eventbus.api.Event;
27+
28+
import net.minecraft.entity.SpawnType;
29+
import net.minecraft.entity.mob.MobEntity;
30+
import net.minecraft.entity.player.PlayerEntity;
31+
import net.minecraft.world.IWorld;
32+
import net.minecraft.world.MobSpawnerLogic;
33+
import net.minecraft.world.World;
2634

2735
import net.patchworkmc.impl.capability.CapabilityEvents;
36+
import net.patchworkmc.impl.event.entity.EntityEvents;
2837

2938
/*
3039
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
@@ -40,4 +49,20 @@ public static <T> CapabilityDispatcher gatherCapabilities(Class<? extends T> typ
4049
public static <T> CapabilityDispatcher gatherCapabilities(Class<? extends T> type, T provider, @Nullable ICapabilityProvider parent) {
4150
return CapabilityEvents.gatherCapabilities(type, provider, parent);
4251
}
52+
53+
public static Event.Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) {
54+
return EntityEvents.canEntitySpawn(entity, world, x, y, z, spawner, spawnReason);
55+
}
56+
57+
public static boolean canEntitySpawnSpawner(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner) {
58+
return EntityEvents.canEntitySpawnFromSpawner(entity, world, x, y, z, spawner);
59+
}
60+
61+
public static void onPlayerFall(PlayerEntity player, float distance, float multiplier) {
62+
EntityEvents.onFlyablePlayerFall(player, distance, multiplier);
63+
}
64+
65+
public static boolean doSpecialSpawn(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner, SpawnType spawnReason) {
66+
return EntityEvents.doSpecialSpawn(entity, world, x, y, z, spawner, spawnReason);
67+
}
4368
}

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)