mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-16 12:43:43 +01:00
Add server-side check for extendo-grip and contraption interaction
This commit is contained in:
parent
4a15fbcec3
commit
5c64c2d942
2 changed files with 43 additions and 33 deletions
|
@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs
|
||||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.network.PacketBuffer;
|
import net.minecraft.network.PacketBuffer;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
|
@ -45,22 +46,26 @@ public class ContraptionInteractionPacket extends SimplePacketBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Supplier<Context> context) {
|
public void handle(Supplier<Context> context) {
|
||||||
context.get()
|
context.get().enqueueWork(() -> {
|
||||||
.enqueueWork(() -> {
|
ServerPlayerEntity sender = context.get().getSender();
|
||||||
ServerPlayerEntity sender = context.get()
|
|
||||||
.getSender();
|
|
||||||
if (sender == null)
|
if (sender == null)
|
||||||
return;
|
return;
|
||||||
Entity entityByID = sender.getServerWorld()
|
Entity entityByID = sender.getServerWorld().getEntityByID(target);
|
||||||
.getEntityByID(target);
|
|
||||||
if (!(entityByID instanceof AbstractContraptionEntity))
|
if (!(entityByID instanceof AbstractContraptionEntity))
|
||||||
return;
|
return;
|
||||||
AbstractContraptionEntity contraptionEntity = (AbstractContraptionEntity) entityByID;
|
AbstractContraptionEntity contraptionEntity = (AbstractContraptionEntity) entityByID;
|
||||||
|
double d = sender.getAttribute(PlayerEntity.REACH_DISTANCE).getValue();
|
||||||
|
if (!sender.canEntityBeSeen(entityByID))
|
||||||
|
d -= 3;
|
||||||
|
d *= d;
|
||||||
|
if (sender.getDistanceSq(entityByID) > d) {
|
||||||
|
// TODO log?
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (contraptionEntity.handlePlayerInteraction(sender, localPos, face, interactionHand))
|
if (contraptionEntity.handlePlayerInteraction(sender, localPos, face, interactionHand))
|
||||||
sender.swingHand(interactionHand, true);
|
sender.swingHand(interactionHand, true);
|
||||||
});
|
});
|
||||||
context.get()
|
context.get().setPacketHandled(true);
|
||||||
.setPacketHandled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.function.Supplier;
|
||||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.network.PacketBuffer;
|
import net.minecraft.network.PacketBuffer;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
|
@ -53,15 +54,20 @@ public class ExtendoGripInteractionPacket extends SimplePacketBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Supplier<Context> context) {
|
public void handle(Supplier<Context> context) {
|
||||||
context.get()
|
context.get().enqueueWork(() -> {
|
||||||
.enqueueWork(() -> {
|
ServerPlayerEntity sender = context.get().getSender();
|
||||||
ServerPlayerEntity sender = context.get()
|
|
||||||
.getSender();
|
|
||||||
if (sender == null)
|
if (sender == null)
|
||||||
return;
|
return;
|
||||||
Entity entityByID = sender.getServerWorld()
|
Entity entityByID = sender.getServerWorld().getEntityByID(target);
|
||||||
.getEntityByID(target);
|
|
||||||
if (entityByID != null && ExtendoGripItem.isHoldingExtendoGrip(sender)) {
|
if (entityByID != null && ExtendoGripItem.isHoldingExtendoGrip(sender)) {
|
||||||
|
double d = sender.getAttribute(PlayerEntity.REACH_DISTANCE).getValue();
|
||||||
|
if (!sender.canEntityBeSeen(entityByID))
|
||||||
|
d -= 3;
|
||||||
|
d *= d;
|
||||||
|
if (sender.getDistanceSq(entityByID) > d) {
|
||||||
|
// TODO log?
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (interactionHand == null)
|
if (interactionHand == null)
|
||||||
sender.attackTargetEntityWithCurrentItem(entityByID);
|
sender.attackTargetEntityWithCurrentItem(entityByID);
|
||||||
else if (specificPoint == null)
|
else if (specificPoint == null)
|
||||||
|
@ -70,8 +76,7 @@ public class ExtendoGripInteractionPacket extends SimplePacketBase {
|
||||||
entityByID.applyPlayerInteraction(sender, specificPoint, interactionHand);
|
entityByID.applyPlayerInteraction(sender, specificPoint, interactionHand);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context.get()
|
context.get().setPacketHandled(true);
|
||||||
.setPacketHandled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue