2023-10-31 21:38:28 +01:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2023-11-25 04:05:45 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2023-10-31 21:38:28 +01:00
|
|
|
import com.google.common.base.Suppliers;
|
2023-11-25 04:05:45 +01:00
|
|
|
import com.minelittlepony.unicopia.block.FancyBedBlock;
|
2023-10-31 21:38:28 +01:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockEntityProvider;
|
|
|
|
import net.minecraft.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.item.BedItem;
|
2023-11-25 04:05:45 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NbtCompound;
|
|
|
|
import net.minecraft.nbt.NbtElement;
|
2023-10-31 21:38:28 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
|
|
|
public class FancyBedItem extends BedItem implements Supplier<BlockEntity> {
|
|
|
|
|
|
|
|
private final Supplier<BlockEntity> renderEntity;
|
|
|
|
|
|
|
|
public FancyBedItem(Block block, Settings settings) {
|
|
|
|
super(block, settings);
|
|
|
|
this.renderEntity = Suppliers.memoize(() -> ((BlockEntityProvider)block).createBlockEntity(BlockPos.ORIGIN, block.getDefaultState()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockEntity get() {
|
|
|
|
return renderEntity.get();
|
|
|
|
}
|
2023-11-25 04:05:45 +01:00
|
|
|
|
|
|
|
public static FancyBedBlock.SheetPattern getPattern(ItemStack stack) {
|
|
|
|
@Nullable
|
|
|
|
NbtCompound blockEntityNbt = getBlockEntityNbt(stack);
|
|
|
|
if (blockEntityNbt == null || !blockEntityNbt.contains("pattern", NbtElement.STRING_TYPE)) {
|
|
|
|
return FancyBedBlock.SheetPattern.NONE;
|
|
|
|
}
|
|
|
|
return FancyBedBlock.SheetPattern.byId(blockEntityNbt.getString("pattern"));
|
|
|
|
}
|
2023-10-31 21:38:28 +01:00
|
|
|
}
|