mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-04 06:44:40 +01:00
Double act
- Fixed player interaction able to trigger for multiple contraptions in the raycast
This commit is contained in:
parent
b69ec101a6
commit
f81eae550b
1 changed files with 27 additions and 12 deletions
|
@ -92,6 +92,10 @@ public class ContraptionHandlerClient {
|
|||
Collection<WeakReference<AbstractContraptionEntity>> contraptions =
|
||||
ContraptionHandler.loadedContraptions.get(mc.level)
|
||||
.values();
|
||||
|
||||
double bestDistance = Double.MAX_VALUE;
|
||||
BlockHitResult bestResult = null;
|
||||
AbstractContraptionEntity bestEntity = null;
|
||||
|
||||
for (WeakReference<AbstractContraptionEntity> ref : contraptions) {
|
||||
AbstractContraptionEntity contraptionEntity = ref.get();
|
||||
|
@ -104,20 +108,31 @@ public class ContraptionHandlerClient {
|
|||
BlockHitResult rayTraceResult = rayTraceContraption(origin, target, contraptionEntity);
|
||||
if (rayTraceResult == null)
|
||||
continue;
|
||||
|
||||
InteractionHand hand = event.getHand();
|
||||
Direction face = rayTraceResult.getDirection();
|
||||
BlockPos pos = rayTraceResult.getBlockPos();
|
||||
|
||||
if (contraptionEntity.handlePlayerInteraction(player, pos, face, hand)) {
|
||||
AllPackets.getChannel().sendToServer(new ContraptionInteractionPacket(contraptionEntity, hand, pos, face));
|
||||
} else if (handleSpecialInteractions(contraptionEntity, player, pos, face, hand)) {
|
||||
} else
|
||||
|
||||
double distance = contraptionEntity.toGlobalVector(rayTraceResult.getLocation(), 1).distanceTo(origin);
|
||||
if (distance > bestDistance)
|
||||
continue;
|
||||
|
||||
event.setCanceled(true);
|
||||
event.setSwingHand(false);
|
||||
|
||||
bestResult = rayTraceResult;
|
||||
bestDistance = distance;
|
||||
bestEntity = contraptionEntity;
|
||||
}
|
||||
|
||||
if (bestResult == null)
|
||||
return;
|
||||
|
||||
InteractionHand hand = event.getHand();
|
||||
Direction face = bestResult.getDirection();
|
||||
BlockPos pos = bestResult.getBlockPos();
|
||||
|
||||
if (bestEntity.handlePlayerInteraction(player, pos, face, hand)) {
|
||||
AllPackets.getChannel()
|
||||
.sendToServer(new ContraptionInteractionPacket(bestEntity, hand, pos, face));
|
||||
} else
|
||||
handleSpecialInteractions(bestEntity, player, pos, face, hand);
|
||||
|
||||
event.setCanceled(true);
|
||||
event.setSwingHand(false);
|
||||
}
|
||||
|
||||
private static boolean handleSpecialInteractions(AbstractContraptionEntity contraptionEntity, Player player,
|
||||
|
|
Loading…
Add table
Reference in a new issue