Fix Extendo Grip knockback

This commit is contained in:
Snownee 2020-11-11 10:52:57 +08:00
parent 85b3ab2025
commit 466739bcf5
3 changed files with 5 additions and 21 deletions

View File

@ -47,8 +47,6 @@ public class SuperGlueHandler {
if (entity == null || world == null || pos == null) if (entity == null || world == null || pos == null)
return; return;
if (event.isCanceled())
return;
if (world.isRemote()) if (world.isRemote())
return; return;
@ -79,7 +77,7 @@ public class SuperGlueHandler {
new RayTraceContext(start, end, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, placer)); new RayTraceContext(start, end, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, placer));
Direction face = ray.getFace(); Direction face = ray.getFace();
if (ray == null || face == null || ray.getType() == Type.MISS) if (face == null || ray.getType() == Type.MISS)
return; return;
if (!ray.getPos() if (!ray.getPos()

View File

@ -20,16 +20,15 @@ import net.minecraft.entity.projectile.ProjectileHelper;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.Rarity; import net.minecraft.item.Rarity;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult.Type; import net.minecraft.util.math.RayTraceResult.Type;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.InputEvent.ClickInputEvent; import net.minecraftforge.client.event.InputEvent.ClickInputEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.living.LivingKnockBackEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -64,8 +63,6 @@ public class ExtendoGripItem extends Item {
public static void holdingExtendoGripIncreasesRange(LivingUpdateEvent event) { public static void holdingExtendoGripIncreasesRange(LivingUpdateEvent event) {
if (!(event.getEntity() instanceof PlayerEntity)) if (!(event.getEntity() instanceof PlayerEntity))
return; return;
if (event.isCanceled())
return;
PlayerEntity player = (PlayerEntity) event.getEntityLiving(); PlayerEntity player = (PlayerEntity) event.getEntityLiving();
String marker = "createExtendo"; String marker = "createExtendo";
@ -149,23 +146,14 @@ public class ExtendoGripItem extends Item {
} }
@SubscribeEvent @SubscribeEvent
public static void attacksByExtendoGripHaveMoreKnockback(AttackEntityEvent event) { public static void attacksByExtendoGripHaveMoreKnockback(LivingKnockBackEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getAttacker();
if (!(entity instanceof PlayerEntity)) if (!(entity instanceof PlayerEntity))
return; return;
PlayerEntity player = (PlayerEntity) entity; PlayerEntity player = (PlayerEntity) entity;
if (!isHoldingExtendoGrip(player)) if (!isHoldingExtendoGrip(player))
return; return;
Entity target = event.getTarget(); event.setStrength(event.getStrength() + 2);
if (target instanceof ItemFrameEntity || !target.attackEntityFrom(DamageSource.causePlayerDamage(player), 0))
return;
int strength = 2;
float yaw = entity.rotationYaw * ((float) Math.PI / 180F);
if (target instanceof LivingEntity) {
((LivingEntity) target).knockBack(entity, strength, MathHelper.sin(yaw), -MathHelper.cos(yaw));
return;
}
target.addVelocity(-MathHelper.sin(yaw) * strength, 0.1D, MathHelper.cos(yaw) * strength);
} }
private static boolean isUncaughtClientInteraction(Entity entity, Entity target) { private static boolean isUncaughtClientInteraction(Entity entity, Entity target) {

View File

@ -141,8 +141,6 @@ public class ZapperRenderHandler {
ItemStack heldItem = event.getItemStack(); ItemStack heldItem = event.getItemStack();
if (!(heldItem.getItem() instanceof ZapperItem)) if (!(heldItem.getItem() instanceof ZapperItem))
return; return;
if (event.isCanceled())
return;
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
boolean rightHand = event.getHand() == Hand.MAIN_HAND ^ mc.player.getPrimaryHand() == HandSide.LEFT; boolean rightHand = event.getHand() == Hand.MAIN_HAND ^ mc.player.getPrimaryHand() == HandSide.LEFT;