diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index b85d376d3e..243bb91039 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -33,7 +33,6 @@ import com.simibubi.create.content.equipment.bell.SoulPulseEffectPacket; import com.simibubi.create.content.equipment.blueprint.BlueprintAssignCompleteRecipePacket; import com.simibubi.create.content.equipment.clipboard.ClipboardEditPacket; -import com.simibubi.create.content.equipment.extendoGrip.ExtendoGripInteractionPacket; import com.simibubi.create.content.equipment.potatoCannon.PotatoCannonPacket; import com.simibubi.create.content.equipment.symmetryWand.ConfigureSymmetryWandPacket; import com.simibubi.create.content.equipment.symmetryWand.SymmetryEffectPacket; @@ -126,7 +125,6 @@ public enum AllPackets implements BasePacketPayload.PacketTypeProvider { UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket.STREAM_CODEC), CLEAR_CONTAINER(ClearMenuPacket.class, ClearMenuPacket.STREAM_CODEC), CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket.STREAM_CODEC), - EXTENDO_INTERACT(ExtendoGripInteractionPacket.class, ExtendoGripInteractionPacket.STREAM_CODEC), CONTRAPTION_INTERACT(ContraptionInteractionPacket.class, ContraptionInteractionPacket.STREAM_CODEC), CLIENT_MOTION(ClientMotionPacket.class, ClientMotionPacket.STREAM_CODEC), PLACE_ARM(ArmPlacementPacket.class, ArmPlacementPacket.STREAM_CODEC), diff --git a/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripInteractionPacket.java b/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripInteractionPacket.java deleted file mode 100644 index aaa023d4f3..0000000000 --- a/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripInteractionPacket.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.simibubi.create.content.equipment.extendoGrip; - -import com.simibubi.create.AllPackets; -import net.createmod.catnip.net.base.ServerboundPacketPayload; -import net.createmod.catnip.codecs.stream.CatnipStreamCodecBuilders; -import net.createmod.catnip.codecs.stream.CatnipStreamCodecs; -import io.netty.buffer.ByteBuf; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.ai.attributes.Attributes; -import net.minecraft.world.phys.Vec3; - -public record ExtendoGripInteractionPacket(InteractionHand hand, int target, Vec3 point) implements ServerboundPacketPayload { - public static final StreamCodec STREAM_CODEC = StreamCodec.composite( - CatnipStreamCodecBuilders.nullable(CatnipStreamCodecs.HAND), ExtendoGripInteractionPacket::hand, - ByteBufCodecs.INT, ExtendoGripInteractionPacket::target, - CatnipStreamCodecBuilders.nullable(CatnipStreamCodecs.VEC3), ExtendoGripInteractionPacket::point, - ExtendoGripInteractionPacket::new - ); - - public ExtendoGripInteractionPacket(Entity target) { - this(target, null); - } - - public ExtendoGripInteractionPacket(Entity target, InteractionHand hand) { - this(target, hand, null); - } - - public ExtendoGripInteractionPacket(Entity target, InteractionHand hand, Vec3 specificPoint) { - this(hand, target.getId(), specificPoint); - } - - @Override - public PacketTypeProvider getTypeProvider() { - return AllPackets.EXTENDO_INTERACT; - } - - @Override - public void handle(ServerPlayer sender) { - if (sender == null) - return; - Entity entityByID = sender.level() - .getEntity(this.target); - if (entityByID != null && ExtendoGripItem.isHoldingExtendoGrip(sender)) { - double d = sender.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE); - if (!sender.hasLineOfSight(entityByID)) - d -= 3; - d *= d; - if (sender.distanceToSqr(entityByID) > d) - return; - if (this.hand == null) - sender.attack(entityByID); - else if (this.point == null) - sender.interactOn(entityByID, this.hand); - else - entityByID.interactAt(sender, this.point, this.hand); - } - } -} diff --git a/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripItem.java b/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripItem.java index 6d4f8a4949..2ee692bc15 100644 --- a/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripItem.java +++ b/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripItem.java @@ -13,31 +13,19 @@ import com.simibubi.create.foundation.item.render.SimpleCustomRenderer; import com.simibubi.create.infrastructure.config.AllConfigs; -import net.createmod.catnip.animation.AnimationTickHolder; -import net.createmod.catnip.platform.CatnipServices; -import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.Holder; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; -import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.LevelReader; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.HitResult.Type; -import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.event.tick.EntityTickEvent; import net.neoforged.api.distmarker.Dist; @@ -45,13 +33,10 @@ import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; -import net.neoforged.neoforge.client.event.InputEvent; import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; import net.neoforged.neoforge.event.entity.living.LivingIncomingDamageEvent; import net.neoforged.neoforge.event.entity.living.LivingKnockBackEvent; -import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; import net.neoforged.neoforge.event.entity.player.PlayerEvent; -import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import net.neoforged.neoforge.event.level.BlockEvent.BreakEvent; import net.neoforged.neoforge.event.level.BlockEvent.EntityPlaceEvent; @@ -68,11 +53,14 @@ public class ExtendoGripItem extends Item { private static final Supplier, AttributeModifier>> rangeModifier = Suppliers.memoize(() -> // Holding an ExtendoGrip - ImmutableMultimap.of(Attributes.BLOCK_INTERACTION_RANGE, singleRangeAttributeModifier)); + ImmutableMultimap.of( + Attributes.BLOCK_INTERACTION_RANGE, singleRangeAttributeModifier, + Attributes.ENTITY_INTERACTION_RANGE, singleRangeAttributeModifier)); private static final Supplier, AttributeModifier>> doubleRangeModifier = Suppliers.memoize(() -> // Holding two ExtendoGrips o.O - ImmutableMultimap.of(Attributes.BLOCK_INTERACTION_RANGE, doubleRangeAttributeModifier)); - + ImmutableMultimap.of( + Attributes.BLOCK_INTERACTION_RANGE, doubleRangeAttributeModifier, + Attributes.ENTITY_INTERACTION_RANGE, doubleRangeAttributeModifier)); private static DamageSource lastActiveDamageSource; public ExtendoGripItem(Properties properties) { @@ -137,44 +125,6 @@ else if (persistentData.contains(EXTENDO_MARKER)) .addTransientAttributeModifiers(rangeModifier.get()); } - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public static void dontMissEntitiesWhenYouHaveHighReachDistance(InputEvent.InteractionKeyMappingTriggered event) { - Minecraft mc = Minecraft.getInstance(); - LocalPlayer player = mc.player; - if (mc.level == null || player == null) - return; - if (!isHoldingExtendoGrip(player)) - return; - if (mc.hitResult instanceof BlockHitResult && mc.hitResult.getType() != Type.MISS) - return; - - // Modified version of GameRenderer#getMouseOver - double d0 = player.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE); - if (!player.isCreative()) - d0 -= 0.5f; - Vec3 Vector3d = player.getEyePosition(AnimationTickHolder.getPartialTicks()); - Vec3 Vector3d1 = player.getViewVector(1.0F); - Vec3 Vector3d2 = Vector3d.add(Vector3d1.x * d0, Vector3d1.y * d0, Vector3d1.z * d0); - AABB AABB = player.getBoundingBox() - .expandTowards(Vector3d1.scale(d0)) - .inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityraytraceresult = - ProjectileUtil.getEntityHitResult(player, Vector3d, Vector3d2, AABB, (e) -> { - return !e.isSpectator() && e.isPickable(); - }, d0 * d0); - if (entityraytraceresult != null) { - Entity entity1 = entityraytraceresult.getEntity(); - Vec3 Vector3d3 = entityraytraceresult.getLocation(); - double d2 = Vector3d.distanceToSqr(Vector3d3); - if (d2 < d0 * d0 || mc.hitResult == null || mc.hitResult.getType() == Type.MISS) { - mc.hitResult = entityraytraceresult; - if (entity1 instanceof LivingEntity || entity1 instanceof ItemFrame) - mc.crosshairPickEntity = entity1; - } - } - } - @SubscribeEvent(priority = EventPriority.LOWEST) public static void consumeDurabilityOnBlockBreak(BreakEvent event) { findAndDamageExtendoGrip(event.getPlayer()); @@ -187,11 +137,6 @@ public static void consumeDurabilityOnPlace(EntityPlaceEvent event) { findAndDamageExtendoGrip((Player) entity); } -// @SubscribeEvent(priority = EventPriority.LOWEST) -// public static void consumeDurabilityOnPlace(PlayerInteractEvent event) { -// findAndDamageExtendoGrip(event.getPlayer()); -// } - private static void findAndDamageExtendoGrip(Player player) { if (player == null) return; @@ -259,52 +204,6 @@ public static void attacksByExtendoGripHaveMoreKnockback(LivingKnockBackEvent ev event.setStrength(event.getStrength() + 2); } - private static boolean isUncaughtClientInteraction(Entity entity, Entity target) { - // Server ignores entity interaction further than 6m - if (entity.distanceToSqr(target) < 36) - return false; - if (!entity.level().isClientSide) - return false; - if (!(entity instanceof Player)) - return false; - return true; - } - - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public static void notifyServerOfLongRangeAttacks(AttackEntityEvent event) { - Entity entity = event.getEntity(); - Entity target = event.getTarget(); - if (!isUncaughtClientInteraction(entity, target)) - return; - Player player = (Player) entity; - if (isHoldingExtendoGrip(player)) - CatnipServices.NETWORK.sendToServer(new ExtendoGripInteractionPacket(target)); - } - - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public static void notifyServerOfLongRangeInteractions(PlayerInteractEvent.EntityInteract event) { - Entity entity = event.getEntity(); - Entity target = event.getTarget(); - if (!isUncaughtClientInteraction(entity, target)) - return; - Player player = (Player) entity; - if (isHoldingExtendoGrip(player)) - CatnipServices.NETWORK.sendToServer(new ExtendoGripInteractionPacket(target, event.getHand())); - } - - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public static void notifyServerOfLongRangeSpecificInteractions(PlayerInteractEvent.EntityInteractSpecific event) { - Player entity = event.getEntity(); - Entity target = event.getTarget(); - if (!isUncaughtClientInteraction(entity, target)) - return; - if (isHoldingExtendoGrip(entity)) - CatnipServices.NETWORK.sendToServer(new ExtendoGripInteractionPacket(target, event.getHand(), event.getLocalPos())); - } - public static boolean isHoldingExtendoGrip(Player player) { boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getOffhandItem()); boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getMainHandItem());