Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package net.patchworkmc.impl.event.entity;

import java.util.List;
import java.util.Collection;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.extensions.IForgeItem;
Expand All @@ -28,6 +29,7 @@
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
Expand All @@ -47,13 +49,13 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityPose;
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.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 @@ -97,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 Expand Up @@ -128,6 +130,10 @@ public static float onLivingDamage(LivingEntity entity, DamageSource src, float
return MinecraftForge.EVENT_BUS.post(event) ? 0 : event.getAmount();
}

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

public static float getEyeHeight(Entity entity, EntityPose pose, EntityDimensions size, float defaultHeight) {
EntityEvent.EyeHeight event = new EntityEvent.EyeHeight(entity, pose, size, defaultHeight);
MinecraftForge.EVENT_BUS.post(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import java.util.ArrayList;
import java.util.Collection;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.extensions.IForgeEntity;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
Expand Down Expand Up @@ -154,7 +152,7 @@ private void hookDropForDropsEvent(DamageSource src, CallbackInfo info) {
IForgeEntity forgeEntity = (IForgeEntity) this;
Collection<ItemEntity> drops = forgeEntity.captureDrops(null);

if (!MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(entity, src, drops, dropLootingLevel.get(), playerHitTimer > 0))) {
if (!EntityEvents.onLivingDrops(entity, src, drops, dropLootingLevel.get(), playerHitTimer > 0)) {
for (ItemEntity item : drops) {
forgeEntity.getEntity().world.spawnEntity(item);
}
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