-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/wenxin2/marioverse/network/server_bound/data/EntityInteractPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//package com.wenxin2.marioverse.network.server_bound.data; | ||
// | ||
//import com.wenxin2.marioverse.Marioverse; | ||
//import net.minecraft.network.FriendlyByteBuf; | ||
//import net.minecraft.network.codec.ByteBufCodecs; | ||
//import net.minecraft.network.codec.StreamCodec; | ||
//import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
//import net.minecraft.resources.ResourceLocation; | ||
//import net.minecraft.world.entity.Entity; | ||
//import net.minecraft.world.level.Level; | ||
//import net.minecraft.world.phys.Vec3; | ||
//import org.jetbrains.annotations.NotNull; | ||
// | ||
//public record EntityInteractPayload(Entity entity, Boolean isSneaking, Vec3 hitVec) implements CustomPacketPayload { | ||
// public static final Type<EntityInteractPayload> ENTITY_INTERACT_PAYLOAD = new Type<>(ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "entity_interact_payload")); | ||
// | ||
// @NotNull | ||
// @Override | ||
// public Type<EntityInteractPayload> type() { | ||
// return ENTITY_INTERACT_PAYLOAD; | ||
// } | ||
// | ||
// public void getLevel() { | ||
// entity.level(); | ||
// } | ||
// | ||
// public static StreamCodec<FriendlyByteBuf, EntityInteractPayload> createStreamCodec(Level level) { | ||
// return StreamCodec.composite( | ||
// // Codec for Entity (using level) | ||
// StreamCodec.of( | ||
// (buf, entity) -> buf.writeInt(entity.getId()), // Serialize entity ID | ||
// buf -> { | ||
// int entityId = buf.readInt(); | ||
// return level.getEntity(entityId); // Deserialize entity by ID | ||
// } | ||
// ), EntityInteractPayload::entity, | ||
// | ||
// // Codec for Boolean (isSneaking) | ||
// ByteBufCodecs.BOOL, EntityInteractPayload::isSneaking, | ||
// | ||
// // Codec for Vec3 (hitVec) | ||
// StreamCodec.of( | ||
// (buf, vec3) -> { | ||
// buf.writeDouble(vec3.x); | ||
// buf.writeDouble(vec3.y); | ||
// buf.writeDouble(vec3.z); | ||
// }, | ||
// buf -> new Vec3(buf.readDouble(), buf.readDouble(), buf.readDouble()) | ||
// ), EntityInteractPayload::hitVec, | ||
// | ||
// EntityInteractPayload::new | ||
// ); | ||
// } | ||
//} |
100 changes: 100 additions & 0 deletions
100
src/main/java/com/wenxin2/marioverse/network/server_bound/handler/EntityInteractPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//package com.wenxin2.marioverse.network.server_bound.handler; | ||
// | ||
//import com.wenxin2.marioverse.blocks.WarpPipeBlock; | ||
//import com.wenxin2.marioverse.blocks.entities.WarpPipeBlockEntity; | ||
//import com.wenxin2.marioverse.entities.PiranhaPlantEntity; | ||
//import com.wenxin2.marioverse.network.server_bound.data.ClosePipeButtonPayload; | ||
//import com.wenxin2.marioverse.network.server_bound.data.EntityInteractPayload; | ||
//import java.util.Optional; | ||
//import net.minecraft.core.BlockPos; | ||
//import net.minecraft.network.protocol.game.ServerboundInteractPacket; | ||
//import net.minecraft.server.level.ServerLevel; | ||
//import net.minecraft.server.level.ServerPlayer; | ||
//import net.minecraft.world.InteractionHand; | ||
//import net.minecraft.world.InteractionResult; | ||
//import net.minecraft.world.entity.Entity; | ||
//import net.minecraft.world.item.ItemStack; | ||
//import net.minecraft.world.level.Level; | ||
//import net.minecraft.world.level.block.entity.BlockEntity; | ||
//import net.minecraft.world.level.block.state.BlockState; | ||
//import net.neoforged.neoforge.entity.PartEntity; | ||
//import net.neoforged.neoforge.network.handling.IPayloadContext; | ||
//import org.jetbrains.annotations.Nullable; | ||
// | ||
//public class EntityInteractPacket { | ||
// public static final EntityInteractPacket INSTANCE = new EntityInteractPacket(); | ||
// | ||
// public static EntityInteractPacket get() { | ||
// return INSTANCE; | ||
// } | ||
// | ||
// public void handle(final EntityInteractPayload payload, IPayloadContext context) { | ||
// if (context.flow().isServerbound()) { | ||
// final ServerLevel serverWorld = (ServerLevel) context.player().level(); | ||
// | ||
// final Entity entity = payload.entity(); | ||
// | ||
// final double d0 = 36.0D; | ||
// context.enqueueWork(() -> { | ||
// if (entity != null) | ||
// { | ||
// // Convert to the relevant part if found. | ||
// if (entity.isMultipartEntity()) for (final PartEntity<?> p : entity.getParts()) | ||
// if (context.player().distanceToSqr(entity) < d0) | ||
// { | ||
// final InteractionHand hand = context.player().getUsedItemHand(); | ||
// final ItemStack itemstack = context.player().getItemInHand(hand).copy(); | ||
// Optional<InteractionResult> optional = Optional.empty(); | ||
// | ||
// if (this.getAction() == ServerboundInteractPacket.Handler.INTERACT) | ||
// optional = Optional.of(context.player().interactOn(entity, hand)); | ||
// else if (this.getAction() == ServerboundInteractPacket.ActionType.INTERACT_AT) | ||
// { | ||
// if (net.minecraftforge.common.ForgeHooks.onInteractEntityAt(player, entity, this.getHitVec(), | ||
// hand) != null) | ||
// return; | ||
// optional = Optional.of(entity.interactAt(player, this.getHitVec(), hand)); | ||
// } | ||
// else if (this.getAction() == ServerboundInteractPacket.ActionType.ATTACK) context.player().attack(entity); | ||
// | ||
// if (optional.isPresent() && optional.get().consumesAction()) | ||
// { | ||
// CriteriaTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(player, itemstack, entity); | ||
// if (optional.get().shouldSwing()) context.player().swing(hand, true); | ||
// } | ||
// } | ||
// } | ||
// }); | ||
// } | ||
// } | ||
// | ||
// @Nullable | ||
// public Entity getEntityFromWorld(final Level world) { | ||
// return EntityPro.provider.getEntity(world, entityId); | ||
// } | ||
// | ||
// public void changeState(ServerPlayer player, WarpPipeBlockEntity pipeBlockEntity) { | ||
// Level world = pipeBlockEntity.getLevel(); | ||
// if (world == null) | ||
// return; | ||
// BlockPos pos = pipeBlockEntity.getBlockPos(); | ||
// BlockState state = world.getBlockState(pos); | ||
// | ||
// if (!(state.getBlock() instanceof WarpPipeBlock)) | ||
// return; | ||
// | ||
// pipeBlockEntity.closePipe(player); | ||
// } | ||
// | ||
// public static EntityInteractPacket openPipe(BlockPos pos, Boolean closePipe) { | ||
// EntityInteractPacket packet = new EntityInteractPacket(); | ||
// closePipe = false; | ||
// return packet; | ||
// } | ||
// | ||
// public static EntityInteractPacket closePipe(BlockPos pos) { | ||
// EntityInteractPacket packet = new EntityInteractPacket(); | ||
// Boolean closePipe = true; | ||
// return packet; | ||
// } | ||
//} |