Skip to content

Commit

Permalink
Fix leashing part
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Jan 18, 2025
1 parent cb886df commit bf6c994
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.Leashable;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
Expand All @@ -24,10 +25,11 @@
import net.neoforged.neoforge.entity.PartEntity;
import org.jetbrains.annotations.NotNull;

public class PiranhaPlantPart extends PartEntity<PiranhaPlantEntity> {
public class PiranhaPlantPart extends PartEntity<PiranhaPlantEntity> implements Leashable {
public final PiranhaPlantEntity parentMob;
public final String name;
private final EntityDimensions size;
private Leashable.LeashData leashData;

public PiranhaPlantPart(PiranhaPlantEntity parentMob, String name, float width, float height) {
super(parentMob);
Expand All @@ -41,10 +43,14 @@ public PiranhaPlantPart(PiranhaPlantEntity parentMob, String name, float width,
protected void defineSynchedData(SynchedEntityData.Builder builder) {}

@Override
public void readAdditionalSaveData(CompoundTag tag) {}
public void readAdditionalSaveData(CompoundTag tag) {
this.leashData = this.readLeashData(tag);
}

@Override
public void addAdditionalSaveData(CompoundTag tag) {}
public void addAdditionalSaveData(CompoundTag tag) {
this.writeLeashData(tag, this.leashData);
}

@Override
public boolean isPickable() {
Expand Down Expand Up @@ -126,6 +132,22 @@ public boolean canRiderInteract() {
return this.getParent().canRiderInteract();
}

@Nullable
@Override
public LeashData getLeashData() {
return this.leashData;
}

@Override
public void setLeashData(@Nullable Leashable.LeashData leashData) {
this.leashData = leashData;
}

@Override
public boolean canBeLeashed() {
return true;
}

@Override
public boolean canCollideWith(final Entity entity) {
return !this.isPassengerOfSameVehicle(entity);
Expand Down
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
// );
// }
//}
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;
// }
//}

0 comments on commit bf6c994

Please sign in to comment.