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

Commit

Permalink
Dispatch from patchwork-god-classes to EntityEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
kitlith committed Jul 19, 2020
1 parent 67053d8 commit 51baa33
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
Expand Down Expand Up @@ -100,7 +99,7 @@ public static void onEnteringChunk(Entity entity, int newChunkX, int newChunkZ,
}

// PlayerEvents
public static void onPlayerLoggedIn(ServerPlayerEntity playerEntity) {
public static void onPlayerLoggedIn(PlayerEntity playerEntity) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedInEvent(playerEntity));
}

Expand Down
1 change: 1 addition & 0 deletions patchwork-god-classes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ version = getSubprojectVersion(project, "0.1.0")
dependencies {
compile project(path: ':patchwork-fml', configuration: 'dev')
compile project(path: ':patchwork-capabilities', configuration: 'dev')
compile project(path: ':patchwork-events-entity', configuration: 'dev')
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,83 @@

package net.minecraftforge.common;

import java.util.Collection;

import javax.annotation.Nullable;

import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.eventbus.api.Event;

import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.IWorld;
import net.minecraft.world.MobSpawnerLogic;

import net.patchworkmc.impl.event.entity.EntityEvents;

/*
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
* Do not keep implementation details here, methods should be thin wrappers around methods in other modules.
*/
public class ForgeHooks {
public static int canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) {
Event.Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null, spawnReason);
return res == Event.Result.DEFAULT ? 0 : res == Event.Result.DENY ? -1 : 1;
}

// TODO: onInteractEntityAt

public static ActionResult onInteractEntity(PlayerEntity player, Entity entity, Hand hand) {
return EntityEvents.onInteractEntity(player, entity, hand);
}

public static boolean onLivingDeath(LivingEntity entity, DamageSource src) {
return EntityEvents.onLivingDeath(entity, src);
}

public static boolean onLivingUpdate(LivingEntity entity) {
return EntityEvents.onLivingUpdateEvent(entity);
}

// TODO: forge calls the equivilant to this in LivingEntity, but patchwork only calls the equivilant to onPlayerAttack
public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float amount) {
return entity instanceof PlayerEntity || onPlayerAttack(entity, src, amount);
}

public static boolean onPlayerAttack(LivingEntity entity, DamageSource src, float amount) {
return !EntityEvents.onLivingAttack(entity, src, amount);
}

// optifine wants this? O.o
public static void onLivingSetAttackTarget(LivingEntity entity, LivingEntity target) {
EntityEvents.onLivingSetAttackTarget(entity, target);
}

public static float onLivingHurt(LivingEntity entity, DamageSource src, float amount) {
return EntityEvents.onLivingHurt(entity, src, amount);
}

@Nullable
public static float[] onLivingFall(LivingEntity entity, float distance, float damageMultiplier) {
return EntityEvents.onLivingFall(entity, distance, damageMultiplier);
}

public static float onLivingDamage(LivingEntity entity, DamageSource src, float amount) {
return EntityEvents.onLivingDamage(entity, src, amount);
}

public static boolean onLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) {
return EntityEvents.onLivingDrops(entity, source, drops, lootingLevel, recentlyHit);
}

public static boolean onPlayerAttackTarget(PlayerEntity player, Entity target) {
return EntityEvents.attackEntity(player, target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@

import net.minecraftforge.common.capabilities.CapabilityDispatcher;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.eventbus.api.Event;

import net.minecraft.entity.SpawnType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.IWorld;
import net.minecraft.world.MobSpawnerLogic;
import net.minecraft.world.World;

import net.patchworkmc.impl.capability.CapabilityEvents;
import net.patchworkmc.impl.event.entity.EntityEvents;

/*
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
Expand All @@ -40,4 +49,20 @@ public static <T> CapabilityDispatcher gatherCapabilities(Class<? extends T> typ
public static <T> CapabilityDispatcher gatherCapabilities(Class<? extends T> type, T provider, @Nullable ICapabilityProvider parent) {
return CapabilityEvents.gatherCapabilities(type, provider, parent);
}

public static Event.Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) {
return EntityEvents.canEntitySpawn(entity, world, x, y, z, spawner, spawnReason);
}

public static boolean canEntitySpawnSpawner(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner) {
return EntityEvents.canEntitySpawnFromSpawner(entity, world, x, y, z, spawner);
}

public static void onPlayerFall(PlayerEntity player, float distance, float multiplier) {
EntityEvents.onFlyablePlayerFall(player, distance, multiplier);
}

public static boolean doSpecialSpawn(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner, SpawnType spawnReason) {
return EntityEvents.doSpecialSpawn(entity, world, x, y, z, spawner, spawnReason);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

import net.patchworkmc.impl.event.entity.EntityEvents;
import net.patchworkmc.impl.event.lifecycle.LifecycleEvents;

/*
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
* Do not keep implementation details here, methods should be thin wrappers around methods in other modules.
*/
public class BasicEventHooks {
public static void firePlayerLoggedIn(PlayerEntity player) {
EntityEvents.onPlayerLoggedIn(player);
}

public static void onPlayerPreTick(PlayerEntity player) {
LifecycleEvents.firePlayerTickEvent(TickEvent.Phase.START, player);
}
Expand Down

0 comments on commit 51baa33

Please sign in to comment.