39 lines
1.1 KiB
Java
39 lines
1.1 KiB
Java
package com.thebrokenrail.twine.util;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.sound.SoundEvent;
|
|
|
|
public class BoatInventory extends ItemInventory {
|
|
private final Entity entity;
|
|
|
|
private final SoundEvent openSound;
|
|
private final SoundEvent closeSound;
|
|
|
|
public BoatInventory(Entity entity, int size, ItemStack stack, SoundEvent openSound, SoundEvent closeSound) {
|
|
super(size, stack);
|
|
this.entity = entity;
|
|
this.openSound = openSound;
|
|
this.closeSound = closeSound;
|
|
}
|
|
|
|
@Override
|
|
public boolean canPlayerUse(PlayerEntity player) {
|
|
return BoatUtil.canReachEntity(player, entity) && entity.isAlive() && ((BoatUtil) entity).getChestMode().hasItems();
|
|
}
|
|
|
|
@Override
|
|
public void onOpen(PlayerEntity player) {
|
|
if (openSound != null) {
|
|
BoatUtil.playSound(entity, openSound);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onClose(PlayerEntity player) {
|
|
if (closeSound != null) {
|
|
BoatUtil.playSound(entity, closeSound);
|
|
}
|
|
}
|
|
} |