Skip to content

Commit

Permalink
扫帚骑乘修改
Browse files Browse the repository at this point in the history
- 现在扫帚有实体碰撞了
- 女仆和玩家一同坐上时能够打开女仆背包
  • Loading branch information
TartaricAcid committed Aug 27, 2024
1 parent 853e523 commit 87afa11
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
Expand All @@ -30,7 +31,7 @@
import java.util.Optional;
import java.util.UUID;

public class EntityBroom extends AbstractEntityFromItem implements OwnableEntity {
public class EntityBroom extends AbstractEntityFromItem implements OwnableEntity, HasCustomInventoryScreen {
public static final EntityType<EntityBroom> TYPE = EntityType.Builder.<EntityBroom>of(EntityBroom::new, MobCategory.MISC).sized(1.375F, 0.5625F).clientTrackingRange(10).build("broom");

private static final EntityDataAccessor<Optional<UUID>> OWNER_ID = SynchedEntityData.defineId(EntityBroom.class, EntityDataSerializers.OPTIONAL_UUID);
Expand Down Expand Up @@ -217,6 +218,33 @@ public LivingEntity getControllingPassenger() {
return null;
}

@Override
public void openCustomInventoryScreen(Player player) {
if (!(player instanceof ServerPlayer serverPlayer)) {
return;
}
List<Entity> passengers = this.getPassengers();
boolean hasPlayer = false;
EntityMaid maidOpen = null;
for (int i = 0; i < Math.max(passengers.size(), 2); i++) {
Entity entity = passengers.get(i);
if (entity.equals(player)) {
hasPlayer = true;
}
if (entity instanceof EntityMaid maid && maid.isOwnedBy(player)) {
maidOpen = maid;
}
}
if (hasPlayer && maidOpen != null) {
maidOpen.openMaidGui(serverPlayer);
}
}

@Override
public boolean canBeCollidedWith() {
return this.isAlive();
}

@Override
protected boolean canAddPassenger(Entity entity) {
return this.getPassengers().size() < 2;
Expand Down

0 comments on commit 87afa11

Please sign in to comment.