Skip to content
Open
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
2 changes: 0 additions & 2 deletions src/main/java/com/simibubi/create/AllPackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,30 @@
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;
import net.neoforged.api.distmarker.OnlyIn;
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;

Expand All @@ -68,11 +53,14 @@ public class ExtendoGripItem extends Item {

private static final Supplier<Multimap<Holder<Attribute>, 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<Multimap<Holder<Attribute>, 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) {
Expand Down Expand Up @@ -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());
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Loading