Search in sources :

Example 1 with TileEntityComputer

use of com.mrcrayfish.furniture.tileentity.TileEntityComputer in project MrCrayfishFurnitureMod by MrCrayfish.

the class BlockComputer method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    TileEntity tile_entity = worldIn.getTileEntity(pos);
    if (tile_entity instanceof TileEntityComputer) {
        TileEntityComputer computer = (TileEntityComputer) tile_entity;
        if (!computer.isTrading()) {
            computer.setTrading(true);
            playerIn.openGui(MrCrayfishFurnitureMod.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
        } else {
            if (!worldIn.isRemote) {
                playerIn.sendMessage(new TextComponentTranslation("cfm.message.computer"));
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TileEntityComputer(com.mrcrayfish.furniture.tileentity.TileEntityComputer)

Example 2 with TileEntityComputer

use of com.mrcrayfish.furniture.tileentity.TileEntityComputer in project MrCrayfishFurnitureMod by MrCrayfish.

the class MessageMineBayClosed method onMessage.

@Override
public IMessage onMessage(MessageMineBayClosed message, MessageContext ctx) {
    final WorldServer world = ctx.getServerHandler().player.getServerWorld();
    world.addScheduledTask(() -> {
        EntityPlayerMP player = ctx.getServerHandler().player;
        TileEntity tile_entity = world.getTileEntity(new BlockPos(message.x, message.y, message.z));
        if (tile_entity instanceof TileEntityComputer) {
            TileEntityComputer tileEntityComputer = (TileEntityComputer) tile_entity;
            if (!tileEntityComputer.getStackInSlot(0).isEmpty()) {
                player.world.spawnEntity(new EntityItem(world, player.posX, player.posY, player.posZ, tileEntityComputer.getStackInSlot(0)));
                tileEntityComputer.setInventorySlotContents(0, ItemStack.EMPTY);
            }
            tileEntityComputer.setTrading(false);
            BlockPos pos = new BlockPos(message.x, message.y, message.z);
            TileEntityUtil.markBlockForUpdate(world, pos);
        }
    });
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityComputer(com.mrcrayfish.furniture.tileentity.TileEntityComputer) WorldServer(net.minecraft.world.WorldServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with TileEntityComputer

use of com.mrcrayfish.furniture.tileentity.TileEntityComputer in project MrCrayfishFurnitureMod by MrCrayfish.

the class MessageMineBayBrowse method onMessage.

@Override
public IMessage onMessage(MessageMineBayBrowse message, MessageContext ctx) {
    final WorldServer world = ctx.getServerHandler().player.getServerWorld();
    world.addScheduledTask(() -> {
        EntityPlayerMP player = ctx.getServerHandler().player;
        TileEntity tile_entity = player.world.getTileEntity(new BlockPos(message.x, message.y, message.z));
        if (tile_entity instanceof TileEntityComputer) {
            TileEntityComputer tileEntityComputer = (TileEntityComputer) tile_entity;
            tileEntityComputer.setBrowsingInfo(message.itemNum);
            BlockPos pos = new BlockPos(message.x, message.y, message.z);
            TileEntityUtil.markBlockForUpdate(ctx.getServerHandler().player.world, pos);
        }
    });
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityComputer(com.mrcrayfish.furniture.tileentity.TileEntityComputer) WorldServer(net.minecraft.world.WorldServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with TileEntityComputer

use of com.mrcrayfish.furniture.tileentity.TileEntityComputer in project MrCrayfishFurnitureMod by MrCrayfish.

the class MessageMineBayBuy method onMessage.

@Override
public IMessage onMessage(MessageMineBayBuy message, MessageContext ctx) {
    final WorldServer world = ctx.getServerHandler().player.getServerWorld();
    world.addScheduledTask(() -> {
        EntityPlayer player = ctx.getServerHandler().player;
        TileEntity tileEntity = player.world.getTileEntity(new BlockPos(message.x, message.y, message.z));
        if (tileEntity instanceof TileEntityComputer) {
            TileEntityComputer tileEntityComputer = (TileEntityComputer) tileEntity;
            ItemStack buySlot = tileEntityComputer.getStackInSlot(0);
            if (buySlot.isEmpty())
                return;
            RecipeData[] data = Recipes.getMineBayItems();
            if (message.itemNum < 0 || message.itemNum >= data.length)
                return;
            RecipeData recipe = data[message.itemNum];
            int price = recipe.getPrice();
            if (recipe.getCurrency().getItem() == buySlot.getItem() && buySlot.getCount() >= price) {
                tileEntityComputer.takeEmeraldFromSlot(price);
                EntityItem entityItem = new EntityItem(player.world, player.posX, player.posY + 1, player.posZ, data[message.itemNum].getInput().copy());
                player.world.spawnEntity(entityItem);
                Triggers.trigger(Triggers.MINEBAY_PURCHASE, player);
            }
        }
    });
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityComputer(com.mrcrayfish.furniture.tileentity.TileEntityComputer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) RecipeData(com.mrcrayfish.furniture.api.RecipeData)

Aggregations

TileEntityComputer (com.mrcrayfish.furniture.tileentity.TileEntityComputer)4 TileEntity (net.minecraft.tileentity.TileEntity)4 BlockPos (net.minecraft.util.math.BlockPos)3 WorldServer (net.minecraft.world.WorldServer)3 EntityItem (net.minecraft.entity.item.EntityItem)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 RecipeData (com.mrcrayfish.furniture.api.RecipeData)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1