Skip to content

Commit

Permalink
rebase to 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
danorris709 committed Sep 21, 2023
1 parent 516b35c commit 83bd5a9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions patches/minecraft/net/minecraft/world/entity/Entity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@
}

public void moveRelative(float p_19921_, Vec3 p_19922_) {
@@ -1450,7 +_,8 @@
}

public void push(double p_20286_, double p_20287_, double p_20288_) {
- this.setDeltaMovement(this.getDeltaMovement().add(p_20286_, p_20287_, p_20288_));
+ var motion = net.minecraftforge.common.ForgeHooks.onPush(this, p_20286_, p_20287_, p_20288_);
+ this.setDeltaMovement(this.getDeltaMovement().add(motion.x(), motion.y(), motion.z()));
this.hasImpulse = true;
}

@@ -1630,6 +_,8 @@
p_20241_.putBoolean("HasVisualFire", this.hasVisualFire);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@
if (!blockstate.isSolid() && !DiodeBlock.isDiode(blockstate)) {
return false;
}
@@ -170,6 +_,10 @@
}

public void push(double p_31744_, double p_31745_, double p_31746_) {
+ var motion = net.minecraftforge.common.ForgeHooks.onPush(this, p_31744_, p_31745_, p_31746_);
+ p_31744_ = motion.x();
+ p_31745_ = motion.y();
+ p_31746_ = motion.z();
if (!this.level().isClientSide && !this.isRemoved() && p_31744_ * p_31744_ + p_31745_ * p_31745_ + p_31746_ * p_31746_ > 0.0D) {
this.kill();
this.dropItem((Entity)null);
8 changes: 8 additions & 0 deletions src/main/java/net/minecraftforge/common/ForgeHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import net.minecraftforge.event.VanillaGameEvent;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.event.entity.EntityAttributeModificationEvent;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.EnderManAngerEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
Expand Down Expand Up @@ -331,6 +332,13 @@ public static void onLivingJump(LivingEntity entity) {
MinecraftForge.EVENT_BUS.post(new LivingJumpEvent(entity));
}

public static Vec3 onPush(Entity entity, double motionX, double motionY, double motionZ)
{
var event = new EntityEvent.Push(entity, motionX, motionY, motionZ);
MinecraftForge.EVENT_BUS.post(event);
return event.getMotion();
}

@SuppressWarnings("resource")
@Nullable
public static ItemEntity onPlayerTossEvent(@NotNull Player player, @NotNull ItemStack item, boolean includeName) {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/net/minecraftforge/event/entity/EntityEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import net.minecraft.core.SectionPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Event;

Expand Down Expand Up @@ -108,4 +109,36 @@ public boolean didChunkChange() {
return SectionPos.x(packedOldPos) != SectionPos.x(packedNewPos) || SectionPos.z(packedOldPos) != SectionPos.z(packedNewPos);
}
}

/**
* This event is fired whenever {@link Entity#push(double, double, double)} gets called.<br>
* You can use this to modify the push motion. <br>
* Setting the motion on all axies to 0 is equivalent to cancelling the push altogether
* <br>
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Push extends EntityEvent
{
private Vec3 motion;

public Push(Entity entity, double motionX, double motionY, double motionZ)
{
super(entity);
this.motion = new Vec3(motionX, motionY, motionZ);
}

public Vec3 getMotion()
{
return this.motion;
}

public void setMotion(Vec3 motion)
{
this.motion = motion;
}
}
}

0 comments on commit 83bd5a9

Please sign in to comment.