Search in sources :

Example 1 with ItemRecord

use of net.minecraft.item.ItemRecord in project SpongeCommon by SpongePowered.

the class MixinTileEntityJukebox method insertRecord.

@Override
public void insertRecord(ItemStack record) {
    net.minecraft.item.ItemStack itemStack = (net.minecraft.item.ItemStack) checkNotNull(record, "record");
    if (!(itemStack.getItem() instanceof ItemRecord)) {
        return;
    }
    IBlockState block = this.world.getBlockState(this.pos);
    if (block.getBlock() == Blocks.JUKEBOX) {
        // Don't use BlockJukebox#insertRecord - it looses item data
        this.setRecord(itemStack);
        this.world.setBlockState(this.pos, block.withProperty(BlockJukebox.HAS_RECORD, true), 2);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ItemRecord(net.minecraft.item.ItemRecord) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 2 with ItemRecord

use of net.minecraft.item.ItemRecord in project SpongeCommon by SpongePowered.

the class JukeboxDataProcessor method set.

@Override
protected boolean set(BlockJukebox.TileEntityJukebox jukebox, ItemStackSnapshot stackSnapshot) {
    IBlockState block = jukebox.getWorld().getBlockState(jukebox.getPos());
    if (stackSnapshot == ItemStackSnapshot.NONE) {
        if (jukebox.getRecord() == null) {
            return true;
        }
        return remove(jukebox);
    }
    if (!(stackSnapshot.getType() instanceof ItemRecord)) {
        return false;
    }
    ((Jukebox) jukebox).insertRecord(stackSnapshot.createStack());
    block = jukebox.getWorld().getBlockState(jukebox.getPos());
    return block.getBlock() instanceof BlockJukebox && block.getValue(BlockJukebox.HAS_RECORD);
}
Also used : TileEntityJukebox(net.minecraft.block.BlockJukebox.TileEntityJukebox) Jukebox(org.spongepowered.api.block.tileentity.Jukebox) BlockJukebox(net.minecraft.block.BlockJukebox) IBlockState(net.minecraft.block.state.IBlockState) BlockJukebox(net.minecraft.block.BlockJukebox) ItemRecord(net.minecraft.item.ItemRecord)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)2 ItemRecord (net.minecraft.item.ItemRecord)2 BlockJukebox (net.minecraft.block.BlockJukebox)1 TileEntityJukebox (net.minecraft.block.BlockJukebox.TileEntityJukebox)1 Jukebox (org.spongepowered.api.block.tileentity.Jukebox)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1