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

Commit de46403

Browse files
committed
Misc fixups to entity events, add a missing patch to EntityType
1 parent 31262e4 commit de46403

4 files changed

Lines changed: 151 additions & 113 deletions

File tree

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
/*
2-
* Minecraft Forge, Patchwork Project
3-
* Copyright (c) 2016-2019, 2019
4-
*
5-
* This library is free software; you can redistribute it and/or
6-
* modify it under the terms of the GNU Lesser General Public
7-
* License as published by the Free Software Foundation version 2.1
8-
* of the License.
9-
*
10-
* This library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
* Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public
16-
* License along with this library; if not, write to the Free Software
17-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
19-
20-
package com.patchworkmc.mixin.event.entity;
21-
22-
import org.spongepowered.asm.mixin.Mixin;
23-
import org.spongepowered.asm.mixin.injection.At;
24-
import org.spongepowered.asm.mixin.injection.Inject;
25-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
26-
27-
import net.minecraft.client.network.ClientPlayerEntity;
28-
import net.minecraft.entity.LivingEntity;
29-
import net.minecraft.entity.damage.DamageSource;
30-
31-
import com.patchworkmc.impl.event.entity.EntityEvents;
32-
33-
@Mixin(ClientPlayerEntity.class)
34-
public class MixinClientPlayerEntity {
35-
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
36-
private void hookDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> callback) {
37-
LivingEntity entity = (LivingEntity) (Object) this;
38-
39-
if (EntityEvents.onLivingAttack(entity, source, amount)) {
40-
callback.setReturnValue(false);
41-
}
42-
}
43-
}
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2019, 2019
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.mixin.event.entity;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.injection.At;
24+
import org.spongepowered.asm.mixin.injection.Inject;
25+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
26+
27+
import net.minecraft.client.network.ClientPlayerEntity;
28+
import net.minecraft.entity.LivingEntity;
29+
import net.minecraft.entity.damage.DamageSource;
30+
31+
import com.patchworkmc.impl.event.entity.EntityEvents;
32+
33+
@Mixin(ClientPlayerEntity.class)
34+
public class MixinClientPlayerEntity {
35+
@Inject(method = "damage", at = @At("HEAD"))
36+
private void hookDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> callback) {
37+
LivingEntity entity = (LivingEntity) (Object) this;
38+
39+
EntityEvents.onLivingAttack(entity, source, amount);
40+
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.patchworkmc.mixin.event.entity;
2+
3+
import javax.annotation.Nullable;
4+
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
9+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
10+
11+
import net.minecraft.entity.Entity;
12+
import net.minecraft.entity.EntityType;
13+
import net.minecraft.entity.SpawnType;
14+
import net.minecraft.entity.mob.MobEntity;
15+
import net.minecraft.entity.player.PlayerEntity;
16+
import net.minecraft.nbt.CompoundTag;
17+
import net.minecraft.text.Text;
18+
import net.minecraft.util.math.BlockPos;
19+
import net.minecraft.world.World;
20+
21+
import com.patchworkmc.impl.event.entity.EntityEvents;
22+
23+
@Mixin(EntityType.class)
24+
public class MixinEntityType {
25+
private static final String SPAWN = "spawn(Lnet/minecraft/world/World;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/text/Text;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnType;ZZ)Lnet/minecraft/entity/Entity;";
26+
27+
@Inject(method = SPAWN, at = @At(value = "INVOKE", target = "net/minecraft/world/World.spawnEntity(Lnet/minecraft/entity/Entity;)Z"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
28+
private void hookMobSpawns(World world, @Nullable CompoundTag itemTag, @Nullable Text name, @Nullable PlayerEntity player, BlockPos pos, SpawnType type, boolean alignPosition, boolean bl, CallbackInfoReturnable<Entity> callback, Entity entity) {
29+
if (!(entity instanceof MobEntity)) {
30+
return;
31+
}
32+
33+
MobEntity mob = (MobEntity) entity;
34+
35+
if (EntityEvents.doSpecialSpawn(mob, world, pos.getX(), pos.getY(), pos.getZ(), null, type)) {
36+
callback.setReturnValue(null);
37+
}
38+
}
39+
}
Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
/*
2-
* Minecraft Forge, Patchwork Project
3-
* Copyright (c) 2016-2019, 2019
4-
*
5-
* This library is free software; you can redistribute it and/or
6-
* modify it under the terms of the GNU Lesser General Public
7-
* License as published by the Free Software Foundation version 2.1
8-
* of the License.
9-
*
10-
* This library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
* Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public
16-
* License along with this library; if not, write to the Free Software
17-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
19-
20-
package net.minecraftforge.event.entity.living;
21-
22-
import net.minecraft.entity.LivingEntity;
23-
import net.minecraft.entity.damage.DamageSource;
24-
25-
/**
26-
* LivingAttackEvent is fired when a living Entity is attacked.
27-
*
28-
* <p>This event is fired whenever a {@link LivingEntity} is attacked in
29-
* {@link LivingEntity#damage(DamageSource, float)} and
30-
* {@link net.minecraft.entity.player.PlayerEntity#damage(DamageSource, float)}.</p>
31-
*
32-
* <p>This event is fired via the {@link com.patchworkmc.impl.event.entity.EntityEvents#onLivingAttack(EntityLivingBase, DamageSource, float)}.</p>
33-
*
34-
* <p>{@link #source} contains the {@link DamageSource} of the attack.
35-
* {@link #amount} contains the amount of damage dealt to the entity.</p>
36-
*
37-
* <p>This event is cancellable.
38-
* If this event is canceled, the {@link LivingEntity} does not take attack damage.</p>
39-
*
40-
* <p>This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.</p>
41-
*/
42-
public class LivingAttackEvent extends LivingEvent {
43-
private final DamageSource source;
44-
private final float damage;
45-
46-
public LivingAttackEvent() {
47-
this.source = null;
48-
this.damage = 0f;
49-
}
50-
51-
public LivingAttackEvent(LivingEntity entity, DamageSource source, float damage) {
52-
super(entity);
53-
this.source = source;
54-
this.damage = damage;
55-
}
56-
57-
public DamageSource getSource() {
58-
return source;
59-
}
60-
61-
public float getAmount() {
62-
return damage;
63-
}
64-
65-
@Override
66-
public boolean isCancelable() {
67-
return true;
68-
}
69-
}
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2019, 2019
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.minecraftforge.event.entity.living;
21+
22+
import net.minecraft.entity.LivingEntity;
23+
import net.minecraft.entity.damage.DamageSource;
24+
25+
/**
26+
* LivingAttackEvent is fired when a {@link LivingEntity} is attacked.
27+
*
28+
* <p>This event is fired whenever a {@link LivingEntity} is attacked in
29+
* {@link LivingEntity#damage(DamageSource, float)} and
30+
* {@link net.minecraft.entity.player.PlayerEntity#damage(DamageSource, float)}.</p>
31+
*
32+
* <p>This event is fired via {@link com.patchworkmc.impl.event.entity.EntityEvents#onLivingAttack(LivingEntity, DamageSource, float)}.</p>
33+
*
34+
* <p>{@link #source} contains the {@link DamageSource} of the attack.
35+
* {@link #damage} contains the amount of damage dealt to the entity.</p>
36+
*
37+
* <p>This event is cancellable.
38+
* If this event is canceled, the {@link LivingEntity} does not take attack damage.</p>
39+
*
40+
* <p>This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.</p>
41+
*/
42+
public class LivingAttackEvent extends LivingEvent {
43+
private final DamageSource source;
44+
private final float damage;
45+
46+
public LivingAttackEvent() {
47+
this.source = null;
48+
this.damage = 0f;
49+
}
50+
51+
public LivingAttackEvent(LivingEntity entity, DamageSource source, float damage) {
52+
super(entity);
53+
this.source = source;
54+
this.damage = damage;
55+
}
56+
57+
public DamageSource getSource() {
58+
return source;
59+
}
60+
61+
public float getAmount() {
62+
return damage;
63+
}
64+
65+
@Override
66+
public boolean isCancelable() {
67+
return true;
68+
}
69+
}

patchwork-events-entity/src/main/resources/patchwork-events-entity.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"package": "com.patchworkmc.mixin.event.entity",
44
"compatibilityLevel": "JAVA_8",
55
"mixins": [
6+
"MixinEntityType",
67
"MixinLivingEntity",
8+
"MixinMobSpawnerLogic",
79
"MixinPlayerEntity",
810
"MixinPlayerManager",
911
"MixinServerPlayerEntity",
1012
"MixinServerWorld",
11-
"MixinMobSpawnerLogic",
1213
"MixinSpawnHelper"
1314
],
1415
"client": [

0 commit comments

Comments
 (0)